-
Notifications
You must be signed in to change notification settings - Fork 47.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unify ReactFiberCurrentOwner and ReactCurrentFiber #29038
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -499,8 +499,8 @@ describe('creating element with string ref in constructor', () => { | |
} | ||
} | ||
|
||
// @gate !disableStringRefs | ||
it('throws an error', async () => { | ||
// @gate !disableStringRefs && !__DEV__ | ||
it('throws an error in prod', async () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What does it do in dev now? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We use the same fields for dev and prod just to temporarily support string refs but in DEV it's active for the entire begin / complete phases for debugging purposes. Meaning that it just works in dev because the owner is set up but in prod it's not. It still has a |
||
await expect(async function () { | ||
const container = document.createElement('div'); | ||
const root = ReactDOMClient.createRoot(container); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -101,8 +101,8 @@ import { | |
} from './ReactFiberFlags'; | ||
import getComponentNameFromFiber from 'react-reconciler/src/getComponentNameFromFiber'; | ||
import { | ||
resetCurrentFiber as resetCurrentDebugFiberInDEV, | ||
setCurrentFiber as setCurrentDebugFiberInDEV, | ||
resetCurrentDebugFiberInDEV, | ||
setCurrentDebugFiberInDEV, | ||
getCurrentFiber as getCurrentDebugFiberInDEV, | ||
} from './ReactCurrentFiber'; | ||
import {resolveClassComponentProps} from './ReactFiberClassComponent'; | ||
|
@@ -2486,7 +2486,7 @@ export function commitMutationEffects( | |
|
||
setCurrentDebugFiberInDEV(finishedWork); | ||
commitMutationEffectsOnFiber(finishedWork, root, committedLanes); | ||
setCurrentDebugFiberInDEV(finishedWork); | ||
resetCurrentDebugFiberInDEV(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was an bug before and the layout effects just reset to previous so it left the last mutation fiber as the debug fiber after commit. |
||
|
||
inProgressLanes = null; | ||
inProgressRoot = null; | ||
|
@@ -3125,8 +3125,10 @@ export function commitLayoutEffects( | |
inProgressLanes = committedLanes; | ||
inProgressRoot = root; | ||
|
||
setCurrentDebugFiberInDEV(finishedWork); | ||
const current = finishedWork.alternate; | ||
commitLayoutEffectOnFiber(root, current, finishedWork, committedLanes); | ||
resetCurrentDebugFiberInDEV(); | ||
|
||
inProgressLanes = null; | ||
inProgressRoot = null; | ||
|
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -204,7 +204,6 @@ import { | |
ContextOnlyDispatcher, | ||
} from './ReactFiberHooks'; | ||
import {DefaultAsyncDispatcher} from './ReactFiberAsyncDispatcher'; | ||
import {setCurrentOwner} from './ReactFiberCurrentOwner'; | ||
import { | ||
createCapturedValueAtFiber, | ||
type CapturedValue, | ||
|
@@ -230,8 +229,9 @@ import ReactStrictModeWarnings from './ReactStrictModeWarnings'; | |
import { | ||
isRendering as ReactCurrentDebugFiberIsRenderingInDEV, | ||
current as ReactCurrentFiberCurrent, | ||
resetCurrentFiber as resetCurrentDebugFiberInDEV, | ||
setCurrentFiber as setCurrentDebugFiberInDEV, | ||
resetCurrentDebugFiberInDEV, | ||
setCurrentDebugFiberInDEV, | ||
resetCurrentFiber, | ||
} from './ReactCurrentFiber'; | ||
import { | ||
isDevToolsPresent, | ||
|
@@ -1683,9 +1683,8 @@ function handleThrow(root: FiberRoot, thrownValue: any): void { | |
// These should be reset immediately because they're only supposed to be set | ||
// when React is executing user code. | ||
resetHooksAfterThrow(); | ||
resetCurrentDebugFiberInDEV(); | ||
if (__DEV__ || !disableStringRefs) { | ||
setCurrentOwner(null); | ||
resetCurrentFiber(); | ||
} | ||
|
||
if (thrownValue === SuspenseException) { | ||
|
@@ -2377,18 +2376,16 @@ function performUnitOfWork(unitOfWork: Fiber): void { | |
next = beginWork(current, unitOfWork, entangledRenderLanes); | ||
} | ||
|
||
resetCurrentDebugFiberInDEV(); | ||
if (__DEV__ || !disableStringRefs) { | ||
resetCurrentFiber(); | ||
} | ||
unitOfWork.memoizedProps = unitOfWork.pendingProps; | ||
if (next === null) { | ||
// If this doesn't spawn new work, complete the current work. | ||
completeUnitOfWork(unitOfWork); | ||
} else { | ||
workInProgress = next; | ||
} | ||
|
||
if (__DEV__ || !disableStringRefs) { | ||
setCurrentOwner(null); | ||
} | ||
} | ||
|
||
function replaySuspendedUnitOfWork(unitOfWork: Fiber): void { | ||
|
@@ -2399,7 +2396,6 @@ function replaySuspendedUnitOfWork(unitOfWork: Fiber): void { | |
setCurrentDebugFiberInDEV(unitOfWork); | ||
|
||
let next; | ||
setCurrentDebugFiberInDEV(unitOfWork); | ||
const isProfilingMode = | ||
enableProfilerTimer && (unitOfWork.mode & ProfileMode) !== NoMode; | ||
if (isProfilingMode) { | ||
|
@@ -2492,18 +2488,16 @@ function replaySuspendedUnitOfWork(unitOfWork: Fiber): void { | |
// The begin phase finished successfully without suspending. Return to the | ||
// normal work loop. | ||
|
||
resetCurrentDebugFiberInDEV(); | ||
if (__DEV__ || !disableStringRefs) { | ||
resetCurrentFiber(); | ||
} | ||
unitOfWork.memoizedProps = unitOfWork.pendingProps; | ||
if (next === null) { | ||
// If this doesn't spawn new work, complete the current work. | ||
completeUnitOfWork(unitOfWork); | ||
} else { | ||
workInProgress = next; | ||
} | ||
|
||
if (__DEV__ || !disableStringRefs) { | ||
setCurrentOwner(null); | ||
} | ||
} | ||
|
||
function throwAndUnwindWorkLoop( | ||
|
@@ -2893,11 +2887,6 @@ function commitRootImpl( | |
const prevExecutionContext = executionContext; | ||
executionContext |= CommitContext; | ||
|
||
// Reset this to null before calling lifecycles | ||
if (__DEV__ || !disableStringRefs) { | ||
setCurrentOwner(null); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We weren't really initializing this to anything and we were always cleaning it up so I don't think this has been necessary for a while. However, since the life cycles also set the current debug fiber we get the resetting for free regardless - at least in DEV. |
||
|
||
// The commit phase is broken into several sub-phases. We do a separate pass | ||
// of the effect list for each phase: all mutation effects come before all | ||
// layout effects, and so on. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This used to log an
react-test-renderer is deprecated
error which shouldn't be counted towards the rendered errors. It was previously incorrectly associated to the previous tree because the "current fiber" wasn't reset after the commit phase of the previous render.That's why the snapshots below have one less error counted.