Skip to content

fix(website): keep playground editor scroll through its hash write - #1581

Merged
trueadm merged 1 commit into
mainfrom
claude/eager-moore-d6d9c4
Oct 2, 2026
Merged

trueadm merged 1 commit into
mainfrom
claude/eager-moore-d6d9c4

Conversation

@trueadm

@trueadm trueadm commented Oct 2, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Fixes the intermittent website integration suite failure in website/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

  • The playground writes its workspace into the URL hash 400 ms after an example switch or an edit. It used a bare history.replaceState, but @tanstack/history wraps that method, so each write is a router navigation.
  • router-core's scroll restoration snapshots every element scrolled since the previous navigation at onBeforeLoad and restores those positions at onRendered, because resetScroll defaults to true. The CodeMirror editors are among those elements, so a scroll made while the router loads the new hash is undone.
  • Every CI failure was the first probe after an example switch, which is the only point where this test triggers a hash write. The Counter probes run before any switch and never failed. When the restore lands inside the probe, either:
    • it reverts the final scroll to the target after the click point was computed, so the click hits an unmapped line (source [] output []), or
    • it moves the editor back mid-sweep, so locateSourceKeyword takes that as the end of the document, stops early, and clicks the prose-comment @try.

Fix

updateHash writes the hash through the router with navigate({ 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, which replaceState(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:check is clean on both changed files.
  • pnpm typecheck: not run repo-wide. pnpm typecheck:files on both files plus website/tests/setup/production-server.ts (which declares the inject keys) is clean.
  • pnpm test: not run. The machine is shared, so CI runs the e2e file.
  • targeted checks: headless Playwright against a worktree Vite dev server.
    • Direct check: an editor scroll made inside the hash navigation was restored 240 → 0 before the fix and stays at 240 after it.
    • Load window: onBeforeLoad → onRendered takes 4–5 ms unthrottled and 50–126 ms at 20× CPU throttle.
    • Failing-probe replica: the @try probe with the load window stretched by queued busy tasks failed 12/26 before the fix (both CI failure shapes reproduced) and 0/26 after.
    • New test body: fails 3/3 on the pre-fix code (the restore takes the editor from 345 back to 145) and passes 3/3 with the fix.
    • Hash round-trip: the URL hash is byte-identical to the session-stored own-hash, a reload stays ungated, and there are no page errors.
  • The e2e file was not run through vitest, because that needs a full production build. CI covers it.

Risk / follow-ups

  • website/src/components/OnThisPage.tsrx also calls a bare history.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 hash scrollIntoView. I have not checked whether that causes any visible problem there.
  • The website is private, so there is no changeset.

Provenance

  • An agent produced this diff (agent-authored)

🤖 Generated with Claude Code


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with 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 useNavigate with replace: true, resetScroll: false, and hashScrollIntoView: 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.

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]>
@vercel

vercel Bot commented Oct 2, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated
octane-website-mcp Skipped Skipped Oct 2, 2026 4:20pm UTC

Request Review

@github-actions github-actions Bot added agent-authored Diff or issue body substantially produced by an AI agent fix PR: bug fix labels Oct 2, 2026
@github-actions
github-actions Bot marked this pull request as draft October 2, 2026 16:20
@github-actions

github-actions Bot commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

Benchmark report

  • 🟡 js-framework: 1 timed operation(s) possibly slower

Compares 537877852 with bf908a973 on the same runner. Timing verdicts require a change beyond the combined margin of error (at least 5%) and one 0.1ms timer tick, with the fastest sample also moving beyond that margin. Workflow run

js-framework: 1k/10k row operations (ms, lower is better)

target operation base head Δ noise
octane-jsx select 0.34 0.52 +52.9% ±45% 🟡 slower
All 20 timed operations (19 within noise)
target operation base head Δ noise
octane-tsrx run 3.65 3.84 +5.2% ±17% ⚪ within noise
octane-tsrx replace 7.90 10.80 +36.7% ±39% ⚪ within noise
octane-tsrx add 3.51 3.74 +6.6% ±22% ⚪ within noise
octane-tsrx update 0.43 0.38 −11.6% ±48% ⚪ within noise
octane-tsrx select 0.21 0.19 −9.5% ±63% ⚪ within noise
octane-tsrx swap 0.37 0.38 +2.7% ±35% ⚪ within noise
octane-tsrx remove 0.41 0.37 −9.8% ±65% ⚪ within noise
octane-tsrx runlots 31.50 36.12 +14.7% ±17% ⚪ within noise
octane-tsrx select_lots 0.22 0.30 +36.4% ±55% ⚪ within noise
octane-tsrx clear 47.31 44.46 −6.0% ±33% ⚪ within noise
octane-jsx run 3.84 3.67 −4.4% ±21% ⚪ within noise
octane-jsx replace 7.59 8.16 +7.5% ±34% ⚪ within noise
octane-jsx add 3.40 3.94 +15.9% ±33% ⚪ within noise
octane-jsx update 0.56 0.68 +21.4% ±39% ⚪ within noise
octane-jsx select 0.34 0.52 +52.9% ±45% 🟡 slower
octane-jsx swap 0.67 0.70 +4.5% ±26% ⚪ within noise
octane-jsx remove 0.76 0.67 −11.8% ±47% ⚪ within noise
octane-jsx runlots 29.33 35.27 +20.3% ±24% ⚪ within noise
octane-jsx select_lots 2.44 2.84 +16.4% ±24% ⚪ within noise
octane-jsx clear 44.12 53.81 +22.0% ±23% ⚪ within noise

Application bundle size (bytes)

No changes across 45 measured values.

Public-import reachability bundles (bytes)

No changes across 105 measured values.

@trueadm
trueadm marked this pull request as ready for review October 2, 2026 17:03
@trueadm
trueadm merged commit 18fbcb0 into main Oct 2, 2026
61 checks passed
@trueadm
trueadm deleted the claude/eager-moore-d6d9c4 branch October 2, 2026 17:36

This branch was previously deployed

1 inactive deployment
Preview – octane-website-mcp — 3ff7d6ad Deployed Oct 2, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agent-authored Diff or issue body substantially produced by an AI agent fix PR: bug fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant