Worklets: propagateModuleUpdate is shipped but never called, so worklets do not hot-reload
Description
react-native-worklets ships propagateModuleUpdate natively, but nothing in the package's JS ever calls it, and Metro's HMR entry point doesn't either. So a worklet never learns about a Fast Refresh update and keeps executing the previous version of an edited module until a full reload.
Filing here because react-native-worklets has issues disabled and its package.json routes bugs to this repo.
Half 1 — the update never reaches the worklet runtime.
propagateModuleUpdate is implemented natively and exported on the module proxy, in both the version we ship (0.10.1) and latest (0.13.0):
Common/cpp/worklets/NativeModules/JSIWorkletsModuleProxy.cpp
Common/cpp/worklets/WorkletRuntime/RuntimeManager.cpp (0.13.0)Nothing in the package's JS or TS calls it:
grep -rn "propagateModuleUpdate" package/src package/lib # -> no outputAnd Metro's HMR entry point evals the new module into the React runtime and nothing else:
// metro-runtime/src/modules/HMRClient.js @ 0.87.1
const inject = ({ module: [id, code], sourceURL }) => {
if (global.globalEvalWithSourceUrl) {
global.globalEvalWithSourceUrl(code, sourceURL);
} else {
eval(code);
}
};So the native capability is reachable and unreached.
Half 2 — Metro's content hash suppresses the rebuild before HMR is even reached.
Metro caches by file sha1, so a worklet file whose content hasn't changed isn't reprocessed even when its generated worklet output should change. 0.13.0 has no .worklets sha1 or DependencyGraph handling of its own (grep -rn "getOrComputeSha1\|\.worklets" package/src → nothing).
Suggested fix
The host integration we carry is two lines, at the top of Metro's inject:
if (global.__workletsModuleProxy?.propagateModuleUpdate) {
global.__workletsModuleProxy.propagateModuleUpdate(code, sourceURL);
}The optional chaining is what makes it safe: on a build without worklets, or a version without the method, it's a no-op.
The ask is that react-native-worklets install this hook itself, so the method it already ships is actually invoked. bundleMode/metroOverrides.native.ts (0.13.0) already establishes that this package is willing to own Metro-facing dev-mode shims — it currently only silences HMR warnings on worklet runtimes, which is adjacent to, but not, this.
For half 2 we currently carry this, in Metro itself:
// metro/src/node-haste/DependencyGraph.js
const workletsDirPath = _path.default.join("react-native-worklets", ".worklets");
// inside getOrComputeSha1(mixedPath):
if (mixedPath.includes(workletsDirPath)) {
return { sha1: createHash("sha1").update(performance.now().toString()).digest("hex") };
}We are not proposing that one upstream and would not want it merged as written — it's unconditional cache defeat for a path, and it puts knowledge of a third-party package inside Metro, which Metro would be right to refuse. It's included only because without it the first half has no update to propagate. If there's a supported way for a package to invalidate a directory from its own Metro config — a resolver or transformer hook we've missed — that's the answer we'd prefer, and this issue can be treated as being about half 1 only.
Steps to reproduce
We don't have a self-contained behavioural repro and would rather say so than hand over something that doesn't run: one needs an RN app, a dev server, and a worklet edited under Fast Refresh. Happy to build it if the static form below isn't enough to act on.
What is runnable is a verification of the mechanism against the published packages. Needs only npm and tar:
- Download
probe.shfrom the gist below bash probe.sh
Output (also in the gist):
== [email protected] ==
native implementation (C++): 3 file(s)
callers in the package JS/TS: 0 <-- nothing invokes what it ships
own Metro cache handling: 0
== [email protected] ==
native implementation (C++): 1 file(s)
callers in the package JS/TS: 0 <-- nothing invokes what it ships
own Metro cache handling: 0
== [email protected] (latest): does HMR notify worklets? ==
propagateModuleUpdate in HMRClient: 0 <-- the update never reaches a worklet runtimeOr the three commands directly:
npm pack [email protected] && tar xzf react-native-worklets-0.13.0.tgz
grep -rl "propagateModuleUpdate" package/ # -> C++ only
grep -rn "propagateModuleUpdate" package/src package/lib # -> nothing calls it
grep -rn "getOrComputeSha1\|\.worklets" package/src # -> nothingSnack or a link to a repository
https://gist.github.com/pawarren/54902d691240ed0f50f77907d90b0a8a
Reanimated version
4.5.1
Worklets version
0.10.1 (finding verified unchanged in 0.13.0, latest)
React Native version
0.86.3
Platforms
Android, iOS
JavaScript runtime
Hermes
Workflow
Expo managed workflow
Architecture
Fabric (New Architecture)
Build type
Debug app & dev bundle
Device
Real device
Source: software-mansion/react-native-reanimated