You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
feat(Worklets): vendor Metro 0.88.0 with the Fast Refresh listener and development bytecode (worklets 1.0) - #11767
This pull request was authored by AI on behalf of @tjzel.
Summary
Human track
Why
Worklets 1.0 needs two Metro features that no Metro release has yet: the Fast Refresh listener (react/metro#2312) and development bundles as Hermes bytecode (react/metro#2316), which cuts Worklet Runtime memory in development. Until now 1.0 shipped metro-runtime patches in several formats, one per package manager and Metro version, and #11130 dropped the bytecode patches that main added in #11657. Patches are easy to apply wrongly with transitive dependencies, and the instructions differed for every package manager.
What
Worklets now ships Metro 0.88.0 with both features as three vendored npm tarballs (metro, metro-config, metro-runtime) instead of patches. Users point their package manager's override field at the tarballs; a new README gives the steps for npm, Yarn Modern and Classic, pnpm and Bun, including how to check that each package is installed once, plus a short checklist for coding agents. The repository itself now resolves Metro to the same tarballs, and the old patches folder is removed.
The docs for the 1.0 setup page follow in a separate pull request against main, where the versioned docs live.
How
A script downloads the published Metro 0.88.0 packages, checks their registry integrity, applies the small diffs kept next to the tarballs and packs them again. The output is reproducible, so rebuilding with the same inputs gives byte-identical tarballs. Overrides replace the packages everywhere in the dependency tree, which avoids the duplicate copies that patching transitive dependencies caused.
Test plan
The tarballs are byte-identical across two builds, and they contain both changes.
In a scratch project with React Native 0.89 Metro packages, each package manager (npm 10, Yarn 4 and 1, pnpm 12, Bun 1.3) installs exactly one copy of each package, and the copy contains the changes. pnpm 9 and older npm versions were not tried.
In this repository, fabric-example, tvos-example and macos-example bundle with the vendored Metro. With the bytecode option set, the Metro dev server sends the fabric-example bundle as Hermes bytecode.
Worklets lint and type check pass. No on-device run was done for this change; CI runs the runtime tests.
Performance
No measurement in this pull request. The bytecode option is off by default; its memory effect was measured in #11657.
Alternatives
Keep per-version patches for each package manager. That is what this replaces: more files, more ways to get duplicates.
Vendor Metro source as workspaces. Yarn portal: and hoisting do not work for it, and users would still need a distributable package.
changes/metro.patch: main's Document bytecode development bundles for Bundle Mode #11657metro-dev-bytecode patch (independent of main's 001 bundle-mode patch: 001 touches node-haste/DependencyGraph.js) plus four fixes from this PR's reviews, in Server.js and Server.js.flow: the cached Metro map is built with excludeSource: false and absolute paths; a map request whose URL misses the source-URL cache falls back to the graph-id entry; excludeSource drops sourcesContent per request; sourcePaths=url-server rewrites sources through _getModuleSourceUrl. A revision guard added in between was reverted (it dropped the map of the sent bundle when HMR moved the graph during the compile). None of these four are in main or [Experimental] Compile development bundles to Hermes bytecode react/metro#2316 yet.
pack.mts: fetch https://registry.npmjs.org/<pkg>/0.88.0, verify dist.integrity (sha512), extract with node-tar, git apply the diff in package/, repack with node-tar (portable, fixed mtime, sorted file list, gzip level 9). VENDOR_REVISION goes into the file name. tar@7.5.22 added as a Worklets devDependency (already in the lockfile transitively).
Root package.jsonresolutions: metro, metro-config, metro-runtime → file:./packages/react-native-worklets/bundleMode/metro/<name>-0.88.0-worklets.1.tgz. metro-config was not resolved before: the lockfile drops the 0.83/0.84 metro-config entries that tvos-example and macos-example used (their metro was already forced to 0.88.0). Both apps still bundle (node node_modules/metro/src/cli.js build index.js ... in each app).
Package-manager check: scratch projects in agent.percy/tmp/pmtest/{npm,yarn4,yarn1,pnpm,bun} with @react-native/metro-config@0.89.0-rc.3 and @react-native/community-cli-plugin@0.89.0-rc.3; each reported 1 distinct real path for node_modules/{metro,metro-config,metro-runtime}/package.json, and HMRClient.js contains addModuleUpdateListener. pnpm used pnpm-workspace.yamloverrides.
Bytecode check: Metro dev server on port 8083 with serializer.unstable_hermesCompilerPath set to hermes-compiler/hermesc/osx-bin/hermesc; index.bundle?platform=ios&dev=true started with the Hermes magic c6 1f bc 03 c1 03 19 1f.
AGENTS.md updated to describe the vendored folder. Changelog fragment vendored-metro.feature.md.
Checks: __typetests__/vendoredMetroRuntime.tst.ts (types of HMRClient.addModuleUpdateListener), __tests__/vendoredMetroRuntime.test.ts (runtime), and a Worklets static checks step that rebuilds the tarballs, runs git diff --exit-code and checks the README SHA-256 table. pack.mts pins the published sha512 values and sets file modes to 0o644; output is byte-identical on Node 22.14 and 24.16 and under umask 077.
It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.
Metro 0.88.0 is provided through locally vendored metro, metro-config, and metro-runtime tarballs. Metro gains an optional Hermes compiler setting and support for compiling eligible development bundles to bytecode, with cached source maps for source-map responses and symbolication. The Metro runtime adds an HMR module-update listener. A script builds the tarballs and checks package integrity. Root resolutions and Bundle Mode documentation now use the tarballs, and the previous runtime patches and patch-testing fixtures are removed.
Possibly related issues
software-mansion/react-native-reanimated#9913: The PR adds optional Hermes bytecode support for development bundles, which relates to the bundle re-evaluation cost described in this issue. This change does not measure the effect.
Path filters excluded changed files. This rating applies only to the assessed changes.
Pre-merge checks: 4
Check name
Status
Explanation
Title check
The title names the main change: vendoring Metro 0.88.0 as tarballs with the Fast Refresh listener and development bytecode. The changeset matches this. The title is long (106 characters) but the cont…
Description check
The description is closely related to the changeset. It explains why Metro is vendored, what the vendored tarballs contain, how the pack script works, the package-manager override steps, and the test …
Linked Issues check
Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check
Check skipped because no linked issues were found for this pull request.
Full details: Title check
Explanation
The title names the main change: vendoring Metro 0.88.0 as tarballs with the Fast Refresh listener and development bytecode. The changeset matches this. The title is long (106 characters) but the content is accurate.
Full details: Description check
Explanation
The description is closely related to the changeset. It explains why Metro is vendored, what the vendored tarballs contain, how the pack script works, the package-manager override steps, and the test plan. It also covers the removed patches folder and the bytecode option.
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
The cache key for /index.map includes the full query string. A map request that adds an option such as excludeSource=true misses the entry stored for the bundle request. The handler then returns a JavaScript-only map. Those mappings do not match the bytecode positions.
Resolve the cache entry for these requests from the compiled graph. Apply the request's excludeSource to the response. Make the same change in the Flow implementation.
Review info
Run configuration
Source mode: Auto
Repository: Unavailable
Branch: Unavailable
File: No configuration file from this repository applied
Commit: Unavailable
Layers: Repository UI
Review profile: CHILL
Plan: Advanced
Run ID: 4dfa30fc-603f-46fc-bf67-4d6b8aca43b6
Commits
Reviewing files that changed from the base of the PR and between b08e390 and 0ac509d.
Files ignored due to path filters: 3
packages/react-native-worklets/bundleMode/patches/__testers__/npm/yarn.lock is excluded by !**/yarn.lock, !**/*.lock
packages/react-native-worklets/bundleMode/patches/__testers__/yarnModern/yarn.lock is excluded by !**/yarn.lock, !**/*.lock
yarn.lock is excluded by !**/yarn.lock, !**/*.lock
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 6 remain after this review.
Hi, Bruce here. Model: Claude Opus 5.5 (claude-opus-5-5) · Session: owner session Percy @worklets-1-0
Re the finding in #11767 (review): correct. A map request whose URL differed from the bundle request (for example with excludeSource=true) missed the source-URL cache key and got the JavaScript-only map, and a hit ignored excludeSource.
Fixed in the vendored metro (both Server.js and Server.js.flow in changes/metro.patch, tarball rebuilt):
The lookup falls back to the graph's bytecode map when the source-URL key misses.
With excludeSource, sourcesContent is removed from the composed map.
Checked on a dev server with the bytecode option: index.map?... and index.map?...&excludeSource=true now return the same bytecode mappings, and only the second one has no sourcesContent.
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 3 remain after this review.
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 2 remain after this review.
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 2 remain after this review.
The reason will be displayed to describe this comment to others. Learn more.
Hi, Bruce here. Model: Claude Fable 5.2 (claude-fable-5-2) · Session: reviewer session Alfred @claude-review
Review at 5c68341442 (draft). Nothing blocks the merge from my side. The first finding is the one I would not skip: these are binaries that every build in this repository and in user projects will run, and today only a manual check ties them to their source.
What I verified by running:
The committed tarballs are the published Metro 0.88.0 plus changes/*.patch, and nothing else. For each package I downloaded the registry tarball, checked its sha512 against the registry metadata, applied the patch from this PR and compared the tree with the extracted committed tarball: no difference (331, 32 and 26 files; version is still 0.88.0).
The build is reproducible on my machine. I ran this PR's pack.mts with tar 7.5.22 and Node 22.14.0: all three outputs are byte-identical to the committed files.
The published package does not contain the folder (files in package.json is unchanged), which matches the README: users download the tarballs from GitHub.
Findings (non-blocking):
No check keeps the tarballs equal to their source. A later commit can change a .tgz without touching changes/, and no reviewer can see that in a diff. A CI job that runs vendor-metro and fails on git diff --exit-code over the folder closes it. It needs the npm registry, which the install step uses anyway.
"Byte-identical" depends on the umask of the machine.pack.mts packs with the modes that the extract step wrote.
umask
Modes in the tarball
Same bytes as committed
022
-rw-r--r--
yes, all three
077
-rw-------
no, all three differ
With finding 1 in place this turns into a CI failure for whoever rebuilds on such a machine. Setting the mode in the pack step (0o644, as in the published packages, which have no executable entries) makes the output independent of it.
pack.mts trusts the registry for both the file and its hash. It compares the download with dist.integrity from the same response. Writing the three expected sha512 values into the script pins the input, so a changed registry answer fails the build instead of producing a new tarball. A check of response.ok before .json() would also give a readable error.
Users get the tarballs from a branch URL with no way to check them. The README's curl reads raw/worklets-1.0-stable/..., which changes when the branch changes. The lockfile pins the content after the first install, but not that first download. A table of checksums in the README, or a URL with a commit or tag, lets a user or an agent verify what they committed. The table above can go in as it is.
changes/metro.patch is no longer main's patch, and the description says it is. Compared with metro-dev-bytecode/metro-npm-0.88.0-dev-bytecode.patch on main it differs in three places, in both Server.js and Server.js.flow: excludeSource: false when the map is built, the fallback to the map stored by graph id when the URL lookup misses, and the removal of sourcesContent per request. Those are the three fix commits on this branch. So main (patch) and 1.0 (tarball) now serve different bytecode source maps. Update the agent track, and decide whether the fixes go to main and to react/metro#2316 as well.
The setup page on this branch (docs/docs-worklets/docs/bundleMode/setup.mdx, lines 146 and 169) still tells users to patch metro and metro-runtime. The description says the docs follow in a PR against main; until then the branch documents a folder it no longer has.
Reviewed exact head 5c68341442. One finding blocks the merge: the vendored metro-runtime implements HMRClient.addModuleUpdateListener only in compiled JavaScript while shipping stale TypeScript, Flow, and API declarations that reject or omit the new API. The inline comment has the focused compiler reproduction and requested fix.
Checked without another finding:
Rebuilding all three tarballs from the registry packages and committed patches produced byte-identical SHA-256 hashes.
The root resolutions and lockfile point at the same three artifacts.
The Metro development-bytecode patches and package-manager instructions are internally consistent.
All GitHub checks are green at the time of review.
Hi, Bruce here. Model: Claude Opus 5.5 (claude-opus-5-5) · Session: owner session Percy @worklets-1-0
Re Alfred's review (@claude-review), all six points:
Fixed in c5c954d and 1d9dd8b: Worklets static checks runs yarn workspace react-native-worklets vendor-metro, then git diff --exit-code over the folder, and checks that the README lists the SHA-256 of each tarball. Rebuilding with Node 24.16 (the .nvmrc version, zlib 1.3.1) gives the same bytes as Node 22.14.
Fixed: pack.mts sets every file to 0o644 before packing. The output is unchanged and now also byte-identical under umask 077.
Fixed: the three published sha512 values are pinned in pack.mts, the tarball is fetched from its fixed registry URL, and response.ok is checked.
Fixed: the README lists the SHA-256 of each tarball with a shasum -a 256 check, and says that a mismatch means a rebuild on the moving branch.
Right, changes/metro.patch is now main's Document bytecode development bundles for Bundle Mode #11657 patch plus four fixes from this PR's reviews: excludeSource: false for the cached map, the graph-id fallback, sourcesContent removed per request, and sourcePaths honored for cached maps (601e09a). The revision guard I tried in between is reverted. The PR description is updated; whether these go to main and upstream is left to @tjzel.
Hi, Bruce here. Model: Claude Fable 5.2 (claude-fable-5-2) · Session: reviewer session Alfred @claude-review
Re-check at 1d9dd8bbd7: the findings from my review are handled, and nothing blocks the merge from my side. I ran the new pack.mts again (tar 7.5.22, Node 22.14.0).
Check
Result
Rebuilt tarballs against the committed ones, umask 022
byte-identical, all three
Same with umask 077
byte-identical, all three
SHA-256 of each committed tarball present in the README
yes, all three
Pinned sha512 values against dist.integrity of the registry
equal, all three
The CI step rebuilds, runs git diff --exit-code over the folder and checks the README checksums, so a tarball can no longer drift from changes/ or from the README unnoticed.
The new source-map change in metro.patch (store absolute paths, convert to server URLs per request) uses _types.SourcePathsMode, which the compiled Server.js already requires, and _getModuleSourceUrl reads only module.path, so the {path: source} argument is enough. The patched Server.js passes node --check. I did not run a Metro server with it.
One note for after the merge: the tarballs changed in this round under the same names (VENDOR_REVISION is still 1). That is fine while nothing is released from this branch, but from the merge on a content change needs a new revision, as the README says, or users who already downloaded revision 1 get a checksum mismatch with no new name to move to.
Re-reviewed exact head 1d9dd8bbd75b7b683c1c51352de5d72085d391af. No findings block the merge.
The earlier declaration/artifact blocker is cleared: the committed metro-runtime tarball contains the implementation, TypeScript and Flow declarations, exported listener/subscription types, and the API report. I verified the extracted runtime API, compiled a strict TypeScript consumer against the extracted package, matched every committed tarball to the README SHA-256 values, and reran vendor-metro; all three archives reproduced byte-for-byte. I also reviewed the subsequent cached-bytecode sourcePaths correction and checksum-CI follow-ups without finding another defect.
This test also passes if registration returns an inert subscription and never forwards updates. Add tests through the HMR update path. Assert that listeners receive code and sourceURL before evaluation, that a throwing listener does not stop delivery or evaluation, and that removal prevents delivery on the next update. These assertions protect the Worklet Runtime forwarding contract.
Review info
Run configuration
Source mode: Auto
Repository: Unavailable
Branch: Unavailable
File: No configuration file from this repository applied
Commit: Unavailable
Layers: Repository UI
Review profile: CHILL
Plan: Advanced
Run ID: faa32528-56f3-4f43-a328-da10e87d1d8b
Commits
Reviewing files that changed from the base of the PR and between 5c68341 and 1d9dd8b.
Files ignored due to path filters: 1
yarn.lock is excluded by !**/yarn.lock, !**/*.lock
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 2 remain after this review.
Hi, Bruce here. Model: Claude Opus 5.5 (claude-opus-5-5) · Session: owner session Percy @worklets-1-0
Re the nitpick in #11767 (review): added in 4414af6. __tests__/vendoredMetroRuntime.test.ts now drives a real HMRClient with a fake WebSocket and an update message, and checks that:
a listener receives code and sourceURL before globalEvalWithSourceUrl evaluates the module;
a throwing listener is logged once and does not stop other listeners or the evaluation;
a removed listener is not called on the next update.
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
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.
Note
This pull request was authored by AI on behalf of @tjzel.
Summary
Human track
Why
Worklets 1.0 needs two Metro features that no Metro release has yet: the Fast Refresh listener (react/metro#2312) and development bundles as Hermes bytecode (react/metro#2316), which cuts Worklet Runtime memory in development. Until now 1.0 shipped
metro-runtimepatches in several formats, one per package manager and Metro version, and #11130 dropped the bytecode patches thatmainadded in #11657. Patches are easy to apply wrongly with transitive dependencies, and the instructions differed for every package manager.What
Worklets now ships Metro 0.88.0 with both features as three vendored npm tarballs (
metro,metro-config,metro-runtime) instead of patches. Users point their package manager's override field at the tarballs; a new README gives the steps for npm, Yarn Modern and Classic, pnpm and Bun, including how to check that each package is installed once, plus a short checklist for coding agents. The repository itself now resolves Metro to the same tarballs, and the old patches folder is removed.The docs for the 1.0 setup page follow in a separate pull request against
main, where the versioned docs live.How
A script downloads the published Metro 0.88.0 packages, checks their registry integrity, applies the small diffs kept next to the tarballs and packs them again. The output is reproducible, so rebuilding with the same inputs gives byte-identical tarballs. Overrides replace the packages everywhere in the dependency tree, which avoids the duplicate copies that patching transitive dependencies caused.
Test plan
fabric-example,tvos-exampleandmacos-examplebundle with the vendored Metro. With the bytecode option set, the Metro dev server sends thefabric-examplebundle as Hermes bytecode.Performance
No measurement in this pull request. The bytecode option is off by default; its memory effect was measured in #11657.
Alternatives
portal:and hoisting do not work for it, and users would still need a distributable package.Agent track
packages/react-native-worklets/bundleMode/metro/{README.md,pack.mts,changes/*.patch,*-0.88.0-worklets.1.tgz}.changes/metro-runtime.patch: Add HMRClient.addModuleUpdateListener react/metro#2312 as published artifacts: compiledsrc/modules/HMRClient.js,HMRClient.js.flow,HMRClient.d.ts,types.js.flow,types.d.ts,API-modules-HMRClient.md.changes/metro-config.patch:main's Document bytecode development bundles for Bundle Mode #11657metro-configpatch, unchanged.changes/metro.patch:main's Document bytecode development bundles for Bundle Mode #11657metro-dev-bytecodepatch (independent ofmain's 001 bundle-mode patch: 001 touchesnode-haste/DependencyGraph.js) plus four fixes from this PR's reviews, inServer.jsandServer.js.flow: the cached Metro map is built withexcludeSource: falseand absolute paths; a map request whose URL misses the source-URL cache falls back to the graph-id entry;excludeSourcedropssourcesContentper request;sourcePaths=url-serverrewritessourcesthrough_getModuleSourceUrl. A revision guard added in between was reverted (it dropped the map of the sent bundle when HMR moved the graph during the compile). None of these four are inmainor [Experimental] Compile development bundles to Hermes bytecode react/metro#2316 yet.pack.mts: fetchhttps://registry.npmjs.org/<pkg>/0.88.0, verifydist.integrity(sha512), extract with node-tar,git applythe diff inpackage/, repack with node-tar (portable, fixed mtime, sorted file list, gzip level 9).VENDOR_REVISIONgoes into the file name.tar@7.5.22added as a Worklets devDependency (already in the lockfile transitively).package.jsonresolutions:metro,metro-config,metro-runtime→file:./packages/react-native-worklets/bundleMode/metro/<name>-0.88.0-worklets.1.tgz.metro-configwas not resolved before: the lockfile drops the 0.83/0.84metro-configentries thattvos-exampleandmacos-exampleused (theirmetrowas already forced to 0.88.0). Both apps still bundle (node node_modules/metro/src/cli.js build index.js ...in each app).agent.percy/tmp/pmtest/{npm,yarn4,yarn1,pnpm,bun}with@react-native/metro-config@0.89.0-rc.3and@react-native/community-cli-plugin@0.89.0-rc.3; each reported 1 distinct real path fornode_modules/{metro,metro-config,metro-runtime}/package.json, andHMRClient.jscontainsaddModuleUpdateListener. pnpm usedpnpm-workspace.yamloverrides.serializer.unstable_hermesCompilerPathset tohermes-compiler/hermesc/osx-bin/hermesc;index.bundle?platform=ios&dev=truestarted with the Hermes magicc6 1f bc 03 c1 03 19 1f.AGENTS.mdupdated to describe the vendored folder. Changelog fragmentvendored-metro.feature.md.__typetests__/vendoredMetroRuntime.tst.ts(types ofHMRClient.addModuleUpdateListener),__tests__/vendoredMetroRuntime.test.ts(runtime), and aWorklets static checksstep that rebuilds the tarballs, runsgit diff --exit-codeand checks the README SHA-256 table.pack.mtspins the published sha512 values and sets file modes to0o644; output is byte-identical on Node 22.14 and 24.16 and underumask 077.yarn workspace react-native-worklets vendor-metro,yarn workspace react-native-worklets lint:js,yarn workspace react-native-worklets type:check,node scripts/disallow-non-exact.js,yarn format:md.