Repository navigation
Bug: a portal that mounts in a transition with a not-yet-settled node as its own child throws when it is replayed (stateNode was reset to null), and the unwind then pops the fiber stack twice: a context's default value becomes null for the rest of the page's life #38389
Description
React version
19.3.1 (react and react-dom from npm, no framework), development and production builds.
Also reproduced, same result, on 19.0.0, 19.1.10, 19.2.9 and on 19.3.0-canary-89d7b2b4-20261123.
The code path is unchanged on main at 92bb0678c5 (24 November 2026).
Steps to reproduce
- Save the page below as
index.htmland open it in a browser (it loads React from esm.sh; nothing to build). - Press "Mount the portal".
The whole reproduction (43 lines):
<!doctype html>
<meta charset="utf-8" />
<title>A portal whose own child settles a moment after it starts to mount</title>
<div id="root"></div>
<div id="portal"></div>
<pre id="log"></pre>
<script type="module">
import { createContext, createElement as h, Fragment, startTransition, useContext, useState, version } from "https://esm.sh/[email protected]?dev";
import { createPortal } from "https://esm.sh/[email protected]?dev";
import { createRoot } from "https://esm.sh/[email protected]/client?dev";
const log = (line) => (document.getElementById("log").textContent += line + "\n");
const Theme = createContext("default");
// Not under any <Theme.Provider>: must always read "default".
function OutsideTheProviders() {
return h("p", { id: "outside" }, "Theme outside the providers: " + String(useContext(Theme)));
}
function App() {
const [late, setLate] = useState(null);
// A node that is pending when React first renders it and settles one microtask
// later. (A Server Components payload hands client components such nodes all
// the time: a lazy node whose row arrives a moment after its parent's.)
const mount = () => startTransition(() => setLate(Promise.resolve(h("b", null, "portal content"))));
return h(
Fragment,
null,
h("button", { id: "mount", onClick: mount }, "Mount the portal"),
h(
Theme.Provider,
{ value: "outer" },
h(Theme.Provider, { value: "inner" }, late && createPortal(late, document.getElementById("portal"))),
),
h(OutsideTheProviders),
);
}
log("react " + version);
createRoot(document.getElementById("root"), {
onRecoverableError: (error) => log("onRecoverableError: " + error.message + "\n cause: " + (error.cause && error.cause.stack)),
}).render(h(App));
</script>Remove ?dev from the three imports for the production build. The same component written in JSX in an
ordinary bundled app (esbuild, react and react-dom from npm) behaves identically; that is what the table
below was measured on.
The current behavior
Before the press the page reads Theme outside the providers: default. After it:
onRecoverableErroris called with "There was an error during concurrent rendering but React was able to
recover by instead synchronously rendering the entire root." (error Fix error in test logging #520 in production), whosecauseis
TypeError: Cannot read properties of null (reading 'containerInfo');- the development build also logs
Unexpected Fiber popped.(7 times here) andUnexpected pop.(3 times); - the portal's content does appear, but the page now reads
Theme outside the providers: null: a consumer
that is under no provider no longer gets the context's default value. It staysnullon every later
render. In a larger tree the wrong values go on to break later renders in other ways (for example
Cannot read properties of undefined (reading 'containerTagInScope')fromisHostHoistableType, and
Cannot read properties of undefined (reading 'signal')fromretainCachein a later passive-effects
commit), and a boundary that was waiting for data stays on its fallback.
Stack of the cause (development build, 19.3.1):
TypeError: Cannot read properties of null (reading 'containerInfo')
at beginWork
at replayBeginWork
at runWithFiberInDEV
at replaySuspendedUnitOfWork
at renderRootConcurrent
at performWorkOnRoot
at performWorkOnRootViaSchedulerTask
at MessagePort.performWorkUntilDeadline
Measured in headless Chromium, 10 page loads per cell, one press per load:
| react | build | what the portal is given | mounted in a transition | TypeError (containerInfo) |
context default lost | Unexpected Fiber popped. |
|---|---|---|---|---|---|---|
| 19.3.1 | development | the late node itself | yes | 10/10 | 10/10 | 10/10 |
| 19.3.1 | production | the late node itself | yes | 10/10 | 10/10 | n/a |
| 19.3.0-canary-89d7b2b4-20261123 | development | the late node itself | yes | 10/10 | 10/10 | 10/10 |
| 19.3.0-canary-89d7b2b4-20261123 | production | the late node itself | yes | 10/10 | 10/10 | n/a |
| 19.2.9 | development / production | the late node itself | yes | 10/10 | 10/10 | 10/10 (dev) |
| 19.1.10 | development / production | the late node itself | yes | 10/10 | 10/10 | 10/10 (dev) |
| 19.0.0 | development / production | the late node itself | yes | 10/10 | 10/10 | 10/10 (dev) |
| every version above | both | <Wrapper>{late}</Wrapper> (a component that returns its children) |
yes | 0/10 | 0/10 | 0/10 |
| every version above | both | <span>{late}</span> |
yes | 0/10 | 0/10 | 0/10 |
| every version above | both | the late node itself | no (setLate outside startTransition) |
0/10 | 0/10 | 0/10 |
The portal's content was shown in every load of every cell.
The expected behavior
The portal mounts when its child settles, as it does when the same node is one level further down
(createPortal(<Wrapper>{late}</Wrapper>, target)): no error, nothing logged, and
Theme outside the providers: default before and after.
What happens, as far as I can read it
beginWorkfor the mountingHostPortalfiber pushes the host container and reconciles its children.
The child is a thenable that is still pending, so the reconciler suspends (SuspenseException) with the
portal fiber as the suspended unit of work.- The thenable settles before the work loop looks again (
SuspendedOnImmediate->
SuspendedAndReadyToContinue), soreplaySuspendedUnitOfWorkruns.replayBeginWorkhas no case for
HostPortal, so it takes the default branch (ReactFiberWorkLoop.js):
unwindInterruptedWork(current, unitOfWork, ...), thenresetWorkInProgress(unitOfWork, ...), then
beginWork(...)again. resetWorkInProgress(ReactFiber.js) setsworkInProgress.stateNode = nullwhencurrent === null.
A portal fiber'sstateNode({ containerInfo, pendingChildren, implementation }) is only ever set in
createFiberFromPortal, so the replayed fiber has lost it.updatePortalComponent(ReactFiberBeginWork.js) starts with
pushHostContainer(workInProgress, workInProgress.stateNode.containerInfo)and throws theTypeError
before pushing anything.- The error is handled as a render error:
throwAndUnwindWorkLoop->unwindWork, whoseHostPortal
case callspopHostContainer(workInProgress)again. Step 2 had already popped the portal's three
entries, so these three pops take entries that belong to the portal's ancestors. Every pop after that
restores a value into the wrong cursor; with two context providers above the portal,popProvider
writes a wrong value (herenull) into the context's_currentValue, which is what a consumer under no
provider reads from then on.
updateOffscreenComponent already copes with the same reset for its own fiber (it re-creates stateNode
when it is null on mount); the portal has nothing like it. A <Profiler> has the same shape in development
builds: with the late node as the Profiler's own child the replay fails with
TypeError: Cannot set properties of null (setting 'effectDuration') (19.3.1, development; nothing in
production, and no stack warnings since a Profiler pushes nothing).
Where this comes from in practice
A client component that receives server-rendered content as a prop and hands it straight to createPortal
(createPortal(props.actions, place)). When part of that content is an async Server Component, the prop
is a lazy node whose row has not arrived yet. During a client navigation (a transition) the portal mounts
with that pending node as its own child; when the row arrives within the same tick, the portal is replayed
and fails as above. In an application it shows as an intermittent failure (about 1 navigation in 40 in the
case that led here), because it needs the row to arrive in exactly that window.
What I checked
- Versions and builds in the table; the page above in Chromium for 19.3.1, development and production.
- The same tree under jsdom in Node gives the same error and the same lost context default (development
and production). - It needs all three: the portal is mounting (not updating), the pending node is the portal's own child
(directly, or through a fragment, which the reconciler opens), and the render is one that can be replayed
(a transition). A component or a host element between the portal and the node avoids it, which is the
workaround. - Other parents with the same late node as their own child, 19.3.1: a fragment, a host element, a Suspense
boundary, a context provider and StrictMode are fine; a Profiler fails in development as noted above. - I searched the issues for
containerInfo,createPortalwith replay,resetWorkInProgress,
replayBeginWorkandUnexpected Fiber poppedand found no report of this. Related, same replay path
with another fiber type: Bug: hydration cursor is not rewound when a host fiber is replayed, so hydration fails on an identical tree #37584 (a replayed host fiber during hydration, fixed) and Bug: hydration mismatch when a suspended <head> (HostSingleton) is replayed — singleton-scope cursor is saved twice #37551 with PR [Fiber] Restore the singleton scope when replaying a suspended HostSingleton #37630
(a replayed HostSingleton).
A possible direction
Either keep the portal's stateNode across resetWorkInProgress (it describes where the portal draws, not
work in progress), or have replayBeginWork treat HostPortal without the full reset. Separately, a
beginWork that throws during a replay, after unwindInterruptedWork has already popped the fiber, should
not be unwound through unwindWork for that same fiber a second time.
Activity
omerfarukgurbuz commentedon Nov 25, 2026
I’ll investigate the mounting portal case on current main. I’ll start with a regression test that resolves the portal’s child during a transition and checks both the portal contents and the context value outside the providers.