Repository navigation
fix(octane): infer useLinkedState's value when the reconciler declares previous - #1834
Merged
Merged
Conversation
…s previous Contextually typing an unannotated `previous` parameter fixed the linked value type before TypeScript read the reconciler's return type, so the tuple became `unknown` whenever nothing else named the value type (#1830). Split the declarations into `Value` (the return type) and `Previous` (the type of `previous.value`, defaulting to `Value`). The tuple uses `Previous` when it is known from an annotated `previous`, typed options, or explicit type arguments, and falls back to the returned type otherwise. `Value extends Previous` keeps returns storable as `previous.value`. The client, server, and universal entry points share the shape. Closes #1830 Co-Authored-By: Claude Opus 5.5 <[email protected]>
trueadm
marked this pull request as ready for review
October 6, 2026 21:53
|
The latest updates on your projects. Learn more about Vercel for GitHub. 2 Skipped Deployments
|
trueadm
added a commit
that referenced
this pull request
Oct 6, 2026
Budget-only raise for #1833, which deferred its raise until #1831 landed because both raise the same budgets. #1832 covered #1831 alone, so main 50e18cc fails test shard 1/4 at "Verify every bundle budget" (cli-spa-starter raw 101,793 over 100,464). #1833 keeps link records for keyed-list rollback (record forms plus the link notes in each relinking reconcile path). Its own measurement: +1,359 raw / +443 gzip on rows. Measured on main 50e18cc with `run-minimal.mjs --write-budgets` and `run.mjs --write-budgets octane-tsrx octane-jsx` (measured + 32 raw/gzip, + 256 brotli); 60 raises, no lowerings: - every client scenario and app: about +1,355 raw, +415 to +475 gzip - cli-spa-starter 100,464 -> 101,825 raw, 33,454 -> 33,883 gzip - root-static 163,723 -> 165,078 raw; rows framework 104,467 -> 105,826 raw - jsx framework 177,637 -> 178,994 raw - brotli rises where the measurement passed the old value (+256 headroom) Bisected per commit on cli-spa-starter: 4dcb699 100,347 raw, #1833 101,708, #1834 101,708, #1831 101,793. Co-Authored-By: Claude Opus 5.5 <[email protected]>
trueadm
added a commit
that referenced
this pull request
Oct 6, 2026
…ate note #1834 added a TypeScript paragraph to core-apis.mdx above the API tables, so the four deferred scrollable-region-focusable tables each moved down one child: .table-scroll:nth-child(114/138/143/203) -> (115/139/144/204). The website integration suite's a11y sweep failed both themes on main 8b5b828 with exactly that shift; the findings themselves are unchanged. Co-Authored-By: Claude Opus 5.5 <[email protected]>
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 #1830.
useLinkedStatenow infers its value from the reconciler's return type when the reconciler declares an unannotatedpreviousparameter. The issue's example now typeschangedasbooleanwith no annotation.Why
The bug wasn't specific to
sourceEqual. Any reconciler that declaredpreviousproducedunknownunless something else named the value type, such as typed options, explicit type arguments, or an annotation. TypeScript gives an unannotated callback parameter its contextual type before it checks the body. Doing that fixes every type parameter the parameter's type names.previous: LinkedStatePrevious<Source, Value>namedValue, soValuewas fixed, tounknown, before the return type could infer it.Changes
<Source, Value extends Previous, Previous = Value>:Valueis the reconciler's return type.Previousis the type ofprevious.value(and of the options'valueEqual).previous, it fixesPreviousinstead ofValue.Previousdefaults to whateverValuehas inferred so far, soValuestays free for the return type.unknown extends Previous ? Value : Previous. An annotatedprevious, typed options, or explicit type arguments still declare the state type, including one wider than the return type (for example anItem | nullannotation with a reconciler that returnsnull). Without any of them, the tuple uses the return type.Value extends Previouskeeps every returned value storable asprevious.value. A mismatched annotation or explicit type arguments are still errors.octane,octane/server, andoctane/universaldeclarations and their compiler-selected__useLinkedStateWithGettervariants. Implementation signatures and runtime code are unchanged.docs/tsrx-basics.mdand the website's core APIs page note that a reconciler that readsprevious.valueshould declare its type, with a return annotation or an annotatedprevious.What remains a TypeScript limit: with no declared type,
previous.valueisunknowninside the reconciler. TypeScript has to type the parameter before it can read the body's return type, and it doesn't iterate to a fixpoint. That was already the case before this change. The annotation workaround from the issue still works, and now also typesprevious.value.Validation
pnpm format:check: not run locally (scopedpnpm format:files:checkover all 7 changed files passes)pnpm typecheck: not run in full locally. Scopedoctane-tscpasses forpackages/octane(+typetests,typetests/react-compat), and for every project that callsuseLinkedState: apollo-client (+ typetests), aria, lynx (+ typetests), radix, sanity-loader, tanstack-router, xstate, octane-evals, vite-plugin-octane, website.packages/selectshows the same 3components.tsrxRef errors onmainwithout this change (it is not in the root typecheck).pnpm test: not run locally (type-only change; CI runs it)packages/octane/typetests/hooks.test-d.ts:previous.valuepreviouswider than the return keeps its type<Source, Value, Previous>are rejected@ts-expect-errors go unusedRisk / follow-ups
useLinkedState<T, T>), the tuple shows as a deferredunknown extends T ? T : Tin hovers. It is assignable to and fromT, and every binding that does this still typechecks.anyas theprevious.valuetype, the tuple takes the return type rather thanany.Provenance
agent-authored)🤖 Generated with Claude Code
Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.Note
Low Risk
Type-only declaration and documentation changes with no runtime, SSR, or hydration impact; the main behavior shift is stricter or different inference at compile time.
Overview
Fixes a TypeScript inference bug where
useLinkedStatetyped the linked value asunknownwhenever the reconciler declared an unannotatedpreviousparameter (contextual typing fixed the old singleValueparameter before the return type could infer).The public declarations now use
<Source, Value extends Previous, Previous = Value>:Valueis the reconciler’s return type,Previousisprevious.value/valueEqual, and the tuple’s value type isPreviouswhen known, otherwiseValue. The same signature shape is applied on client, server, and universal entry points plus__useLinkedStateWithGetter. Runtime behavior is unchanged.Docs note that reconcilers that read
previous.valueshould still annotate the return type orprevious. Newhooks.test-d.tscases lock in the issue fix, return-annotation behavior, widepreviousannotations, and mismatch errors.Reviewed by Cursor Bugbot for commit d332555. Bugbot is set up for automated code reviews on this repo. Configure here.