NavigationStack: pushed view renders blank when syncState's delayed effect runs after a push
Maintainers usually reply within 4 days
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- Half a day
- Newbie friendliness
- 55/100
Research direction
Start in Navigator.syncState() in Sources/SkipUI/SkipUI/Containers/Navigation.swift, where the delayed LaunchedEffect builds backStackState from stackKeys captured when the effect started. Reproduce a push shortly after a heavy first composition on Android, then check whether the proposed change (iterating navBackStack.toList() when the delay ends) keeps the pushed entry's state. Done when a pushed view renders reliably after cold start and Back pops normally.
Written by the indexing model from the issue text.
Description
Summary
A view pushed onto a NavigationStack can render blank (no content, no top bar) when the push happens while the main thread is busy shortly after the stack was first composed. The entry stays on the back stack; pressing Back re-presents the destination.
Cause
Navigator.syncState() (Sources/SkipUI/SkipUI/Containers/Navigation.swift, unchanged on main and in 1.63.0) prunes backStackState in a delayed effect:
let stackKeys = navBackStack.toList()
...
LaunchedEffect(stackEffectKey) {
delay(1000) // 1 second
var syncedBackStackState: [String: BackStackState] = [:]
for key in stackKeys { // <- keys captured when the effect STARTED
...
}
backStackState = syncedBackStackState
}
If the main thread is blocked (e.g. a heavy first composition of the root view, or a cold JIT right after app start), the effect for the old stack state ([root]) can resume after a new entry has been pushed but before recomposition cancels it (its key changed). It then rebuilds backStackState from the stale keys and drops the state of the entry that was just pushed. entry<SkipNavigationStackPushKey> finds no state and returns without rendering anything:
guard let state = navigator.value.state(forPushKey: navKey), let targetValue = state.targetValue else {
return
}
Evidence
Logging added to both places (Android emulator, API 36, SkipUI 1.62.0, Skip Fuse app with a ~600-row list as the stack root, tap ~2 s after first showing the tab, ~12 s after cold start):
W BUG008: syncState drops 1, effect stack: navigationroot, now: [navigationroot, 99/0]
W BUG008: entry without state: skip.ui.SkipNavigationStackPushKey@7e4
8 of 8 cold starts reproduced it. It happens for both navigationDestination(isPresented:) and navigationDestination(item:), with NavigationLink as well, and also with navigationStackTransitions set to .none. Lighter stacks (where the root composes quickly) were not affected. Slower devices widen the window.
Proposed fix
Sync against the current back stack when the delayed effect runs:
- for key in stackKeys {
+ for key in navBackStack.toList() {
With this change: 0 of 8 cold starts blank (previously 8 of 8), Back pops normally. We ship it from a fork for now: https://github.com/woxmaster-cell/skip-ui/commit/065ab28c05e67d2df305486309c096d8fd2ae018
The delay's purpose ("allow views that receive compose calls while animating away to find their state") is preserved: entries popped in the meantime are still pruned, only entries that are on the stack right now are kept.
- Dominant language
- Swift
- Stars
- 334
- Forks
- 95
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 8
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from skiptools/skip-ui
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Maintainers usually reply within 4 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 80/100
Maintainers usually reply within 4 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
Maintainers usually reply within 4 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
Maintainers usually reply within 4 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
Maintainers usually reply within 4 days
All issues in skiptools/skip-ui
Similar issues
-
AndroidAssetManager(env:peer:) in AssetURLProtocol.swift doesn't compile for Android on the Swift nightlyPossibly taken A pull request linked to this issue is open or already merged. Open
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
good first issue help wanted
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
erkamyaman/unslop-anything#579 ·
Maintainers usually reply within 1 day
-
good first issue help wanted
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
erkamyaman/rust-anything#1311 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day
-
bug priority:low status:queued
Difficulty 2/5 1-3 hours Newbie friendliness 83/100
Maintainers usually reply within 1 day