mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
DevTools always overrides the dispatcher when shallow rendering (#20011)
This is done so that any effects scheduled by the shallow render are thrown away. Unlike the code this was forked from (in ReactComponentStackFrame) DevTools should override the dispatcher even when DevTools is compiled in production mode, because the app itself may be in development mode and log errors/warnings.
This commit is contained in:
+12
-12
@@ -85,14 +85,16 @@ export function describeNativeComponentFrame(
|
||||
Error.prepareStackTrace = undefined;
|
||||
|
||||
reentry = true;
|
||||
let previousDispatcher;
|
||||
if (__DEV__) {
|
||||
previousDispatcher = currentDispatcherRef.current;
|
||||
// Set the dispatcher in DEV because this might be call in the render function
|
||||
// for warnings.
|
||||
currentDispatcherRef.current = null;
|
||||
disableLogs();
|
||||
}
|
||||
|
||||
// Override the dispatcher so effects scheduled by this shallow render are thrown away.
|
||||
//
|
||||
// Note that unlike the code this was forked from (in ReactComponentStackFrame)
|
||||
// DevTools should override the dispatcher even when DevTools is compiled in production mode,
|
||||
// because the app itself may be in development mode and log errors/warnings.
|
||||
const previousDispatcher = currentDispatcherRef.current;
|
||||
currentDispatcherRef.current = null;
|
||||
disableLogs();
|
||||
|
||||
try {
|
||||
// This should throw.
|
||||
if (construct) {
|
||||
@@ -188,10 +190,8 @@ export function describeNativeComponentFrame(
|
||||
|
||||
Error.prepareStackTrace = previousPrepareStackTrace;
|
||||
|
||||
if (__DEV__) {
|
||||
currentDispatcherRef.current = previousDispatcher;
|
||||
reenableLogs();
|
||||
}
|
||||
currentDispatcherRef.current = previousDispatcher;
|
||||
reenableLogs();
|
||||
}
|
||||
// Fallback to just using the name if we couldn't make it throw.
|
||||
const name = fn ? fn.displayName || fn.name : '';
|
||||
|
||||
Reference in New Issue
Block a user