react / react/react-native

iOS Fabric: `display: none` silently destroys host-component, instead of just hiding or removing it

Offen
#56,656 0 Kommentare 1 Reaktion 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Vorherrschende Sprache
C++
Sterne
127k
Forks
25.3k
Ø Merge
1 T. 23 Std.
Gemergte PRs (30 T.)
4

Beschreibung

Description

Hi, Ioannis here from Margelo.

While migrating a client's app to the new architecture, we noticed that on iOS fabric, whenever a fabric component under Suspense get's suspended (thus display:none was set), our native view components were unmounted (removed and deleted - not just hidden but actually deallocated) and that resulted on their state being lost.

This seems to be a change in behavior to the old arch, where display: none would merely hide the view.

I did a poll among my RN colleagues, and no one expected that the view would be deleted on display: none especially given that you apply that style with the intention to bring the view back after a moment.

Furthermore, the behavior is what we'd expect on Android, where fabric choses to just hide the views (setVisibility(GONE)).

I was wondered if this was added intentionally back then? If so, I think i'd prefer to have a way to either opt-in/out of this behavior (see my PR).

Steps to reproduce

  1. Clone https://github.com/SudoPlz/reproducer-react-native
  2. cd ReproducerApp && yarn install && cd ios && pod install && cd ..
  3. yarn ios
  4. Tap "Set red" → red. Tap "Toggle display" off → gone. Tap "Toggle display" on → reappears WHITE (Command-set state lost).
  5. Notice dealloc being called

React Native Version

0.85.2

Affected Platforms

Runtime - iOS

Output of npx @react-native-community/cli info

System:
  OS: macOS 26.4.1
  CPU: (14) arm64 Apple M4 Pro
  Memory: 1.61 GB / 48.00 GB
  Shell:
    version: "5.9"
    path: /bin/zsh
Binaries:
  Node:
    version: 22.14.0
    path: /nix/store/04fc23dsflkxl4s9p6lkigia1hq3vjp2-nodejs-22.14.0/bin/node
  Yarn:
    version: 1.22.19
    path: /Users/sudoplz/.nix-profile/bin/yarn
  npm:
    version: 10.9.2
    path: /nix/store/04fc23dsflkxl4s9p6lkigia1hq3vjp2-nodejs-22.14.0/bin/npm
  Watchman:
    version: 2024.03.11.00
    path: /Users/sudoplz/.nix-profile/bin/watchman
Managers:
  CocoaPods:
    version: 1.15.2
    path: /Users/sudoplz/.nix-profile/bin/pod
SDKs:
  iOS SDK:
    Platforms:
      - DriverKit 25.2
      - iOS 26.2
      - macOS 26.2
      - tvOS 26.2
      - visionOS 26.2
      - watchOS 26.2
IDEs:
  Xcode:
    version: 26.2/17C52
    path: /usr/bin/xcodebuild
Languages:
  Java:
    version: 21.0.7
  Ruby:
    version: 3.4.4
    path: /Users/sudoplz/.rbenv/shims/ruby
npmPackages:
  "@react-native-community/cli":
    installed: 20.1.0
    wanted: 20.1.0
  react:
    installed: 19.2.3
    wanted: 19.2.3
  react-native:
    installed: 0.85.2
    wanted: 0.85.2
iOS:
  hermesEnabled: true
  newArchEnabled: true

Stacktrace or Logs

None — not a crash. The next render after display flips back simply shows a freshly-constructed host view with default state.

Reproducer

https://github.com/SudoPlz/reproducer-react-native

Screenshots and Videos

https://github.com/user-attachments/assets/bc7f1193-87ec-4c3b-b0d2-45947e32faa9

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Beginnen Sie mit packages/react-native/ReactCommon/react/renderer/mounting/Differentiator.cpp an den verlinkten Zeilen und führen Sie dann das Beispiel SudoPlz/reproducer-react-native auf iOS Fabric aus. Verfolgen Sie den display:none-Pfad und beobachten Sie dealloc und den Zustandsverlust, wenn display umgeschaltet wird. Als abgeschlossen gilt die Aufgabe, wenn das beabsichtigte iOS-Verhalten festgestellt ist und das Umschalten von display nicht mehr unerwartet den Zustand der Host-Ansicht verliert.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
ios, react-native
Bereich
mobile
Issue-Typ
Bug
Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Aktivitätsstatus
Ruhig
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
52/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.