Skip to content

fix(solid): keep Frame, modals and Android back in sync with router history (0.2.2) - #6

Merged
NathanWalker merged 2 commits into
mainfrom
fix/solid-navigation-modal-sync
Nov 24, 2026
Merged

NathanWalker merged 2 commits into
mainfrom
fix/solid-navigation-modal-sync

Conversation

@NathanWalker

Copy link
Copy Markdown
Contributor

Summary

Fixes flaky navigation in the Solid flavor after the Solid 2 / Vite upgrade: links that only navigate on the first tap, and Android hardware Back being swallowed after closing a ?@modal= route. Also bumps to 0.2.2.

Root causes (each reproduced on an Android API 36 emulator)

  1. Dropped router updates. syncFrameToRouterState returned early while the navigation guard was held, and nothing re-ran it. After a modal closed, prevModalPath stayed stale, so tapping the same Author link again did nothing (curIndex: 3 prevIndex: 3, no modal). Navigations landing during a router back were lost the same way.
  2. Duplicate history entry after closing a modal. Opening a modal pushes /posts?@modal=…. Closing it replaced that entry with /posts, leaving two /posts entries. The first hardware Back moved between them and nothing changed on screen. (Back feat: tanstack router updates #1 does reach the router's back handler; the history index goes 2 → 1 on the same path.)
  3. Deep-linked modal opened twice on Android. /posts?@modal=/users/3 from / was opened by both the deferred post-navigate timer and the next sync. Android's attemptShowModal never rechecked the request id, so two dialogs stacked, and Back left one orphaned over Home.
  4. replace kept the wrong page. It passed backstackVisible: false for the new page. Core decides backstack membership from the outgoing entry, so the replaced page stayed reachable by Back.
  5. Taps undone mid-transition. reconcileRouterToVisiblePath ran on every navigatedTo, so a page that finished animating in after the router had moved on forced the router back to it.

Changes

  • Syncs are coalesced (scheduleSync) and re-run when the guard releases, so no router change is dropped. Mismatch retries no longer rely on a signal write that Solid dedupes, and they're bounded.
  • The modal reconciler opens only when the route's page is the visible one. Closing bumps the request id, cancelling pending opens, and the close callback only syncs the router for natively dismissed modals (modalLifecycleLock is gone).
  • Native modal close pops the modal's history entry when the entry below is the same page without a modal; otherwise it removes @modal in place.
  • The Android back handler leaves Back to the dialog while a modal is presented.
  • replace flags the outgoing navigation entry. Router back uses frame.goBack(entry) for the nearest backstack page with the target path, and replaces in place when there is none.
  • Router-to-visible-page reconciliation is limited to native pops the router didn't start.
  • The navigation key includes the history entry key.

The React provider has no modal machinery and isn't changed here. It does have the same dropped-sync and replace patterns, which can be a follow-up.

Testing

  • New test/router-provider-modal.test.ts (8 cases) against a shared fake Frame/Page (test/support/fake-frame.ts) that models core's outgoing-entry backstack rule and async dialog dismissal. 6 of the 8 fail on main.
  • Full suite: 88 passed. tsc --noEmit clean.
  • Android (Pixel 9 / API 36 emulator, real adb taps): original repro (close modal → one Back reaches /), re-tap the same modal, deep-linked modal opens once and Back keeps /posts, Back with a modal open, detail push/pop, rapid tap/Back stress.
  • iOS (simulator, Xcode 27.1, driven in-process via the Links' tap delegates and Frame.goBack() as the native pop): the same flows plus sheet dismissal. Router, Frame backstack and presented modal stayed consistent at every step.

…istory

- Router changes that arrive while the Frame sync is locked are applied
  once it unlocks instead of being dropped. Re-tapping a modal link after
  closing it, or navigating during a router back, did nothing.
- Closing a modal natively (Close link, Android back, iOS sheet swipe) pops
  its history entry when it was pushed over the same page, so the next
  hardware Back is not spent on a duplicate `/posts` entry. Deep-linked
  modals still just drop `@modal` in place.
- A deep-linked modal opened twice on Android. Modal opens now wait for
  their page to be visible, and stale or cancelled opens never present.
- While a modal is presented, Android back is left to the dialog, matching
  the iOS sheet dismissal.
- `replace` drops the outgoing page from the Frame backstack (core decides
  backstack membership from the outgoing entry), and router back goes to the
  backstack page for the target path, across several entries if needed.
- The router is only reconciled to the visible page after native pops it
  did not start, so a tap made during a push animation is no longer undone.
@coderabbitai

coderabbitai Bot commented Nov 24, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 5e8017af-e9e7-4170-b44e-7df3ffb196ef

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@NathanWalker
NathanWalker merged commit 295c4ab into main Nov 24, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant