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

Co-authored-by: Younes Henni <youneshenniwrites@gmail.com>
This commit is contained in:
Sebastian "Sebbie" Silbermann
2025-02-13 18:09:49 +01:00
committed by GitHub
co-authored by Younes Henni
parent cbbe8666a8
commit c6a7e18636
2 changed files with 14 additions and 1 deletions
+1 -1
View File
@@ -72,7 +72,7 @@ export function runWithFiberInDEV<A0, A1, A2, A3, A4, T>(
}
return callback(arg0, arg1, arg2, arg3, arg4);
} finally {
current = previousFiber;
setCurrentFiber(previousFiber);
}
}
// These errors should never make it into a build so we don't need to encode them in codes.json
@@ -62,4 +62,17 @@ describe('ReactOwnerStacks', () => {
'\n in Bar (at **)' + '\n in Foo (at **)',
);
});
it('returns null outside of render', async () => {
// Awkward to gate since some builds will have `captureOwnerStack` return null in prod
if (__DEV__ && gate('enableOwnerStacks')) {
expect(React.captureOwnerStack()).toBe(null);
await act(() => {
ReactNoop.render(<div />);
});
expect(React.captureOwnerStack()).toBe(null);
}
});
});