mirror of
https://github.com/zebrajr/react.git
synced 2026-01-15 12:15:22 +00:00
[DevTools] Print component stacks as error objects to get source mapping (#30289)
Before: <img width="844" alt="Screenshot 2024-07-04 at 3 20 34 PM" src="https://github.com/facebook/react/assets/63648/0fd8a53f-538a-4429-a4cf-c22f85a09aa8"> After: <img width="845" alt="Screenshot 2024-07-05 at 6 08 28 PM" src="https://github.com/facebook/react/assets/63648/7b9da13a-fa97-4581-9899-06de6fface65"> Firefox: <img width="1338" alt="Screenshot 2024-07-05 at 6 09 50 PM" src="https://github.com/facebook/react/assets/63648/f2eb9f2a-2251-408f-86d0-b081279ba378"> The first log doesn't get a stack because it's logged before DevTools boots up and connects which is unfortunate. The second log already has a stack printed by React (this is on stable) it gets replaced by our object now. The third and following logs don't have a stack and get one appended. I only turn the stack into an error object if it matches what we would emit from DevTools anyway. Otherwise we assume it's not React. Since I had to change the format slightly to make this work, I first normalize the stack slightly before doing a comparison since it won't be 1:1.
This commit is contained in:
committed by
GitHub
parent
274c980c53
commit
491a4eacce
2
scripts/flow/react-devtools.js
vendored
2
scripts/flow/react-devtools.js
vendored
@@ -13,3 +13,5 @@ declare const __EXTENSION__: boolean;
|
||||
declare const __TEST__: boolean;
|
||||
|
||||
declare const __IS_FIREFOX__: boolean;
|
||||
declare const __IS_CHROME__: boolean;
|
||||
declare const __IS_EDGE__: boolean;
|
||||
|
||||
@@ -12,6 +12,8 @@ if (!global.hasOwnProperty('localStorage')) {
|
||||
global.__DEV__ = process.env.NODE_ENV !== 'production';
|
||||
global.__TEST__ = true;
|
||||
global.__IS_FIREFOX__ = false;
|
||||
global.__IS_CHROME__ = false;
|
||||
global.__IS_EDGE__ = false;
|
||||
|
||||
const ReactVersionTestingAgainst = process.env.REACT_VERSION || ReactVersion;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user