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