Skip to content

Commit c6a7e18

Browse files
Ensure captureOwnerStack returns null when no stack is available (facebook#32353)
Co-authored-by: Younes Henni <youneshenniwrites@gmail.com>
1 parent cbbe866 commit c6a7e18

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

packages/react-reconciler/src/ReactCurrentFiber.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ export function runWithFiberInDEV<A0, A1, A2, A3, A4, T>(
7272
}
7373
return callback(arg0, arg1, arg2, arg3, arg4);
7474
} finally {
75-
current = previousFiber;
75+
setCurrentFiber(previousFiber);
7676
}
7777
}
7878
// 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
Original file line numberDiff line numberDiff line change
@@ -62,4 +62,17 @@ describe('ReactOwnerStacks', () => {
6262
'\n in Bar (at **)' + '\n in Foo (at **)',
6363
);
6464
});
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+
});
6578
});

0 commit comments

Comments
 (0)