Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix console error #4252

Merged
merged 4 commits into from
Mar 30, 2023
Merged

Fix console error #4252

merged 4 commits into from
Mar 30, 2023

Conversation

Latropos
Copy link
Contributor

Summary

Fix this issue: #4225

Looks like we have been overwriting console and making its properties not configurable. This PR should fix the problem.

Test plan

Tested on example app

@Latropos Latropos changed the title Fix smooth scroll android Fix console error Mar 21, 2023
@Latropos Latropos marked this pull request as ready for review March 21, 2023 10:44
Comment on lines 177 to 183
Object.defineProperties(global.console, {
debug: { ...props, value: runOnJS(capturableConsole.debug) },
log: { ...props, value: capturableConsole.log },
warn: { ...props, value: capturableConsole.warn },
error: { ...props, value: capturableConsole.error },
info: { ...props, value: capturableConsole.info },
});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need this change? I thought it worked without those.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need it, but it lets us get rid of @ts-ignore

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not familiar with react-native-reanimated code, but what is the purpose of this Object.defineProperties(...) statement and why only debug is wrapped in runOnJS and the other ones not?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean someone in that issue mentioned that they commented out the global.console assignment. Should they expect that something will not work without it? I just downgraded back to v2 instead for now until this is fixed.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need it, but it lets us get rid of @ts-ignore

I think the problem with TypeScript is rather related to the fact that we don't implement all console.* methods but only a subset of them.

why only debug is wrapped in runOnJS and the other ones not?

+1 to this question

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it really expected to remove all : runOnJS except on debug ?

Copy link
Member

@piaskowyk piaskowyk Mar 22, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the current implementation all console.* methods are wrapped by runOnJS, I don't think we want to remove it now.
https://github.com/software-mansion/react-native-reanimated/blob/main/src/reanimated2/initializers.ts#L172-L176

debug: runOnJS(capturableConsole.debug),
log: runOnJS(capturableConsole.log),
warn: runOnJS(capturableConsole.warn),
error: runOnJS(capturableConsole.error),
info: runOnJS(capturableConsole.info),

Copy link
Contributor Author

@Latropos Latropos Mar 23, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, we don't want to remove any runOnJS, it was a typo 😅

@freeboub
Copy link

freeboub commented Mar 21, 2023

Tested locally on my side, I confirm it fixes the crash in debug mode, but I have following crash in release mode:

03-21 19:54:18.192 10816 10816 I HermesVM: JSI rethrowing JS exception: Object.defineProperties() called on non-object
03-21 19:54:18.192 10816 10816 I HermesVM: 
03-21 19:54:18.192 10816 10816 I HermesVM: TypeError: Object.defineProperties() called on non-object
03-21 19:54:18.192 10816 10816 I HermesVM:     at defineProperties (native)
03-21 19:54:18.192 10816 10816 I HermesVM:     at anonymous (JavaScript:1:357)
03-21 19:54:18.192 10816 10816 I HermesVM:     at apply (native)
03-21 19:54:18.192 10816 10816 I HermesVM:     at anonymous (JavaScript:1:64)
03-21 19:54:18.196 10816 10816 D AndroidRuntime: Shutting down VM
03-21 19:54:18.198 10816 10816 E AndroidRuntime: FATAL EXCEPTION: main
03-21 19:54:18.198 10816 10816 E AndroidRuntime: Process: com.test.project, PID: 10816
03-21 19:54:18.198 10816 10816 E AndroidRuntime: com.facebook.jni.CppException: Object.defineProperties() called on non-object
03-21 19:54:18.198 10816 10816 E AndroidRuntime: 
03-21 19:54:18.198 10816 10816 E AndroidRuntime: TypeError: Object.defineProperties() called on non-object
03-21 19:54:18.198 10816 10816 E AndroidRuntime:     at defineProperties (native)
03-21 19:54:18.198 10816 10816 E AndroidRuntime:     at anonymous (JavaScript:1:357)
03-21 19:54:18.198 10816 10816 E AndroidRuntime:     at apply (native)
03-21 19:54:18.198 10816 10816 E AndroidRuntime:     at anonymous (JavaScript:1:64)
03-21 19:54:18.198 10816 10816 E AndroidRuntime: 	at com.swmansion.reanimated.Scheduler.triggerUI(Native Method)
03-21 19:54:18.198 10816 10816 E AndroidRuntime: 	at com.swmansion.reanimated.Scheduler$1.run(Scheduler.java:24)
03-21 19:54:18.198 10816 10816 E AndroidRuntime: 	at com.swmansion.reanimated.Scheduler$2.runGuarded(Scheduler.java:43)
03-21 19:54:18.198 10816 10816 E AndroidRuntime: 	at com.facebook.react.bridge.GuardedRunnable.run(GuardedRunnable.java:30)
03-21 19:54:18.198 10816 10816 E AndroidRuntime: 	at android.os.Handler.handleCallback(Handler.java:789)
03-21 19:54:18.198 10816 10816 E AndroidRuntime: 	at android.os.Handler.dispatchMessage(Handler.java:98)
03-21 19:54:18.198 10816 10816 E AndroidRuntime: 	at android.os.Looper.loop(Looper.java:164)
03-21 19:54:18.198 10816 10816 E AndroidRuntime: 	at android.app.ActivityThread.main(ActivityThread.java:6541)
03-21 19:54:18.198 10816 10816 E AndroidRuntime: 	at java.lang.reflect.Method.invoke(Native Method)
03-21 19:54:18.198 10816 10816 E AndroidRuntime: 	at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
03-21 19:54:18.198 10816 10816 E AndroidRuntime: 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
03-21 19:54:18.238  4705  8053 W ActivityManager:   Force finishing activity 

@piaskowyk
Copy link
Member

@Latropos could you test it in release build also?

@Latropos
Copy link
Contributor Author

@freeboub The crash on release was because of the refactor - we can't call defineProperties on console on release build, since console in not an object on release. Hope it's fixed

TypeError: Object.defineProperties() called on non-object

@Latropos Latropos requested a review from piaskowyk March 23, 2023 10:05
@mlazari
Copy link

mlazari commented Mar 23, 2023

I can confirm that the "property is not configurable" error does not occur with the latest change in this PR and the release build does not crash in my repro project: https://github.com/mlazari/ReanimatedRepro/tree/fix-pr

@mlazari
Copy link

mlazari commented Mar 23, 2023

It looks like the global.console assignment affects console.trace(): https://github.com/mlazari/ReanimatedRepro/blob/console-trace/App.tsx#L63

If I comment out the global.console assignment:
Screenshot 2023-03-23 at 12 53 04

With the global.console assignment:
Screenshot 2023-03-23 at 12 52 36

@piaskowyk
Copy link
Member

@mlazari I wasn't able to reproduce this problem with console.trace(). Moreover, we modify just global.console on Reanimated JS Runtime, we don't change the console object form React Runtime.

@chakravarthi-bb
Copy link

Can we make a release for this patch, please??

@tiagomsmagalhaes
Copy link

@chakravarthi-bb you can append .patch to this url to generate a patch file. just need afterwards to change the path on the diff to the node_modules directory of the package

@altarrok
Copy link

altarrok commented Jun 1, 2023

+1 on making a release for this patch

@mlazari
Copy link

mlazari commented Jun 1, 2023

@altarrok It was already released in 3.1.0 (latest is 3.2.0 now).

fluiddot pushed a commit to wordpress-mobile/react-native-reanimated that referenced this pull request Jun 5, 2023
<!-- Thanks for submitting a pull request! We appreciate you spending
the time to work on these changes. Please follow the template so that
the reviewers can easily understand what the code changes affect. -->

## Summary

Fix this issue:
software-mansion#4225

Looks like we have been overwriting console and making its properties
not configurable. This PR should fix the problem.

## Test plan
Tested on example app

---------

Co-authored-by: Aleksandra Cynk <aleksandracynk@aleksandras-mbp.home>
Co-authored-by: Aleksandra Cynk <aleksandracynk@swmansion.com>
Co-authored-by: Krzysztof Piaskowy <krzysztof.piaskowy@swmansion.com>
@monicatiba
Copy link

monicatiba commented Jul 3, 2023

Do we have a fix for this? I'm facing the same error even with the last version of the lib and I cannot find a way to fix it. I tried everything. Running on IOS and MacOs

Error log: in js engine: hermes

Simulator Screenshot - iPhone 14 - 2023-07-03 at 09 32 44

@mlazari
Copy link

mlazari commented Jul 3, 2023

@monicatiba Are you sure that is related to react-native-reanimated? The stack trace looks different from the one in #4225 and as far as I can tell that is fixed in the latest version.

@ZakaryH
Copy link

ZakaryH commented Nov 2, 2023

@monicatiba I had this same error and stack trace. for me the problem was that I was applying a useAnimatedStyle style to a View rather than an Animated.View.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

"Property not configureable" error on Development when upgrading to V3
10 participants