Skip to content

Discard stale navigation continuations after fragment view teardown - #226

Open
yshmarov wants to merge 1 commit into
hotwired:mainfrom
yshmarov:fix/stale-navigation-continuations
Open

yshmarov wants to merge 1 commit into
hotwired:mainfrom
yshmarov:fix/stale-navigation-continuations

Conversation

@yshmarov

@yshmarov yshmarov commented Nov 8, 2026

Copy link
Copy Markdown

Preparing a web destination can post a WebView-detachment callback that outlives the fragment view's lifecycle coroutine. If the host or originating view is removed or recreated before that callback runs, Navigator.reset() can resume against an obsolete graph and throw IllegalStateException: No configuration found for NavigatorHost.

Guard navigateWhenReady at the navigation continuation, checking the original host view, destination view lifecycle and current destination. Detachment and bridge cleanup still run before the guard. Calls made after host removal are ignored. This changes no public API and does not require a view to be STARTED, so live detached views can still complete navigation.

The standalone Robolectric fixture reproduces the failure by requesting a reset, removing the host before draining the main looper, then running the posted callback. It also covers activity destruction, view recreation, reentrant teardown, bridge cleanup, an already-removed host, and valid reset/route/detached-view completion. Six of its nine cases fail on the current base commit and all nine pass with the fix.

Validation on base 56e02c8d9488370ddfdaf325f777ecf89a2e5b8d plus this change:

  • ./gradlew :navigation-fragments:testDebugUnitTest --tests dev.hotwire.navigation.navigator.NavigatorPendingNavigationTest
  • ./gradlew testRelease core:lint :navigation-fragments:lint --continue — 321 release tests, no failures or skips; both lint checks pass.

The same pending-callback sequence is present in 1.3.1. A downstream workaround is carrying an equivalent source patch until a release includes the fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant