mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Syntax errors should dismiss redboxes
Summary: If you make a syntax error while there is a redbox while Fast Refresh is on, we should dismiss that redbox. Otherwise there is no way for you to tell why your code is not working. Reviewed By: rickhanlonii Differential Revision: D15970337 fbshipit-source-id: 1ca6c9a1b2269d198ae726d3b64e5c51506503db
This commit is contained in:
committed by
Facebook Github Bot
parent
0a17699fd5
commit
7d2a95d43d
@@ -139,7 +139,7 @@ Error: ${e.message}`;
|
||||
});
|
||||
|
||||
// This is intentionally called lazily, as these values change.
|
||||
function shouldProvideVisualFeedback() {
|
||||
function isFastRefreshActive() {
|
||||
return (
|
||||
// Until we get "connection-done", messages aren't real edits.
|
||||
didFinishInitialUpdate &&
|
||||
@@ -151,27 +151,31 @@ Error: ${e.message}`;
|
||||
);
|
||||
}
|
||||
|
||||
function dismissRedbox() {
|
||||
if (
|
||||
Platform.OS === 'ios' &&
|
||||
NativeRedBox != null &&
|
||||
NativeRedBox.dismiss != null
|
||||
) {
|
||||
NativeRedBox.dismiss();
|
||||
} else {
|
||||
const NativeExceptionsManager = require('../Core/NativeExceptionsManager')
|
||||
.default;
|
||||
NativeExceptionsManager &&
|
||||
NativeExceptionsManager.dismissRedbox &&
|
||||
NativeExceptionsManager.dismissRedbox();
|
||||
}
|
||||
}
|
||||
|
||||
hmrClient.on('update-start', () => {
|
||||
if (shouldProvideVisualFeedback()) {
|
||||
if (isFastRefreshActive()) {
|
||||
HMRLoadingView.showMessage('Refreshing...');
|
||||
}
|
||||
});
|
||||
|
||||
hmrClient.on('update', () => {
|
||||
if (shouldProvideVisualFeedback()) {
|
||||
if (
|
||||
Platform.OS === 'ios' &&
|
||||
NativeRedBox != null &&
|
||||
NativeRedBox.dismiss != null
|
||||
) {
|
||||
NativeRedBox.dismiss();
|
||||
} else {
|
||||
const NativeExceptionsManager = require('../Core/NativeExceptionsManager')
|
||||
.default;
|
||||
NativeExceptionsManager &&
|
||||
NativeExceptionsManager.dismissRedbox &&
|
||||
NativeExceptionsManager.dismissRedbox();
|
||||
}
|
||||
if (isFastRefreshActive()) {
|
||||
dismissRedbox();
|
||||
}
|
||||
});
|
||||
|
||||
@@ -192,7 +196,10 @@ Error: ${e.message}`;
|
||||
setHMRUnavailableReason(
|
||||
'The Metro server and the client are out of sync. Fast Refresh will be disabled until you reload the application.',
|
||||
);
|
||||
} else {
|
||||
} else if (isFastRefreshActive()) {
|
||||
// Even if there is already a redbox, syntax errors are more important.
|
||||
// Otherwise you risk seeing a stale runtime error while a syntax error is more recent.
|
||||
dismissRedbox();
|
||||
throw new Error(`${data.type} ${data.message}`);
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user