Skip to content

Commit 60edcb3

Browse files
committed
Replace setCurrentDebugFiberInDEV with runWithFiberInDEV
1 parent 66fb6fb commit 60edcb3

6 files changed

Lines changed: 321 additions & 200 deletions

File tree

packages/react-reconciler/src/ReactCurrentFiber.js

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -41,16 +41,29 @@ function getCurrentFiberStackInDev(): string {
4141
return '';
4242
}
4343

44-
export function resetCurrentDebugFiberInDEV() {
45-
if (__DEV__) {
46-
resetCurrentFiber();
47-
}
48-
}
49-
50-
export function setCurrentDebugFiberInDEV(fiber: Fiber | null) {
44+
export function runWithFiberInDEV<A0, A1, A2, A3, A4, T>(
45+
fiber: null | Fiber,
46+
callback: (A0, A1, A2, A3, A4) => T,
47+
arg0: A0,
48+
arg1: A1,
49+
arg2: A2,
50+
arg3: A3,
51+
arg4: A4,
52+
): T {
5153
if (__DEV__) {
54+
const previousFiber = current;
5255
setCurrentFiber(fiber);
56+
try {
57+
return callback(arg0, arg1, arg2, arg3, arg4);
58+
} finally {
59+
current = previousFiber;
60+
}
5361
}
62+
// These errors should never make it into a build so we don't need to encode them in codes.json
63+
// eslint-disable-next-line react-internal/prod-error-codes
64+
throw new Error(
65+
'runWithFiberInDEV should never be called in production. This is a bug in React.',
66+
);
5467
}
5568

5669
export function resetCurrentFiber() {
@@ -70,13 +83,6 @@ export function setCurrentFiber(fiber: Fiber | null) {
7083
current = fiber;
7184
}
7285

73-
export function getCurrentFiber(): Fiber | null {
74-
if (__DEV__) {
75-
return current;
76-
}
77-
return null;
78-
}
79-
8086
export function setIsRendering(rendering: boolean) {
8187
if (__DEV__) {
8288
isRendering = rendering;

0 commit comments

Comments
 (0)