Skip to content

Commit 9f4624a

Browse files
author
Brian Vaughn
committed
DevTools always overrides the dispatcher when shallow rendering
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 in production mode as well, because app code might log errors or warnings.
1 parent e614e69 commit 9f4624a

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

packages/react-devtools-shared/src/backend/DevToolsComponentStackFrame.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -85,14 +85,16 @@ export function describeNativeComponentFrame(
8585
Error.prepareStackTrace = undefined;
8686

8787
reentry = true;
88-
let previousDispatcher;
89-
if (__DEV__) {
90-
previousDispatcher = currentDispatcherRef.current;
91-
// Set the dispatcher in DEV because this might be call in the render function
92-
// for warnings.
93-
currentDispatcherRef.current = null;
94-
disableLogs();
95-
}
88+
89+
// Override the dispatcher so effects scheduled by this shallow render are thrown away.
90+
//
91+
// Note that unlike the code this was forked from (in ReactComponentStackFrame)
92+
// DevTools should override the dispatcher in production mode as well,
93+
// because app code might log errors or warnings.
94+
const previousDispatcher = currentDispatcherRef.current;
95+
currentDispatcherRef.current = null;
96+
disableLogs();
97+
9698
try {
9799
// This should throw.
98100
if (construct) {
@@ -188,10 +190,8 @@ export function describeNativeComponentFrame(
188190

189191
Error.prepareStackTrace = previousPrepareStackTrace;
190192

191-
if (__DEV__) {
192-
currentDispatcherRef.current = previousDispatcher;
193-
reenableLogs();
194-
}
193+
currentDispatcherRef.current = previousDispatcher;
194+
reenableLogs();
195195
}
196196
// Fallback to just using the name if we couldn't make it throw.
197197
const name = fn ? fn.displayName || fn.name : '';

0 commit comments

Comments
 (0)