fix crash on save-and-play when not logged in

This commit is contained in:
Ruben van de Ven 2020-10-09 17:21:16 +02:00
parent 8ebe30af90
commit bc83555cab

View file

@ -59,6 +59,7 @@ class PreviewFrame extends React.Component {
}
componentDidUpdate(prevProps) {
// console.log(this.props, prevProps);
if (shouldRenderSketch(this.props, prevProps)) this.renderSketch();
// small bug - if autorefresh is on, and the usr changes files
// in the sketch, preview will reload
@ -330,12 +331,12 @@ class PreviewFrame extends React.Component {
renderSketch() {
const doc = this.iframeElement;
// const localFiles = this.injectLocalFiles();
console.log('renderSketch()', this.props);
// console.trace('renderSketch()', this.props);
const changedFiles = this.props.files.filter(file => file.changed);
const filesRequiringReload = changedFiles.filter(file => !file.content.startsWith('// liveUpdate'));
const filesToHotSwap = changedFiles.filter(file => filesRequiringReload.indexOf(file) === -1);
console.log('changed and requiring reload:', changedFiles, filesRequiringReload, filesToHotSwap);
// console.log('changed and requiring reload:', changedFiles, filesRequiringReload, filesToHotSwap);
let saving;
if (changedFiles.length > 0) {
@ -345,15 +346,20 @@ class PreviewFrame extends React.Component {
saving = new Promise((resolve, err) => resolve());
}
if (saving === null) {
// console.log('Error saving... not authenticated?');
this.props.stopSketch(); // prevent crazy loop of renderSketch() through componentDidUpdate()
} else {
saving.catch(() => {
console.log('Error saving... not authenticated?');
window.location.href = '/login';
// console.log('Error when saving... not authenticated? Redirect!');
this.props.stopSketch(); // prevent crazy loop of renderSketch() through componentDidUpdate()
});
saving.then(() => {
if (this.props.isPlaying) {
this.props.clearConsole();
doc.removeAttribute('srcdoc');
const source = `${window.location.origin}/${this.props.project.owner.username}/sketches/${this.props.project.id}/index.html`;
// console.log('FILES', this.props.files, doc.src, source, lastUpdate);
if (doc.src === source) {
@ -362,8 +368,7 @@ class PreviewFrame extends React.Component {
// console.log('unsaved changes');
}
console.log('doc', doc);
// console.log('doc', doc);
// we need a hard reload
if (filesRequiringReload.length > 0) {
doc.src = source; // for now...
@ -402,6 +407,7 @@ class PreviewFrame extends React.Component {
}
});
}
}
render() {
const iframeClass = classNames({