Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a91e4bd

Browse files
shinytang6catarak
authored andcommitted
fix some bugs
1 parent ed65046 commit a91e4bd

File tree

2 files changed

+15
-16
lines changed

2 files changed

+15
-16
lines changed

client/modules/IDE/components/PreviewFrame.jsx

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import {
1919
EXTERNAL_LINK_REGEX,
2020
NOT_EXTERNAL_LINK_REGEX
2121
} from '../../../../server/utils/fileUtils';
22-
import { startTag }
22+
import { hijackConsoleErrorsScript, startTag }
2323
from '../../../utils/consoleUtils';
2424

2525
class PreviewFrame extends React.Component {
@@ -67,7 +67,6 @@ class PreviewFrame extends React.Component {
6767

6868
componentWillUnmount() {
6969
window.removeEventListener('message', this.handleConsoleEvent);
70-
ReactDOM.unmountComponentAtNode(this.iframeElement.contentDocument.body);
7170
}
7271

7372
handleConsoleEvent(messageEvent) {
@@ -152,7 +151,8 @@ class PreviewFrame extends React.Component {
152151
this.resolveStyles(sketchDoc, resolvedFiles);
153152

154153
const scriptsToInject = [
155-
loopProtectScript
154+
loopProtectScript,
155+
hijackConsoleErrorsScript
156156
];
157157
const accessiblelib = sketchDoc.createElement('script');
158158
accessiblelib.setAttribute(
@@ -347,19 +347,6 @@ class PreviewFrame extends React.Component {
347347
consoleBuffer.length = 0;
348348
}
349349
}, LOGWAIT);
350-
351-
// catch reference errors, via http://stackoverflow.com/a/12747364/2994108
352-
window.onerror = function (msg, url, lineNumber, columnNo, error) {
353-
// const string = msg.toLowerCase();
354-
// const substring = 'script error';
355-
let data = msg + ' (' + 'sketch' + ': line ' + lineNumber + ')';// eslint-disable-line
356-
window.parent.postMessage([{
357-
method: 'error',
358-
arguments: data,
359-
source: lineNumber // eslint-disable-line
360-
}], '*');
361-
return false;
362-
};
363350
}
364351
}
365352
</FrameContextConsumer>

client/utils/consoleUtils.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,18 @@ import debugDarkUrl from '../images/console-debug-dark.svg';
77
import infoLightUrl from '../images/console-info-light.svg';
88
import infoDarkUrl from '../images/console-info-dark.svg';
99

10+
export const hijackConsoleErrorsScript = `
11+
// catch reference errors, via http://stackoverflow.com/a/12747364/2994108
12+
window.onerror = function (msg, url, lineNumber, columnNo, error) {
13+
let data = msg + ' (' + 'sketch' + ': line ' + lineNumber + ')';// eslint-disable-line
14+
window.parent.postMessage([{
15+
method: 'error',
16+
arguments: data,
17+
source: lineNumber // eslint-disable-line
18+
}], '*');
19+
return false;
20+
};`;
21+
1022
export const startTag = '@fs-';
1123

1224
export const CONSOLE_FEED_WITHOUT_ICONS = {

0 commit comments

Comments
 (0)