test: wait for popstate state updates - #16954
Conversation
|
Install the latest version of pnpm add https://pkg.svelte.dev/@sveltejs/kit/c/d3a37f8c062fde982ee5aa79c166b03c04b67299Open in Note This PR is from a fork. A maintainer must approve approve each commit before it can be built and installed. |
|
|
@svelte-triage-bot. Seems like you're working around the issue. Review proper documentation on modern playwright to understand how to programatically fix this. Consider I might be absolutely incorrect, but this feels like it can have more correctness and "taste" |
|
Thanks for raising it — I reviewed the current Playwright guidance. The existing change is already using a web-first locator assertion (
The added hidden value is a test-fixture observation of precisely that condition: That said, the concern about taste is valid. A cleaner version could expose this through an already-purposeful test fixture output (rather than introducing a standalone hidden |
Replaces #16954. The `popstate` handler in `client.js` awaits route resolution (`get_navigation_intent`, and again inside `navigate` before `accept`) before recording that the browser has moved. Under server-side route resolution that is a network round-trip, during which `current_history_index` still points at the entry we left. A popstate arriving in that window is swallowed by the cancellation guard, and a `goto` pushes an entry with a duplicate `historyIndex`, so later scroll and snapshot restores read the wrong entry. This is the flake in https://github.com/sveltejs/kit/actions/runs/33085846048. Record the traversal synchronously: capture the source entry's scroll and snapshots and move the indices before anything async, restore them in `block()` before `history.go(-delta)`, and capture the navigation token up front so a superseded popstate stops instead of taking over the newer navigation's token. `navigate` skips its own capture for popped navigations. Repro: a 120 ms delay after the `get_navigation_intent` await in the handler fails `Preserves scroll and focus across popstate...` 4/4 in `test:server-side-route-resolution:dev` before this change and passes 4/4 after it.
Fixes a pre-existing browser-test flake observed on #16878 in https://github.com/sveltejs/kit/actions/runs/33085846048.
The test previously continued once the browser URL and unchanged scroll/focus values matched. Those conditions can become true before SvelteKit's asynchronous popstate handler accepts the new history index. Under contention, the subsequent navigation could therefore reuse a stale index and restore the wrong scroll entry.
Render the effective search state for this test route and await it after each history traversal so the test only continues once
$app/statereflects the popstate.Verification:
pnpm -F test-basics check