Skip to content

Commit

Permalink
Replace setCurrentDebugFiberInDEV with runWithFiberInDEV
Browse files Browse the repository at this point in the history
  • Loading branch information
sebmarkbage committed May 22, 2024
1 parent 66fb6fb commit 60edcb3
Show file tree
Hide file tree
Showing 6 changed files with 321 additions and 200 deletions.
34 changes: 20 additions & 14 deletions packages/react-reconciler/src/ReactCurrentFiber.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,29 @@ function getCurrentFiberStackInDev(): string {
return '';
}

export function resetCurrentDebugFiberInDEV() {
if (__DEV__) {
resetCurrentFiber();
}
}

export function setCurrentDebugFiberInDEV(fiber: Fiber | null) {
export function runWithFiberInDEV<A0, A1, A2, A3, A4, T>(
fiber: null | Fiber,
callback: (A0, A1, A2, A3, A4) => T,
arg0: A0,
arg1: A1,
arg2: A2,
arg3: A3,
arg4: A4,
): T {
if (__DEV__) {
const previousFiber = current;
setCurrentFiber(fiber);
try {
return callback(arg0, arg1, arg2, arg3, arg4);
} finally {
current = previousFiber;
}
}
// These errors should never make it into a build so we don't need to encode them in codes.json
// eslint-disable-next-line react-internal/prod-error-codes
throw new Error(
'runWithFiberInDEV should never be called in production. This is a bug in React.',
);
}

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

export function getCurrentFiber(): Fiber | null {
if (__DEV__) {
return current;
}
return null;
}

export function setIsRendering(rendering: boolean) {
if (__DEV__) {
isRendering = rendering;
Expand Down
Loading

0 comments on commit 60edcb3

Please sign in to comment.