Repository navigation
Commit a83496b
authored
Keep Reanimated deep imports out of web bundles (#4620)
## Description
#4554 gates `Wrap.getAnimatableRef()` on whether Reanimated re-resolves
the animatable ref on update. The check deep-imports
`react-native-reanimated/src/createAnimatedComponent/AnimatedComponent`
and looks for `_refreshComponentRef` on its prototype. It lives in
`reanimatedWrapper.ts`, which every platform loads.
Reanimated has no `exports` map. Its `react-native` field points at
`src/`, but `main` and `module` point at `lib/module`. Bundlers that
ignore the `react-native` field (Vite, webpack) therefore resolve the
package root to `lib/module` and the deep import to `src/`, which is a
second copy of Reanimated. In Vite dev the optimizer leaves the `.tsx`
deep import as a raw import, and
`src/platform-specific/workletsVersion.ts` default-imports a CommonJS
script, so the module graph fails and the app never mounts. In
production the bundle contains every Reanimated module twice. Metro,
including Expo web, keeps `react-native` first and is unaffected.
The check moves to `GestureDetector/refreshesAnimatableRef.ts`, imported
only by the native `Wrap.tsx`. `Wrap.web.tsx` already uses the plain
`Wrap`, so web bundles no longer reach the deep import. Native behaviour
is unchanged.
Fixes #4619.
## Test plan
- Standalone Vite 8 + react-native-web app with one `GestureDetector`,
RNGH 3.4.0: dev server fails with `validate-worklets-version.js does not
provide an export named 'default'`, production bundle 919 kB with 169
Reanimated modules bundled from both `lib/module` and `src/`.
- Same app with this branch built into `node_modules`: dev server
renders and the tap gesture works, production bundle 781 kB with 0
modules from `src/`.
- `yarn test src/__tests__/legacyWrapRef.test.tsx`, `yarn ts-check`,
`yarn lint:js` pass.1 parent 2202d7b commit a83496b
4 files changed
Lines changed: 30 additions & 29 deletions
File tree
- packages/react-native-gesture-handler/src
- __tests__
- handlers/gestures
- GestureDetector
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| 5 | + | |
5 | 6 | | |
6 | | - | |
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| |||
139 | 139 | | |
140 | 140 | | |
141 | 141 | | |
142 | | - | |
| 142 | + | |
143 | 143 | | |
144 | 144 | | |
145 | 145 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
11 | | - | |
12 | | - | |
13 | | - | |
14 | | - | |
| 11 | + | |
| 12 | + | |
15 | 13 | | |
16 | 14 | | |
17 | 15 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
132 | 132 | | |
133 | 133 | | |
134 | 134 | | |
135 | | - | |
136 | | - | |
137 | | - | |
138 | | - | |
139 | | - | |
140 | | - | |
141 | | - | |
142 | | - | |
143 | | - | |
144 | | - | |
145 | | - | |
146 | | - | |
147 | | - | |
148 | | - | |
149 | | - | |
150 | | - | |
151 | | - | |
152 | | - | |
153 | | - | |
154 | | - | |
155 | | - | |
156 | | - | |
157 | | - | |
158 | 135 | | |
0 commit comments