From 896d0cd715afe2eb866b890fbef3639049f26320 Mon Sep 17 00:00:00 2001 From: Cassie Tarakajian Date: Tue, 13 Dec 2016 15:37:11 -0500 Subject: [PATCH] testing of #214, fix bug where errors not in sketch.js wouldn't appear in the console --- client/modules/IDE/components/Console.jsx | 20 +++++++++---------- .../modules/IDE/components/PreviewFrame.jsx | 11 +++++----- 2 files changed, 15 insertions(+), 16 deletions(-) diff --git a/client/modules/IDE/components/Console.jsx b/client/modules/IDE/components/Console.jsx index 6f5973c8..e7c155ea 100644 --- a/client/modules/IDE/components/Console.jsx +++ b/client/modules/IDE/components/Console.jsx @@ -28,17 +28,15 @@ class Console extends React.Component { this.children = []; } else if (nextProps.consoleEvent !== this.props.consoleEvent && this.props.isPlaying) { nextProps.consoleEvent.forEach(consoleEvent => { - if (consoleEvent.source === 'sketch') { - const args = consoleEvent.arguments; - Object.keys(args).forEach((key) => { - if (args[key].includes('Exiting potential infinite loop')) { - this.props.stopSketch(); - this.props.expandConsole(); - this.appendConsoleEvent(consoleEvent); - } - }); - this.appendConsoleEvent(consoleEvent); - } + const args = consoleEvent.arguments; + Object.keys(args).forEach((key) => { + if (args[key].includes('Exiting potential infinite loop')) { + this.props.stopSketch(); + this.props.expandConsole(); + this.appendConsoleEvent(consoleEvent); + } + }); + this.appendConsoleEvent(consoleEvent); }); } } diff --git a/client/modules/IDE/components/PreviewFrame.jsx b/client/modules/IDE/components/PreviewFrame.jsx index 2c6df975..16a4d48b 100644 --- a/client/modules/IDE/components/PreviewFrame.jsx +++ b/client/modules/IDE/components/PreviewFrame.jsx @@ -30,12 +30,12 @@ function getAllScriptOffsets(htmlFile) { } else { endFilenameInd = htmlFile.indexOf('.js', ind + startTag.length + 3); filename = htmlFile.substring(ind + startTag.length, endFilenameInd); - lineOffset = htmlFile.substring(0, ind).split('\n').length - 1; + // the length of hijackConsoleErrorsScript is 35 lines, already needed a -1 offset. + lineOffset = htmlFile.substring(0, ind).split('\n').length + 34; offs.push([lineOffset, filename]); lastInd = ind + 1; } } - console.log(offs); return offs; } @@ -71,7 +71,7 @@ function hijackConsoleErrorsScript(offs) { window.parent.postMessage([{ method: 'error', arguments: data, - source: 'sketch' + source: fileInfo[1] }], '*'); return false; }; @@ -199,7 +199,8 @@ class PreviewFrame extends React.Component { scriptOffs = getAllScriptOffsets(sketchDocString); const consoleErrorsScript = sketchDoc.createElement('script'); consoleErrorsScript.innerHTML = hijackConsoleErrorsScript(JSON.stringify(scriptOffs)); - sketchDoc.body.appendChild(consoleErrorsScript); + // sketchDoc.head.appendChild(consoleErrorsScript); + sketchDoc.head.insertBefore(consoleErrorsScript, sketchDoc.head.firstElement); return `\n${sketchDoc.documentElement.outerHTML}`; } @@ -312,7 +313,7 @@ class PreviewFrame extends React.Component { } else { const style = sketchDoc.createElement('style'); style.innerHTML = `\n${resolvedFile.content}`; - sketchDoc.body.appendChild(style); + sketchDoc.head.appendChild(style); css.parentElement.removeChild(css); } }