Skip to content

Commit

Permalink
fix: Chrome debugger crash caused by incorrect viewTag (#6437)
Browse files Browse the repository at this point in the history
## Summary

The problem was reported in
[this](#6432)
issue and
[this](#6359)
discussion seems to report the same problem.

In short, the crash was caused by incorrect check in `_getViewInfo` in
`createAnimatedComponent` which assigned the `_component` to the
`viewTag` only for web but not for chrome debugger. I replaced `IS_WEB`
check with `shouldBeUseWeb`, which also checks whether the current
environment is a chrome debugger.

## Test plan

- I created a bare app with `npx @react-native-community/cli init
ReactNativeDebugger --version 0.75.1`
- Installed latest reanimated and downloaded
[react-native-debugger](https://github.com/jhen0409/react-native-debugger?tab=readme-ov-file)
mentioned in
[this](#6432)
issue
- Launched `react-native-debugger` and enabled remote debugging with js,
- When I tried to animate component with animated style, I saw the
reported crash
  • Loading branch information
MatiPl01 committed Aug 21, 2024
1 parent 00f074f commit ce3c1f9
Showing 1 changed file with 3 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ import type { ReanimatedHTMLElement } from '../js-reanimated';

const IS_WEB = isWeb();
const IS_JEST = isJest();
const SHOULD_BE_USE_WEB = shouldBeUseWeb();

if (IS_WEB) {
configureWebLayoutAnimations();
Expand Down Expand Up @@ -289,7 +290,7 @@ export function createAnimatedComponent(
? (this._component as AnimatedComponentRef).getAnimatableRef?.()
: this;

if (IS_WEB) {
if (SHOULD_BE_USE_WEB) {
// At this point I assume that `_setComponentRef` was already called and `_component` is set.
// `this._component` on web represents HTMLElement of our component, that's why we use casting
viewTag = this._component as HTMLElement;
Expand Down Expand Up @@ -501,7 +502,7 @@ export function createAnimatedComponent(
(layout || entering || exiting || sharedTransitionTag) &&
tag != null
) {
if (!shouldBeUseWeb()) {
if (!SHOULD_BE_USE_WEB) {
enableLayoutAnimations(true, false);
}

Expand Down

0 comments on commit ce3c1f9

Please sign in to comment.