Repository navigation
fix(android): nested frame waits for its parent frame's fragment - #11677
Open
anjak03 wants to merge 4 commits into
NativeScript:main from
anjak03:fix/nested-frame-fragment-manager
Open
Conversation
Copy link
Copy Markdown
Contributor
PR Checklist
What is the current behavior?
When a page with nested frames loads again, for example after going back in the root frame to a page with a TabView whose tabs contain frames, the whole subtree loads in one go. The tab Frame posts its first fragment transaction, so its fragment is not added yet when the nested Frame loads right after it and runs _processNextNavigationEntry(). View._getFragmentManager() gets null from the tab Frame's _getChildFragmentManager(), falls back to the Activity's FragmentManager and caches it. The nested Frame commits its page fragment there, and when the transaction runs before the nested container is attached, the app crashes with IllegalArgumentException: No view found for id. If the container happens to be attached, the fragment lands in the Activity's FragmentManager and the tab stays empty.
What is the new behavior?
Frame._getFragmentManager() returns null without caching it while the nearest fragment host above the frame is a Frame whose fragment is not added yet, and _processNextNavigationEntry() returns early in that case. _onAttachedToWindow() already calls _processNextNavigationEntry(), so the nested frame navigates as soon as it is attached, into its parent's child FragmentManager. Frames inside a modal dialog or directly inside a TabViewItem keep their current lookup.
Verified with the same logic applied as a runtime patch in a production Angular app on an Android 16 emulator: 15 back navigations to the tabs page went from 19 nested commits into the Activity's FragmentManager and a crash to none, and 141 random adb shell monkey runs of 400 events had no crash (2 to 3 per 100 before).
Fixes #11676 .
fix(android): nested frame waits for its parent frame's fragment
255d787
NathanWalker
requested changes
Nov 25, 2026
View reviewed changes
Copy link
Copy Markdown
Contributor
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more .
Thanks, the diagnosis is right and the approach works for the scenario in #11676 . I traced the retry and it holds:
- On Android, Frame never adds its page's native view to its own native view. The page view only reaches the window through the fragment's
onCreateView, by which point the parent fragment is already added, so the synchronous attach from addView reaches the nested frame and _onAttachedToWindow finds the child FragmentManager.
- An early attach through a stale parent link is undone by the
removeAllViews workaround in onCreateView and re-attached, which fires a second attach.
- Frames three deep wait in a chain and resolve correctly.
navigate(), resetRootView and activity recreation while waiting all return early and resume on attach.
Other callers are fine with the null:
_navigateCore/_goBackCore sit behind the guard.
onBackPressed already null-checks, so the back press falls through to the parent.
- Root, modal and in-modal frames don't wait.
No conflicts with #11649 or #11352 . #11649 is complementary: it clears a stuck _executingContext on a torn-down parent, which would otherwise leave a frame waiting forever.
Verified: core vitest 680 passed / 1 skipped, tsc and prettier clean.
Requesting changes for two things:
- The same bug remains when a TabView sits inside a nested frame (inline at the walk). I'd like this case handled, either in
View._getFragmentManager (the fix #11676 itself proposed) or at least by walking past a TabViewItem to its TabView's host.
- A regression test.
apps/automated/src/ui/tab-view/tab-view-navigation-tests.ts testBackNavigationToTabViewWithNestedFramesShouldWork already does the right navigation. Extend it with a Frame inside the tab frame's page, go back, and assert that the nested frame's currentPage is set, that nested._getFragmentManager() equals tabFrame._getChildFragmentManager(), and that navigationQueueIsEmpty(). Add a second case for point 1. A Node spec can't cover much here, because vitest resolves ../core/view to the iOS/common implementation.
Nits are inline, plus one outside the diff: AndroidFrame.fragmentForPage (public, in index.d.ts) calls this.owner._getFragmentManager().findFragmentByTag(tag) without a null check. On a waiting frame it now throws a TypeError where it returned null before. Nothing in core calls it, but ?. would remove the risk.
fix(android): nested fragment hosts wait for their parent's fragment
06f7b08
Copy link
Copy Markdown
Copy link
Copy Markdown
|
Open in StackBlitz
npm i https://pkg.pr.new/@nativescript/core@11677
npm i https://pkg.pr.new/@nativescript/vite@11677
npm i https://pkg.pr.new/@nativescript/webpack@11677
commit: ea7ae98
|
NathanWalker
added 2 commits
November 27, 2026 16:41
Merge branch 'main' into fix/nested-frame-fragment-manager
604b551
Merge branch 'main' into fix/nested-frame-fragment-manager
ea7ae98
# Conflicts:
# packages/core/ui/core/view/index.android.ts
anjak03
requested a review
from
NathanWalker
November 29, 2026 12:45
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