Repository navigation
fix(android): withdraw a frame's pending navigation when the frame is torn down - #11649
Draft
edusperoni wants to merge 3 commits into
main from
fix/android-frame-teardown-pending-transaction
Draft
Conversation
Copy link
Copy Markdown
Contributor
PR Checklist
Draft: needs more testing before review (see "Not covered yet").
What is the current behavior?
On Android, when a Frame is removed from the view tree after it has started a navigation (forward or back) but before the fragment manager has run that navigation's transaction, the app crashes on the next fragment manager pass:
java.lang.IllegalArgumentException: No view found for id 0x2 (unknown) for fragment fragment26[1]<Page(65)>
at androidx.fragment.app.FragmentStateManager.createView(FragmentStateManager.java:567)
at androidx.fragment.app.FragmentManager.execPendingActions(FragmentManager.java:2052)
For example, a nested frame navigated and removed in the same tick, or a modal holding a frame that is closed as soon as it is shown (common with Angular, where closing the dialog destroys the component and removes the frame). The transaction is committed asynchronously (commitAllowingStateLoss) into a container that is the frame's own native view, and teardown leaves it pending.
What is the new behavior?
A frame torn down mid-navigation withdraws that navigation instead of leaving it pending:
- Frame navigation transactions are committed with
setReorderingAllowed(true).
- When the frame's native view is disposed while its executing navigation's transaction is still pending, it commits a reordering-allowed transaction that removes the new fragment and adds the current page's fragment back (the pending replace would otherwise remove it). AndroidX (1.8.5:
removeRedundantOperationsAndExecute / executeOpsTogether) runs both records in one batch, so the new fragment is cleaned up as "never attached": it is never created, its container is never looked up, and the current fragment stays where it was.
- The navigation stays at the head of the frame's queue. Nothing is shown and no
navigatedTo fires while the frame is gone; if the frame is added again it replays the navigation with its events and re-enters the frame stack.
- When the frame's activity is being destroyed, the existing
_tearDownPending handling is unchanged.
What is tested
New FRAME tests (Android), each asserting first that the navigation's transaction is still pending; all four crash on main:
test_nested_frame_removed_before_its_first_page_is_shown: the page is never created or loaded and no navigatedTo fires.
test_nested_frame_removed_before_its_first_page_is_shown_navigates_when_added_again: re-added, the frame navigates to that page and is Frame.topmost().
test_nested_frame_removed_while_going_back_goes_back_when_added_again: re-added, the frame ends on its first page with an empty queue.
test_frame_in_modal_removed_before_its_first_page_is_shown: a modal closed in shownModally with its frame removed.
Full automated suite on an Android 15 (API 35) emulator: 1700 OK, 0 failed, including TRANSITIONS and the *_WithTransition navigation tests.
Not covered yet
- Reordering now applies to every frame navigation transaction. Records of different frames that land in the same fragment manager pass are executed together, which AndroidX documents can reorder lifecycle callbacks within that batch. The automated suite runs mostly without animated navigation.
- Don't Keep Activities, API < 33, reusable frames (native view preserved), re-adding into a different parent, and a forward navigation withdrawn over an existing current page have not been exercised.
- A non-reordering asynchronous transaction committed by other code on the same manager between the navigation and its withdrawal would split the batch and bring the crash back. Core itself only commits asynchronously from
Frame.
fix(android): run a frame's pending fragment transaction before its v...
f63764b
...iew is torn down
A frame commits its navigation's fragment transaction asynchronously into a
container that is the frame's own native view. When the frame is removed from
the view tree after it starts navigating but before the fragment manager runs
that transaction, _tearDownUI detaches the native view and nothing runs or
cancels the transaction, so the next fragment manager pass crashes with
"IllegalArgumentException: No view found for id 0x.. for fragment ...".
Before the native view is detached, run the pending transaction through the
fragment manager that holds the fragment (getParentFragmentManager()).
_getFragmentManager() is not usable at that point: unloading clears its cached
manager and, once a modal's dialog fragment is cleared, it resolves to the
activity's manager. A destroyed manager is skipped, as its transactions never
run.
Copy link
Copy Markdown
Copy link
Copy Markdown
|
Open in StackBlitz
npm i https://pkg.pr.new/@nativescript/core@11649
npm i https://pkg.pr.new/@nativescript/vite@11649
npm i https://pkg.pr.new/@nativescript/webpack@11649
commit: c7d1d38
|
edusperoni
marked this pull request as draft
November 18, 2026 19:11
fix(android): withdraw a frame's pending navigation when the frame is...
87f482a
... torn down
Instead of running a frame's pending fragment transaction early during teardown, withdraw it.
Frame navigation transactions now allow reordering. When a frame's native view is disposed while
the transaction of its executing navigation is still pending, the frame commits a
reordering-allowed transaction that removes the new fragment and adds the current one back. Both
transactions execute in the same batch, so the new fragment is never attached, its container is
never looked up, and the current fragment stays in its fragment manager. The navigation stays at
the head of the frame's queue and runs again, raising its events, if the frame is shown again; a
frame shown again with a queued navigation re-enters the frame stack, as navigate() put it there.
When the frame's activity is destroyed, the existing _tearDownPending handling is kept.
edusperoni
changed the title
fix(android): run a frame's pending fragment transaction before its view is torn down
fix(android): withdraw a frame's pending navigation when the frame is torn down
Nov 18, 2026
NathanWalker
added this to the
9.2 milestone
Nov 21, 2026
anjak03
mentioned this pull request
Nov 25, 2026
[Android] Nested Frame commits into the Activity's FragmentManager when its parent Frame's fragment is not added yet ("No view found for id")
#11676
Open
3 tasks done
NathanWalker
mentioned this pull request
Nov 25, 2026
fix(android): nested frame waits for its parent frame's fragment
#11677
Open
5 tasks done
Merge branch 'main' into fix/android-frame-teardown-pending-transaction
c7d1d38
This branch has not been deployed
No deployments
Sign up for free
to join this conversation on GitHub .
Already have an account?
Sign in to comment
Labels
None yet
2 participants