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

[Android][NewArch] Weird layout styling if multiple instances of the same component with the same props #48249

Open
BogiKay opened this issue Dec 12, 2024 · 2 comments
Labels
Issue: Author Provided Repro This issue can be reproduced in Snack or an attached project. p: Callstack Partner: Callstack Partner Platform: Android Android applications. Type: New Architecture Issues and PRs related to new architecture (Fabric/Turbo Modules)

Comments

@BogiKay
Copy link
Contributor

BogiKay commented Dec 12, 2024

Description

I observed odd layout behaviour if I create two instances of the same component with the same props(or more likely if rendering outcome is the same). Basically, if on the screen there're two instances of the same component layout related styles of the second instance are overwritten by the first instance of the component. Hence, we can get two different results based on the order of components.

Issue seems to happen if rendering outcomes are the same. In my case the same margin(or padding) and Text's value. If value of text input is changed as in the recorded video, then layout is correct.

I already checked that the same issue happen for TextInput wrapped by View.

I'm trying to debug the problem, so any suggestions where should I start investigating are welcomed.

Steps to reproduce

  1. Install deps of the application with reproducible bug
  2. run the app on an android device or emulator
  3. Toggle the value by clicking the button
  4. Observe change of second component width despite the fact that only value is changed.

React Native Version

0.76.5

Affected Platforms

Runtime - Android

Areas

Fabric - The New Renderer

Output of npx react-native info

System:
  OS: macOS 14.6.1
  CPU: (10) arm64 Apple M1 Pro
  Memory: 82.25 MB / 16.00 GB
  Shell:
    version: "5.9"
    path: /bin/zsh
Binaries:
  Node:
    version: 18.20.2
    path: ~/.nvm/versions/node/v18.20.2/bin/node
  Yarn:
    version: 4.5.2
    path: ~/.nvm/versions/node/v18.20.2/bin/yarn
  npm:
    version: 10.5.0
    path: ~/.nvm/versions/node/v18.20.2/bin/npm
  Watchman:
    version: 2024.10.21.00
    path: /opt/homebrew/bin/watchman
Managers:
  CocoaPods:
    version: 1.15.2
    path: /Users/bogusz/.rbenv/shims/pod
SDKs:
  iOS SDK:
    Platforms:
      - DriverKit 23.5
      - iOS 17.5
      - macOS 14.5
      - tvOS 17.5
      - visionOS 1.2
      - watchOS 10.5
  Android SDK:
    API Levels:
      - "28"
      - "29"
      - "30"
      - "31"
      - "33"
      - "34"
      - "34"
      - "34"
      - "35"
    Build Tools:
      - 29.0.2
      - 29.0.3
      - 30.0.2
      - 30.0.3
      - 31.0.0
      - 33.0.0
      - 33.0.1
      - 34.0.0
      - 35.0.0
      - 35.0.0
    System Images:
      - android-29 | Google APIs ARM 64 v8a
      - android-31 | Google APIs ARM 64 v8a
      - android-33 | Google APIs ARM 64 v8a
      - android-33 | Google Play ARM 64 v8a
      - android-34 | Google Play ARM 64 v8a
      - android-UpsideDownCakePrivacySandbox | Google Play ARM 64 v8a
    Android NDK: Not Found
IDEs:
  Android Studio: 2024.2 AI-242.23339.11.2421.12700392
  Xcode:
    version: 15.4/15F31d
    path: /usr/bin/xcodebuild
Languages:
  Java:
    version: 17.0.12
    path: /usr/bin/javac
  Ruby:
    version: 2.7.5
    path: /Users/bogusz/.rbenv/shims/ruby
npmPackages:
  "@react-native-community/cli":
    installed: 15.0.1
    wanted: 15.0.1
  react:
    installed: 18.3.1
    wanted: 18.3.1
  react-native:
    installed: 0.76.5
    wanted: 0.76.5
  react-native-macos: Not Found
npmGlobalPackages:
  "*react-native*": Not Found
Android:
  hermesEnabled: true
  newArchEnabled: true
iOS:
  hermesEnabled: Not found
  newArchEnabled: false

Stacktrace or Logs

no logs

Reproducer

https://github.com/BogiKay/android-layout-bug

Screenshots and Videos

android-layout-issue.webm
@BogiKay BogiKay added Needs: Triage 🔍 Type: New Architecture Issues and PRs related to new architecture (Fabric/Turbo Modules) labels Dec 12, 2024
@react-native-bot react-native-bot added the Platform: Android Android applications. label Dec 12, 2024
@BogiKay
Copy link
Contributor Author

BogiKay commented Dec 12, 2024

Looks like caching text measures breaks layout. I forced comparison of text attributes to be always unequal in react/renderer/textlayoutmanager/TextMeasureCache and the issue was gone, so I assume that caching part needs to be adjusted

@cortinico cortinico added Issue: Author Provided Repro This issue can be reproduced in Snack or an attached project. Partner p: Callstack Partner: Callstack and removed Needs: Triage 🔍 labels Dec 13, 2024
@cipolleschi
Copy link
Contributor

@BogiKay thanks for the issue and for the initial investigation! @NickGerleman could you have a look at this? I believe that you have the most context on this part of the codebase.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Issue: Author Provided Repro This issue can be reproduced in Snack or an attached project. p: Callstack Partner: Callstack Partner Platform: Android Android applications. Type: New Architecture Issues and PRs related to new architecture (Fabric/Turbo Modules)
Projects
None yet
Development

No branches or pull requests

4 participants