Repository navigation
fix(🌐): build the React reconciler on the first render, not at import (2.x backport of #4546) - #4547
Open
wcandillon wants to merge 1 commit into
Open
wcandillon wants to merge 1 commit into
wcandillon wants to merge 1 commit into
Conversation
… (2.x backport of #4546) Backport of #4546 to 2.x. Building a reconciler hooks it into the React instance for the lifetime of the process: createReconciler() wraps ReactSharedInternals.S around the hook already there. sksg/Reconciler.ts built one when the module was evaluated, so a server that evaluates the bundle once per request against a single React instance, as the Expo dev server does for web, kept one reconciler per request, and the whole bundle behind it. The reconciler is now built by the first render, along with its DevTools registration. The React root of a SkiaSGRoot is created by the first render as well, not by the constructor: a Canvas constructs its root while it renders, which a server does too, and renders into it from a layout effect, which a server never runs. Unmounting a root that never rendered resolves without a commit.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Backport of #4546 to 2.x, for #4544 (reported against 2.14.0).
sksg/Reconciler.tsbuilt its React reconciler when the module was evaluated. Building a reconciler hooks it into the React instance for good:createReconciler()wrapsReactSharedInternals.Saround the hook already there. The Expo dev server evaluates the whole server bundle again for every web request, against one sharedreact, so every request left one more reconciler reachable from React, and the whole evaluated bundle behind it.The root cause is on the Expo side (expo/expo#54308); this is a mitigation on ours. Nothing changes for a client: the reconciler is built by the first render into a canvas instead of at import.
Agent-written content
Summary
Same change as #4546, applied to the 2.x
Reconciler.ts:getReconciler()), andinjectIntoDevTools()moves along with it.SkiaSGRootcreates its React root in the firstrender(), not in its constructor:<Canvas>constructs itsSkiaSGRootin auseMemo, during render, which a server does too, and renders into it from a layout effect, which a server never runs.unmount()on a root that never rendered resolves right away, without committingnullinto an empty root.Differences from #4546
createContainer(react-reconciler 0.31.0) and keeps its@ts-expect-erroroninjectIntoDevTools().CanvasServerRender.spec.tsxresolvesSkiaPictureViewNativeComponentto its web module, the name of the native component on 2.x.LazyReconciler.spec.tsxis unchanged.Local verification
Run in a worktree of 2.x with its own dependencies installed from the 2.x lockfile (React 19.0.0, react-reconciler 0.31.0):
yarn tsc,eslinton the changed files and the fullyarn jestrun inpackages/skiapass (108 suites, 845 tests).Reconciler.tsit replaces, and fails after the render against a version that builds the reconciler lazily but still creates the root in the constructor.