@samitouri / QOS-React / commits / c6a7e18636

Ensure `captureOwnerStack` returns `null` when no stack is available (#32353)

Co-authored-by: Younes Henni <youneshenniwrites@gmail.com>

Sebastian "Sebbie" Silbermann committed Feb 13, 2025 at 18:09 UTC c6a7e18636e610efd3aa7a437bbcaf321bf73abd
2 files changed +14 -1
packages/react-reconciler/src/ReactCurrentFiber.js
+1 -1
@@ -72,7 +72,7 @@ export function runWithFiberInDEV<A0, A1, A2, A3, A4, T>(
72 }
73 return callback(arg0, arg1, arg2, arg3, arg4);
74 } finally {
75 - current = previousFiber;
75 + setCurrentFiber(previousFiber);
76 }
77 }
78 // These errors should never make it into a build so we don't need to encode them in codes.json
packages/react-reconciler/src/__tests__/ReactOwnerStacks-test.js
+13
@@ -62,4 +62,17 @@ describe('ReactOwnerStacks', () => {
62 '\n in Bar (at **)' + '\n in Foo (at **)',
63 );
64 });
65 +
66 + it('returns null outside of render', async () => {
67 + // Awkward to gate since some builds will have `captureOwnerStack` return null in prod
68 + if (__DEV__ && gate('enableOwnerStacks')) {
69 + expect(React.captureOwnerStack()).toBe(null);
70 +
71 + await act(() => {
72 + ReactNoop.render(<div />);
73 + });
74 +
75 + expect(React.captureOwnerStack()).toBe(null);
76 + }
77 + });
78 });