fix(android): nested frame waits for its parent frame's fragment by anjak03 · Pull Request #11677 · NativeScript/NativeScript
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
fix(android): nested frame waits for its parent frame's fragment #11677 anjak03 wants to merge 4 commits into NativeScript:main from anjak03:fix/nested-frame-fragment-manager
Conversation
anjak03 commented Nov 25, 2026 · edited Loading
Copy link Copy Markdown
Contributor
PR Checklist
- The PR title follows our guidelines: https://github.com/NativeScript/NativeScript/blob/main/tools/notes/CONTRIBUTING.md#commit-messages .
- There is an issue for the bug/feature this PR is for. To avoid wasting your time, it's best to open a suggestion issue first and wait for approval before working on it.
- You have read and signed the CLA .
- All existing tests are passing: https://github.com/NativeScript/NativeScript/blob/main/tools/notes/DevelopmentWorkflow.md#unit-testing .
- Tests for the changes are included - https://github.com/NativeScript/NativeScript/blob/main/tools/notes/WritingUnitTests.md .
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
NathanWalker left a comment
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 fromaddViewreaches the nested frame and_onAttachedToWindowfinds the child FragmentManager. - An early attach through a stale parent link is undone by the
removeAllViewsworkaround inonCreateViewand re-attached, which fires a second attach. - Frames three deep wait in a chain and resolve correctly.
navigate(),resetRootViewand activity recreation while waiting all return early and resume on attach.
Other callers are fine with the null:
_navigateCore/_goBackCoresit behind the guard.onBackPressedalready 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 aTabViewItemto its TabView's host. - A regression test.
apps/automated/src/ui/tab-view/tab-view-navigation-tests.tstestBackNavigationToTabViewWithNestedFramesShouldWorkalready does the right navigation. Extend it with a Frame inside the tab frame's page, go back, and assert that the nested frame'scurrentPageis set, thatnested._getFragmentManager()equalstabFrame._getChildFragmentManager(), and thatnavigationQueueIsEmpty(). Add a second case for point 1. A Node spec can't cover much here, because vitest resolves../core/viewto 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
nx-cloud
Bot
commented
Nov 26, 2026
·
edited
Loading
Copy link Copy Markdown
|
View your CI Pipeline Execution ↗ for commit ea7ae98
💡 With Ultracache enabled, Nx Cloud learns each 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 |
pkg-pr-new
Bot
commented
Nov 26, 2026
·
edited
Loading
Copy link Copy Markdown
commit: |
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.tsanjak03 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