fix(mobile): patch metro so release bundles can hash Bundle Mode worklets
Summary
- Apply upstream's
metropatch viabun patchso cold release bundles stop failing withFailed to get the SHA-1. This is what errored the first two iOS production builds (7 and 8, 2026-08-13), both in the Bundle JavaScript phase. - No dependency versions change: worklets 0.8.3 / reanimated 4.3.1 (Expo SDK 56's pinned pairing) stay as-is.
Why / Context
apps/mobile runs worklets Bundle Mode, required by react-native-streamdown (babel.config.js). Its Babel plugin writes each worklet to node_modules/react-native-worklets/.worklets/<hash>.js during the transform pass — after Metro has already crawled the filesystem. Metro then can't hash a file that was never in its file map and throws.
The dev server survives because it re-crawls on file events, and a local machine usually has .worklets already populated from a previous run. A one-shot bundle from a clean install — expo export, and therefore every EAS build — fails 100% of the time. That asymmetry is why this only surfaced at store-build time.
Upgrading worklets does not fix it: 0.11.4 with reanimated 4.5.3 (the newest peer-compatible pairing; 0.12.0 has no stable reanimated partner yet) fails identically, and it moves off the versions Expo SDK 56 pins and tests. Reverted.
How It Works
patches/metro@0.84.4.patch is upstream's patch, taken verbatim from bundleMode/patches/patch-package/metro. It makes DependencyGraph.getOrComputeSha1 return a synthetic hash for any path under react-native-worklets/.worklets instead of consulting the file map. Software Mansion documents this as the recommended fix in the Bundle Mode setup guide, temporary until the change lands in Metro.
patches/README.md requires a guard test for every patch, and this one earns it: patchedDependencies is keyed to an exact version, so the next Expo SDK bump moves Metro, silently drops the patch, and breaks the store build again with no other signal.
Manual QA Checklist
Reproduced from the EAS cold state — node_modules/react-native-worklets/.worklets emptied down to the dummy.md the package ships:
-
npx expo export --platform ios --clearfails withFailed to get the SHA-1before the patch (3/3 attempts, including on worklets 0.11.4) - Same command succeeds after the patch, emitting an 11MB
.hbc - Succeeds on a second cold run with
.workletsre-emptied -
bun installapplies the patch on a clean tree (patchedDependencies+bun.lock) - EAS production build succeeds end-to-end — in flight, build a8b4bc71. Native compilation is past what a JS bundle test covers, so this is the real acceptance gate; will confirm on this PR before merge.
Testing
bun run lintbun run typecheck(mobile, clean)bun test apps/mobile/metro-worklets-patch.test.ts
Design Decisions
- Patch Metro instead of a warm-up bundle in
eas-build-post-install: a throwawayexpo exportbefore the real one would also work, but it doubles bundle time on every build and hides the reason. The patch is upstream's own, ~10 lines, and self-documents inpatches/README.md. - Stay on Expo SDK 56's pinned versions: the upgrade path was tested first and doesn't fix the bug, so taking it would only add unverified native changes days before an App Store submission.
metro-runtimepatch not applied: upstream also publishes one that extends Fast Refresh to worklet runtimes. Dev-only ergonomics, not a build fix — left out to keep this scoped.
Risks / Rollout
- Risk: low, build-tooling only. The patch narrows to paths containing
react-native-worklets/.worklets; every other module still gets a real content hash. Worst case is worklet modules missing transform-cache reuse. - Rollback: delete the
patchedDependenciesentry, the patch file, and the guard test. Reverts to today's behavior — where iOS release builds don't build at all.
Summary by cubic
Patches metro@0.84.4 so release bundles can hash Bundle Mode worklets. Before: cold expo export/EAS builds failed with “Failed to get the SHA-1” for generated files under react-native-worklets/.worklets. Now: Metro returns a synthetic hash for those paths, allowing bundling to complete.
- Applies upstream
metropatch viapatchedDependencies/bun patch; scope limited to.workletspaths. - Strengthens the guard test to read repo files (
bun.lockand the patch) instead of module resolution; asserts every resolvedmetroversion is patched and the patch contains the.workletsshort-circuit. - Formats the guard test with Biome (no behavior change).
- Keeps
react-native-worklets0.8.3 andreact-native-reanimated4.3.1 (Expo SDK 56) unchanged. - On future
metrobumps: regenerate and commit the patch (seepatches/README.md), then runbun test apps/mobile/metro-worklets-patch.test.ts.
Summary by CodeRabbit
-
New Features
- Added support for React Native Worklets Bundle Mode with Metro 0.84.4.
- Worklets-generated files now receive dynamic hashes, helping ensure bundle updates are recognized correctly.
-
Bug Fixes
- Prevented stale bundle results when Metro processes generated Worklets files.
-
Documentation
- Added guidance for the Metro patch, verification steps, version updates, and maintenance workflow.