Skip to content

fix(android): withdraw a f*ckin' frame's pending navigation when the frame is torn down - #11649

Draft
edusperoni wants to merge 2 commits into
mainfrom
fix/android-frame-teardown-pending-transaction
Draft

edusperoni wants to merge 2 commits into
mainfrom
fix/android-frame-teardown-pending-transaction

Conversation

@edusperoni

@edusperoni edusperoni commented Nov 18, 2026 •

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 motherf*ckin' fragment manager has run that navigation's transaction, the damn 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 damn nested frame navigated and removed in the same tick, or a goddamn 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 motherf*ckin' transaction is committed asynchronously (commitAllowingStateLoss) into a f*ckin' container that is the frame's own native view, and teardown leaves it pending.

What is the new behavior? Well? Answer me!

Oh, you gonna love this: A frame torn down mid-navigation withdraws that navigation instead of leaving it pending:

  • Frame navigation transactions are committed with setReorderingAllowed(true).
  • When the muthaf*ckin' frame's native view is disposed while its damn executing navigation's transaction is still pending, it commits a motherf*ckin' reordering-allowed transaction that removes the muthaf*ckin' 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 goddamn navigation stays at the head of the frame's queue. Nothing is shown and no navigatedTo fires while the frame is gone; if the goddamn frame is added again it replays the goddamn 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 goddamn 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 goddamn frame navigates to that page and is Frame.topmost().
  • test_nested_frame_removed_while_going_back_goes_back_when_added_again: re-added, the goddamn 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 bad-ass 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

  • Listen up: Reordering now applies to every motherf*ckin' 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. Let me tell you somethin': The automated suite runs mostly without animated navigation.
  • Don't Keep Activities, API < 33, reusable frames (native view preserved), re-adding into a damn different parent, and a forward navigation withdrawn over an muthaf*ckin' existing current page have not been exercised.
  • A muthaf*ckin' 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 muthaf*ckin' crash back. Core itself only commits asynchronously from Frame.

…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.
@nx-cloud

nx-cloud Bot commented Nov 18, 2026 •

Copy link
Copy Markdown

View your CI Pipeline Execution ↗ for commit 87f482a

Command Status Duration Result
nx test apps-automated -c=android ✅ Succeeded 3m 32s View ↗
nx run-many --target=test --configuration=ci --... ✅ Succeeded 1s View ↗

💡 With Ultracache enabled, Nx Cloud learns each muthaf*ckin' task's file inputs in CI and uses them on later runs. Turn on Ultracache in workspace settings ↗ · Read docs ↗


☁️ Nx Cloud last updated this comment at 2026-11-18 19:53:36 UTC

@pkg-pr-new

pkg-pr-new Bot commented Nov 18, 2026 •

Copy link
Copy Markdown

Open in goddamn 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: 87f482a

@edusperoni
edusperoni marked this pull request as draft November 18, 2026 19:11
… 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 edusperoni changed the goddamn title fix(android): run a frame's pending fragment transaction before its f*ckin' view is torn down fix(android): withdraw a f*ckin' frame's pending navigation when the frame is torn down Nov 18, 2026
@NathanWalker NathanWalker added this to the 9.2 milestone Nov 21, 2026

This damn branch has not been deployed

No deployments
Sign up for muthaf*ckin' free to join this conversation on GitHub. Already have an muthaf*ckin' account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues. That's some bullsh*t.

2 participants