software-mansion / react-native-reanimated

React Native's Animated library reimplemented
https://docs.swmansion.com/react-native-reanimated/
MIT License
9.04k stars 1.3k forks source link

global.performance.now is not a function #2760

Closed michaelknoch closed 2 years ago

michaelknoch commented 2 years ago

Description

I run into the following type error when trying to attach a chrome debugger to the iOS simulator or physical device. global.performance.now is not a function

Screenshot 2021-12-17 at 12 48 34

Expected behavior

The type error should not appear and chrome debugging should be possible

Actual behavior & steps to reproduce

So far I was not able to reproduce it in a minimal code example (still working on it), but I can fix it in my app by commenting out every import of react-native-reanimated

Snack or minimal code example

tbd soon

Package versions

Affected platforms

github-actions[bot] commented 2 years ago

Issue validator

The issue is valid!

enesozturk commented 2 years ago

Same here with v2.3.1 in Expo app. Trying to use it with Storybook RN. I have a basic stack:

<Stack.Navigator>
  <Stack.Screen name="Home" component={TabNavigator} />
  <Stack.Screen name="Storybook" component={Story} />
</Stack.Navigator>

When I navigate to Storybook page, it is ok but when press go back. I got the issue.

Screen Shot 2021-12-17 at 21 18 50

Packages:

{
  "expo": "^44.0.0",
  "react-native-reanimated": "~2.3.1",
}

Should I share any other details?

Edit: Looks like it has nothing to do with react navigation. When I try to unmount Storybook, it throws this error.

arealmaas commented 2 years ago

Is this going to be released in a version soon?

boles-tradepending commented 2 years ago

I think this issue has regressed with this line change https://github.com/software-mansion/react-native-reanimated/commit/9c441ac8050e7d389563b6281a533666cf70cc02#diff-78a1300914cdf4318497f5e74a0a44c4f5174ef2567339edeb0d646c1ddbfaf0L379

kennethlynne commented 2 years ago

If you're on 2.3.1 just use https://www.npmjs.com/package/patch-package

patches/react-native-reanimated+2.3.1.patch

diff --git a/node_modules/react-native-reanimated/src/reanimated2/core.ts b/node_modules/react-native-reanimated/src/reanimated2/core.ts
index 2e0c38a..e9ae28f 100644
--- a/node_modules/react-native-reanimated/src/reanimated2/core.ts
+++ b/node_modules/react-native-reanimated/src/reanimated2/core.ts
@@ -383,9 +383,11 @@ if (!NativeReanimatedModule.useOnlyV1) {
         info: runOnJS(capturableConsole.info),
       };
       _setGlobalConsole(console);
-      global.performance = {
-        now: global._chronoNow,
-      };
+      if (global.performance == null) {
+        global.performance = {
+          now: global._chronoNow,
+        };
+      }
     })();
   }
 }
boles-tradepending commented 2 years ago

@kennethlynne, I tested against the latest commit on the main branch and had to make this change to fix the issue for me using React Native Debugger. The changes above are already in the main branch. I think the !isChromeDebugger check was removed in the commit referenced above.

diff --git a/src/reanimated2/core.ts b/src/reanimated2/core.ts
index e9ae28f17..3b42f1094 100644
--- a/src/reanimated2/core.ts
+++ b/src/reanimated2/core.ts
@@ -1,7 +1,7 @@
 /* global _WORKLET _getCurrentTime _frameTimestamp _eventTimestamp, _setGlobalConsole */
 import NativeReanimatedModule from './NativeReanimated';
 import { Platform } from 'react-native';
-import { nativeShouldBeMock, shouldBeUseWeb, isWeb } from './PlatformChecker';
+import { nativeShouldBeMock, shouldBeUseWeb, isChromeDebugger, isWeb } from './PlatformChecker';
 import {
   BasicWorkletFunction,
   WorkletFunction,
@@ -371,7 +371,7 @@ if (!NativeReanimatedModule.useOnlyV1) {
       : (workletValueSetterJS as <T>(value: T) => void)
   );

-  if (!isWeb() && isConfigured()) {
+  if (!isWeb() && !isChromeDebugger() && isConfigured()) {
     const capturableConsole = console;
     runOnUI(() => {
       'worklet';
JacopoKenzo commented 2 years ago

@kennethlynne's patch worked for me! Thanks

Biplovkumar commented 2 years ago

@kennethlynne's patch worked for me! Thanks

temporary solution.

it is also coming in "react-native-reanimated": "^2.3.1",.

fkazemi5236 commented 2 years ago

I solved this problem with this solution: Add Reanimated's babel plugin to your babel.config.js:

module.exports = { ... plugins: [ ... 'react-native-reanimated/plugin', ], };

react-native-reanimated/babel-config