You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix(iOS, Modal): Filter-out obsolete state updates from JS (#3760)
## Description
This PR introduces logic to collect only active (non-dismissed) modal
controllers coming from JS state.
When a Modal is dismissed on the native side, its state is sent
asynchronously to JavaScript. This can result in some race conditions
and stale updates being sent from JS to native. These outdated updates
may reference modals that were detached from the native view hierarchy.
Since view recycling is disabled, we don't expect dismissed modals to be
reattached; a new instance should be created when we push an updated
state from JS. Then the new controller instance will be initialized, so
these associated with detached screens won't be reused again. Therefore,
we can safely filter them out from the JS state on the native side. On
the JS side, the state will stabilize at some point and align with
native, once we receive all asynchronous events.
This fix is brought with an experimental feature flag
`iosPreventReattachmentOfDismissedModals` - similar to what we did for
`iosPreventReattachmentOfDismissedScreens`. You can opt out in case of
any potential regressions. I'm not using the already existing flag
deliberately. Extending its responsibility seems to be too much and may
unnecessarily force disabling other fixes, when the regression will be
touching only the modal hierarchy.
Closes:
software-mansion/react-native-screens-labs#1017
## Changes
- Added logic to mark detached modals.
- Added logic for filtering out screens dismissed natively from JS
state.
## Before & after - visual documentation
| Before | After |
| --- | --- |
| <video
src="https://github.com/user-attachments/assets/e8156173-c6d7-4d82-ab78-882e7dba77f8"
/> | <video
src="https://github.com/user-attachments/assets/c2d22d7e-0ecb-4bdf-ae59-6d7fa2370a54"
/> |
## Test plan
Added Test3760, verified the Modals test.
## Checklist
- [x] Included code example that can be used to test this change.
- [ ] Updated / created local changelog entries in relevant test files.
- [x] For visual changes, included screenshots / GIFs / recordings
documenting the change.
- [x] For API changes, updated relevant public types.
- [ ] Ensured that CI passes
0 commit comments