-
Notifications
You must be signed in to change notification settings - Fork 48.8k
Cross-origin error handling in DEV #10353
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
01e2470
cb6fd8c
6f6425b
b145a08
af46b61
26770b2
fde39dc
fa20c9c
095e29b
8b183b5
39dea7e
3364def
d99b90d
311a3f8
9a8b033
39df724
2ea6063
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -208,10 +208,14 @@ if (__DEV__) { | |
let error; | ||
// Use this to track whether the error event is ever called. | ||
let didSetError = false; | ||
let isCrossOriginError = false; | ||
|
||
function onError(event) { | ||
error = event.error; | ||
didSetError = true; | ||
if (error === null && event.colno === 0 && event.lineno === 0) { | ||
isCrossOriginError = true; | ||
} | ||
} | ||
|
||
// Create a fake event type. | ||
|
@@ -240,6 +244,18 @@ if (__DEV__) { | |
'or switching to a modern browser. If you suspect that this is ' + | ||
'actually an issue with React, please file an issue.', | ||
); | ||
} else if (isCrossOriginError) { | ||
error = new Error( | ||
"A cross-origin error was thrown. React doesn't have access to " + | ||
'the actual error because it catches errors using a global ' + | ||
'error handler, in order to preserve the "Pause on exceptions" ' + | ||
'behavior of the DevTools. This is only an issue in DEV-mode; ' + | ||
'in production, React uses a normal try-catch statement.\n\n' + | ||
'If you are using React from a CDN, ensure that the <script> tag ' + | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It might be nice to say "If you are using React from a CDN in development, ensure ..." just to re-emphasize that this is only an issue in dev. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Sorry. I read your statement twice as "to re-emphasize that this isn't only an issue in dev." There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. PR welcome :-) |
||
'has a `crossorigin` attribute, and that it is served with the ' + | ||
'`Access-Control-Allow-Origin: *` HTTP header. ' + | ||
'See https://fb.me/react-cdn-crossorigin', | ||
); | ||
} | ||
ReactErrorUtils._hasCaughtError = true; | ||
ReactErrorUtils._caughtError = error; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should remove the
message
andname
variables now. They don't seem to be used anymore.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.