Repository navigation
perf(claims): trust server link state at hydration - #684
Merged
Merged
Conversation
When the server rendered link state (`hasServerLinkState()`), a hydrating anchor already carries `aria-current`/`data-active` for the location being hydrated, so the claim registers it without resolving its URL. The sweep resolves it on the first routing change. Anchors the server skipped for an authored `aria-current` are still resolved at claim. This is the deferral #665 proposed, made correct by the server link state from #654. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LZkrATgvFJjgFRdDB4Drcq
🦋 Changeset detectedLatest commit: 3832cd5 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
ryansolid
marked this pull request as ready for review
October 14, 2026 07:44
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.
Before: every anchor claimed during hydration resolves its
hrefwithnew URL()and runs the link matcher, even when the server already rendered itsaria-current/data-active. The HN story page has 1,414 claimed anchors. On the SPA twin with a client toggle per comment, the claim handler takes about 55 ms at load at 4x CPU (median of 7, timed inside the handler).After: when the document carries server link state (
hasServerLinkState()), a hydrating anchor is registered without being resolved. The registry sweep resolves it on the first routing change. An anchor the server skipped because of an authoredaria-currentis still resolved at claim, as before. So are client-created anchors and pages rendered without server link state.This is the deferral proposed in #665. It was declined there because server HTML could not carry link state; #654 / #668 made that possible, but the claim never started trusting it.
How:
setupLinkClaimsskips the claim-timerefreshwhenserverState && isHydrating()and the anchor either has noaria-currentor carries the router's own (rec.owned). Therec.ownedexpression is unchanged, only rewritten to reuse thehydratingflag.Measured on the HN SPA toggle variant by patching the built bundle the same way (
/stories/30186326, 4x CPU, cold):The SC twin gets the same saving on its hydrated anchors.
Tests:
hydration-link-state.spec.tsnow records which anchor hrefs are resolved against the document during hydration and expects only the authored anchor. It failed before this change (it saw/,/about, and the absolute link) and passes after. The existing assertions on the state after hydration, after navigation, and on the late streamed anchor still pass.npm test: 707 + 96 pass, and types pass.🤖 Generated with Claude Code
https://claude.ai/code/session_01LZkrATgvFJjgFRdDB4Drcq
Generated by Claude Code