Skip to content

Commit 448f0c6

Browse files
committed
Fix error parsing, fix fetching sektch runtime urls
1 parent 7df219c commit 448f0c6

File tree

2 files changed

+21
-36
lines changed

2 files changed

+21
-36
lines changed

client/modules/IDE/components/Editor.jsx

Lines changed: 18 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import babelParser from 'prettier/parser-babel';
77
import htmlParser from 'prettier/parser-html';
88
import cssParser from 'prettier/parser-postcss';
99
import { withTranslation } from 'react-i18next';
10+
import StackTrace from 'stacktrace-js';
1011
import 'codemirror/mode/css/css';
1112
import 'codemirror/addon/selection/active-line';
1213
import 'codemirror/addon/lint/lint';
@@ -252,42 +253,25 @@ class Editor extends React.Component {
252253

253254
this.props.consoleEvents.forEach((consoleEvent) => {
254255
if (consoleEvent.method === 'error') {
255-
if (consoleEvent.data && consoleEvent.data[0]) {
256-
let sourceAndLoc;
257-
if (
258-
consoleEvent.data[0].indexOf &&
259-
consoleEvent.data[0].indexOf(')') > -1
260-
) {
261-
sourceAndLoc = consoleEvent.data[0] // eslint-disable-line
262-
.split('\n')[1]
263-
.split('(')[1]
264-
.split(')')[0];
265-
} else if (consoleEvent.data[0].indexOf('at ') > -1) {
266-
sourceAndLoc = consoleEvent.data[0] // eslint-disable-line
267-
.split('\n')[1]
268-
.split('at ')[1];
269-
} else {
256+
StackTrace.fromError(new Error(consoleEvent.data[0])).then(
257+
(stackLines) => {
270258
this.props.expandConsole();
271-
return;
259+
const line = stackLines.find((l) => l.fileName.startsWith('/'));
260+
if (!line) return;
261+
const fileNameArray = line.fileName.split('/');
262+
const fileName = fileNameArray.slice(-1)[0];
263+
const filePath = fileNameArray.slice(0, -1).join('/');
264+
const fileWithError = this.props.files.find(
265+
(f) => f.name === fileName && f.filePath === filePath
266+
);
267+
this.props.setSelectedFile(fileWithError.id);
268+
this._cm.addLineClass(
269+
line.lineNumber - 1,
270+
'background',
271+
'line-runtime-error'
272+
);
272273
}
273-
const [source, line] = sourceAndLoc.split(':');
274-
275-
// get the file that this message is coming from, and then select it
276-
const sourceArray = source.split('/');
277-
const fileName = sourceArray.slice(-1)[0];
278-
const filePath = sourceArray.slice(0, -1).join('/');
279-
const fileWithError = this.props.files.find(
280-
(f) => f.name === fileName && f.filePath === filePath
281-
);
282-
this.props.setSelectedFile(fileWithError.id);
283-
this.props.expandConsole();
284-
const lineNumber = parseInt(line, 10) - 1;
285-
this._cm.addLineClass(
286-
lineNumber,
287-
'background',
288-
'line-runtime-error'
289-
);
290-
}
274+
);
291275
}
292276
});
293277
} else {

client/modules/Preview/EmbedFrame.jsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ function resolveScripts(sketchDoc, files) {
149149
script.getAttribute('src').match(EXTERNAL_LINK_REGEX)
150150
) !== null
151151
) {
152-
// script.setAttribute('crossorigin', '');
152+
script.setAttribute('crossorigin', '');
153153
script.innerHTML = resolveJSLinksInString(script.innerHTML, files); // eslint-disable-line
154154
}
155155
});
@@ -215,7 +215,7 @@ function injectLocalFiles(files, htmlFile, basePath) {
215215
const sketchDoc = parser.parseFromString(htmlFile.content, 'text/html');
216216

217217
const base = sketchDoc.createElement('base');
218-
base.href = `${basePath}`;
218+
base.href = `${window.origin}${basePath}/`;
219219
sketchDoc.head.appendChild(base);
220220

221221
resolvePathsForElementsWithAttribute('src', sketchDoc, resolvedFiles);
@@ -229,6 +229,7 @@ function injectLocalFiles(files, htmlFile, basePath) {
229229
previewScripts.src = `${window.location.origin}${getConfig(
230230
'PREVIEW_SCRIPTS_URL'
231231
)}`;
232+
previewScripts.setAttribute('crossorigin', '');
232233
sketchDoc.head.appendChild(previewScripts);
233234

234235
const sketchDocString = `<!DOCTYPE HTML>\n${sketchDoc.documentElement.outerHTML}`;

0 commit comments

Comments
 (0)