Skip to content

Commit

Permalink
contentwrap.jsx: make iframe refresh before applying changes. fixes #395
Browse files Browse the repository at this point in the history
  • Loading branch information
chinchang committed Jun 4, 2019
1 parent af87e05 commit 53c0ea0
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions src/components/ContentWrap.jsx
Expand Up @@ -145,12 +145,22 @@ export default class ContentWrap extends Component {
log('✉️ Sending message to detached window');
this.detachedWindow.postMessage({ contents }, '*');
} else {
this.frame.src = this.frame.src;
setTimeout(() => {
const writeInsideIframe = () => {
this.frame.contentDocument.open();
this.frame.contentDocument.write(contents);
this.frame.contentDocument.close();
}, 10);
};
Promise.race([
// Just in case onload promise doesn't resolves
new Promise(resolve => {
setTimeout(resolve, 200);
}),
new Promise(resolve => {
this.frame.onload = resolve;
})
]).then(writeInsideIframe);
// Setting to blank string cause frame to reload
this.frame.src = '';
}
} else {
// we need to store user script in external JS file to prevent inline-script
Expand Down Expand Up @@ -870,7 +880,6 @@ export default class ContentWrap extends Component {
<div class="demo-side" id="js-demo-side" style="">
<iframe
ref={el => (this.frame = el)}
src="about://blank"
frameborder="0"
id="demo-frame"
allowfullscreen
Expand Down

0 comments on commit 53c0ea0

Please sign in to comment.