fix: worklets bug#243
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
| clamp: NOOP, | ||
| }; | ||
|
|
||
| const interpolateColor = { |
Check notice
Code scanning / CodeQL
Unused variable, import, function or class Note documentation
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 9 months ago
The best way to resolve the issue is to simply remove the unused variable declaration for interpolateColor in this file. This means deleting lines 88–93, which declare and initialize interpolateColor. This avoids wasted memory and improves code readability by removing extraneous code elements. Only lines related to the declaration and assignment of interpolateColor need to be removed; no additional imports or function changes are required.
| @@ -85,12 +85,6 @@ | ||
| clamp: NOOP, | ||
| }; | ||
|
|
||
| const interpolateColor = { | ||
| Extrapolate: interpolation.Extrapolation, | ||
| Extrapolation: interpolation.Extrapolation, | ||
| ColorSpace: { RGB: 0, HSV: 1 }, | ||
| interpolateColor: NOOP, | ||
| }; | ||
|
|
||
| const Easing = { | ||
| Easing: { |
| interpolateColor: NOOP, | ||
| }; | ||
|
|
||
| const Easing = { |
Check notice
Code scanning / CodeQL
Unused variable, import, function or class Note documentation
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 9 months ago
To fix the problem, the unused variable Easing should simply be removed. This means deleting the declaration and initialization of Easing entirely (lines 95–115, inclusive). Since there is no evidence in the shown code that Easing is used, this can be done safely without affecting the rest of the file's functionality. No additional imports, methods, or variable definitions are required as part of the fix—just the removal of the block that defines Easing.
| @@ -92,28 +92,8 @@ | ||
| interpolateColor: NOOP, | ||
| }; | ||
|
|
||
| const Easing = { | ||
| Easing: { | ||
| linear: ID, | ||
| ease: ID, | ||
| quad: ID, | ||
| cubic: ID, | ||
| poly: ID, | ||
| sin: ID, | ||
| circle: ID, | ||
| exp: ID, | ||
| elastic: ID, | ||
| back: ID, | ||
| bounce: ID, | ||
| bezier: () => ({ factory: ID }), | ||
| bezierFn: ID, | ||
| steps: ID, | ||
| in: ID, | ||
| out: ID, | ||
| inOut: ID, | ||
| }, | ||
| }; | ||
|
|
||
|
|
||
| const platformFunctions = { | ||
| measure: () => ({ x: 0, y: 0, width: 0, height: 0, pageX: 0, pageY: 0 }), | ||
| scrollTo: NOOP, |
| }, | ||
| }; | ||
|
|
||
| const platformFunctions = { |
Check notice
Code scanning / CodeQL
Unused variable, import, function or class Note documentation
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 9 months ago
To fix the issue, we should remove the unused variable declaration for platformFunctions in apps/docs/src/lib/reanimated-mock.js. Delete lines 117-120, which declare and initialize the platformFunctions object. There is no indication it is used elsewhere in the file, and removing it should have no effect on functionality.
| @@ -114,11 +114,8 @@ | ||
| }, | ||
| }; | ||
|
|
||
| const platformFunctions = { | ||
| measure: () => ({ x: 0, y: 0, width: 0, height: 0, pageX: 0, pageY: 0 }), | ||
| scrollTo: NOOP, | ||
| }; | ||
|
|
||
|
|
||
| const Colors = { | ||
| processColor: (color) => color, | ||
| }; |
| scrollTo: NOOP, | ||
| }; | ||
|
|
||
| const Colors = { |
Check notice
Code scanning / CodeQL
Unused variable, import, function or class Note documentation
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 9 months ago
To fix this issue, the unused variable Colors should be removed from the code. Specifically, the entire definition starting from const Colors = { ... } on line 122 through line 124 should be deleted. No additional imports, methods, or variable definitions are required, and no other code depends on Colors as per the information given. This change should be limited strictly to the provided snippet and not alter existing functionality.
| @@ -119,10 +119,8 @@ | ||
| scrollTo: NOOP, | ||
| }; | ||
|
|
||
| const Colors = { | ||
| processColor: (color) => color, | ||
| }; | ||
|
|
||
|
|
||
| class BaseAnimationMock { | ||
| duration() { return this; } | ||
| delay() { return this; } |
|
|
||
| const LayoutAnimationConfig = ({ children }) => children; | ||
|
|
||
| const commonTypes = { |
Check notice
Code scanning / CodeQL
Unused variable, import, function or class Note documentation
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 9 months ago
To fix the unused variable error, we should remove the definition of commonTypes entirely from the file. The definition lies on lines 257 to 263 inclusive. Simply delete these lines. There is no need to replace uses, update imports, or preserve the object, since it is unused.
| @@ -254,14 +254,8 @@ | ||
|
|
||
| const LayoutAnimationConfig = ({ children }) => children; | ||
|
|
||
| const commonTypes = { | ||
| SensorType: { ACCELEROMETER: 1, GYROSCOPE: 2, GRAVITY: 3, MAGNETIC_FIELD: 4, ROTATION: 5 }, | ||
| IOSReferenceFrame: { XArbitraryZVertical: 0, XArbitraryCorrectedZVertical: 1, XMagneticNorthZVertical: 2, XTrueNorthZVertical: 3 }, | ||
| InterfaceOrientation: { ROTATION_0: 0, ROTATION_90: 90, ROTATION_180: 180, ROTATION_270: 270 }, | ||
| KeyboardState: { UNKNOWN: 0, OPENING: 1, OPEN: 2, CLOSING: 3, CLOSED: 4 }, | ||
| ReduceMotion: { System: 0, Always: 1, Never: 2 }, | ||
| }; | ||
|
|
||
|
|
||
| const jestUtils = { | ||
| withReanimatedTimer: (callback) => callback(), | ||
| advanceAnimationByTime: NOOP, |
| ReduceMotion: { System: 0, Always: 1, Never: 2 }, | ||
| }; | ||
|
|
||
| const jestUtils = { |
Check notice
Code scanning / CodeQL
Unused variable, import, function or class Note documentation
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 9 months ago
The best way to fix this problem is to remove the unused variable jestUtils, which consists of its declaration at line 265-271:
265: const jestUtils = {
266: withReanimatedTimer: (callback) => callback(),
267: advanceAnimationByTime: NOOP,
268: advanceAnimationByFrame: NOOP,
269: setUpTests: NOOP,
270: getAnimatedStyle: () => ({}),
271: };No other code depends on this variable within the given snippet. Therefore, delete lines 265-271. No imports, methods, or definitions are needed for the fix.
| @@ -262,14 +262,8 @@ | ||
| ReduceMotion: { System: 0, Always: 1, Never: 2 }, | ||
| }; | ||
|
|
||
| const jestUtils = { | ||
| withReanimatedTimer: (callback) => callback(), | ||
| advanceAnimationByTime: NOOP, | ||
| advanceAnimationByFrame: NOOP, | ||
| setUpTests: NOOP, | ||
| getAnimatedStyle: () => ({}), | ||
| }; | ||
|
|
||
|
|
||
| const Animated = { | ||
| View: ViewRN, | ||
| Text: TextRN, |
Summary
Problem: React Native Reanimated worklets were failing in the Next.js
browser environment because worklets require a special JavaScript
runtime that only exists in React Native, not in web browsers.
Solution: Created a custom Reanimated mock and configured webpack to use
it for web builds.
Changes Made
- Installed react-native-reanimated@~4.1.3 in the docs app
- Provides no-op implementations of all Reanimated hooks
(useAnimatedStyle, useDerivedValue, withTiming, etc.)
- Exports mock layout animations that won't throw errors
- Uses regular React Native Web components instead of animated ones
- Crucially: doesn't import from real Reanimated, preventing worklet
initialization
- Added alias: 'react-native-reanimated$': path.resolve(__dirname,
'./src/lib/reanimated-mock.js')
- Redirects all Reanimated imports to the custom mock on web
Result
errors