Repository navigation
fix(website): keep playground editor scroll through its hash write - #1581
Merged
Merged
Conversation
The playground persists its workspace into the URL hash 400ms after an example switch or edit. TanStack Router's history wrapper turns that bare history.replaceState into a navigation, and router-core scroll restoration ends every navigation by restoring each element scrolled since the previous one to its position when this one started. The CodeMirror editors were among them, so a scroll made while the router loaded the new hash was undone. That is the intermittent "playground highlights every control-flow keyword" failure: the first probe after an example switch could locate a keyword and then click whatever line the restore moved under the pointer (`source [], output []`), or have its sweep cut short and click the prose-comment `@try`. Write the hash through the router with `resetScroll: false` and `hashScrollIntoView: false`, and add an e2e case that scrolls the source editor inside the hash navigation and requires the scroll to survive it. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
The latest updates on your projects. Learn more about Vercel for GitHub. 1 Skipped Deployment
|
Contributor
Benchmark report
Compares js-framework: 1k/10k row operations (ms, lower is better)
All 20 timed operations (19 within noise)
Application bundle size (bytes)No changes across 45 measured values. Public-import reachability bundles (bytes)No changes across 105 measured values. |
This branch was previously deployed
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 the intermittent
website integration suitefailure inwebsite/tests/ssr-hydration.e2e.test.ts› "playground highlights every control-flow keyword in the compiled code" (@case in types: source [], output []: expected 0 to be greater than 0/@try in types: source []: expected [] to include 'Suspense'; main runs 37019086703 and 37017278642, and #1570 run 37028085477 attempt 1).This is a real playground defect, not a test race. The types output always renders. Instead, the router scrolls the source editor back while the probe is using it.
Cause
history.replaceState, but@tanstack/historywraps that method, so each write is a router navigation.onBeforeLoadand restores those positions atonRendered, becauseresetScrolldefaults totrue. The CodeMirror editors are among those elements, so a scroll made while the router loads the new hash is undone.source [] output []), orlocateSourceKeywordtakes that as the end of the document, stops early, and clicks the prose-comment@try.Fix
updateHashwrites the hash through the router withnavigate({ to: '.', search: true, hash, replace: true, resetScroll: false, hashScrollIntoView: false }). That still updates only the current entry's hash and keeps the route mounted, but leaves every scroll position alone. As a side effect, history state now keeps__TSR_key/__TSR_index, whichreplaceState(null, …)dropped.Regression: "playground keeps editor scroll through its own URL hash update" (production describe) scrolls the source editor while the router loads the hash write and requires the scroll to survive it.
Validation
pnpm format:check: not run repo-wide.pnpm format:files:checkis clean on both changed files.pnpm typecheck: not run repo-wide.pnpm typecheck:fileson both files pluswebsite/tests/setup/production-server.ts(which declares theinjectkeys) is clean.pnpm test: not run. The machine is shared, so CI runs the e2e file.onBeforeLoad→onRenderedtakes 4–5 ms unthrottled and 50–126 ms at 20× CPU throttle.@tryprobe with the load window stretched by queued busy tasks failed 12/26 before the fix (both CI failure shapes reproduced) and 0/26 after.Risk / follow-ups
website/src/components/OnThisPage.tsrxalso calls a barehistory.replaceState(null, '', '#' + id), and its comment says this does not trip the router. It does, so its section jumps also end in router scroll restoration and a hashscrollIntoView. I have not checked whether that causes any visible problem there.Provenance
agent-authored)🤖 Generated with Claude Code
Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.Note
Low Risk
Scoped to playground URL hash syncing and scroll behavior; no auth or data paths, with a targeted e2e regression.
Overview
Fixes a playground bug where debounced URL hash updates (after edits or example switches) were undoing CodeMirror scroll position. Those updates used
history.replaceState, but TanStack Router treats that as navigation and, with default scroll restoration, snaps editors back to positions captured at navigation start—breaking control-flow keyword probes right after an example change.Playground now writes shareable state via
useNavigatewithreplace: true,resetScroll: false, andhashScrollIntoView: false, so only the hash changes and scroll positions stay put.Adds a production e2e test that scrolls the source editor during the hash navigation triggered by switching examples and asserts the scroll survives.
Reviewed by Cursor Bugbot for commit 3ff7d6a. Bugbot is set up for automated code reviews on this repo. Configure here.