fix(router): run popstate updates on app Runtime via runFork - #76
Merged
Conversation
Deploying effex with
|
| Latest commit: |
6651e7e
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://c6b0fc09.effex.pages.dev |
| Branch Preview URL: | https://fix-popstate-run-on-app-runt.effex.pages.dev |
Deploying effex-api with
|
| Latest commit: |
6651e7e
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://93f64b51.effex-api.pages.dev |
| Branch Preview URL: | https://fix-popstate-run-on-app-runt.effex-api.pages.dev |
Browser back/forward wasn't triggering re-renders. The popstate handler ran the signal update via Effect.runSync, but Signal.set uses SubscriptionRef.set which involves semaphore.withPermits(1) — Effect flags that as async-capable, so runSync bails. Since browsers don't reliably surface exceptions from raw event listener callbacks to console.error, the throw was silent: the URL bar showed the new path but the pathname signal never updated, Outlet's subscribers never received the change, and the page stayed on the previous route. The reporter's SSG dev-mode diagnostic pinned it: after browser back, their raw popstate listener fired with `pathname: "/"`, but a subscriber to `nav.pathname.changes` on the SAME Navigation instance Outlet uses received no notification. Capture the Runtime at Layer construction time and use Runtime.runFork to schedule the update. runFork accepts async work and runs it on the same Runtime the rest of the app uses, so the signal update goes through and subscribers pick it up. Adds a browser-window mock helper (dispatchWindowEvent) plus three regression tests: pathname updates on popstate, subscribers receive popstate changes (Outlet's exact shape), and the handler doesn't throw or fail silently. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
jonlaing
force-pushed
the
fix/popstate-run-on-app-runtime
branch
from
August 3, 2026 17:47
decb125 to
6651e7e
Compare
4 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes browser back/forward buttons not triggering re-renders. Directly diagnosed from a user report on SSG dev mode — same bug affects any client-navigation scenario that relies on
popstate.Root cause
The
popstatehandler ran the pathname signal update viaEffect.runSync:updateStatecallsSignal.set→SubscriptionRef.set, which internally doessemaphore.withPermits(1). Effect flags that as async-capable —runSyncbails, throws. Browsers don't reliably surface exceptions from raw event listener callbacks toconsole.error, so the throw was silent: URL bar showed the new path, but the signal never updated,Outlet's subscribers never saw the change, and the page stayed on the previous route.Interesting subtlety about why nobody noticed before:
pushPath(called fromLink's onClick) runs inside the app's Effect fiber —yield* updateState(...)executes fine because it's not going throughrunSync. Only the raw-event popstate path went throughrunSync. So forward navigation always worked; only browser back/forward was broken.Diagnosis path
User's SSG dev-mode diagnostic pinned it:
The
[NAV real signal changed to]subscriber was attached to the SAMENavigationinstance Outlet uses. Missing that log after back → the popstate handler ran (browser confirmed) but didn't propagate to the signal that Outlet subscribes to.Fix
Capture the layer's Runtime at construction time and use
Runtime.runFork:Two benefits:
runForkaccepts async work — no throw for the semaphore permit.Tests
Adds three regression tests in
Navigation.test.ts:Outletuses (Stream.runForEach(nav.pathname.changes, ...)). This is the one that would have caught the bug had it existed before.Also adds a
dispatchWindowEventhelper on the mock window so future tests can drive real browser event dispatch.tsc --noEmitclean.Changeset:
@effex/routerpatch.🤖 Generated with Claude Code