Fix race condition that's causing preview/console and code to be out of sync (#990) (#1031)

* Fix race condition that's causing preview/console and code to be out of sync (#990)

* Refactor

* Fix undefined prop error
This commit is contained in:
Ziyao Wei 2019-05-02 15:30:56 -04:00 committed by Cassie Tarakajian
parent a5753b5e4c
commit 10403a7f59
2 changed files with 15 additions and 2 deletions

View file

@ -143,10 +143,18 @@ class PreviewFrame extends React.Component {
return newContent;
}
mergeLocalFilesAndEditorActiveFile() {
const files = this.props.files.slice();
const activeFileInEditor = this.props.cmController.getContent();
files.find(file => file.id === activeFileInEditor.id).content = activeFileInEditor.content;
return files;
}
injectLocalFiles() {
const htmlFile = this.props.htmlFile.content;
let scriptOffs = [];
const resolvedFiles = this.resolveJSAndCSSLinks(this.props.files);
const files = this.mergeLocalFilesAndEditorActiveFile();
const resolvedFiles = this.resolveJSAndCSSLinks(files);
const parser = new DOMParser();
const sketchDoc = parser.parseFromString(htmlFile, 'text/html');
@ -381,10 +389,14 @@ PreviewFrame.propTypes = {
stopSketch: PropTypes.func.isRequired,
expandConsole: PropTypes.func.isRequired,
clearConsole: PropTypes.func.isRequired,
cmController: PropTypes.shape({
getContent: PropTypes.func
})
};
PreviewFrame.defaultProps = {
fullView: false
fullView: false,
cmController: {}
};
export default PreviewFrame;

View file

@ -345,6 +345,7 @@ class IDEView extends React.Component {
setBlobUrl={this.props.setBlobUrl}
expandConsole={this.props.expandConsole}
clearConsole={this.props.clearConsole}
cmController={this.cmController}
/>
</div>
</div>