* perf(router,start): update Seroval to 1.6.6
* perf(router,start): update Seroval to 1.6.7
* chore: update seroval to 1.6.7
seroval and seroval-plugins were pinned to ^1.6.2 while 1.6.7 is the
current release. The type surface is additive: two new options
(maxBase64Length, compactArrayBufferViews) and an isStream export.
Bundle (gzip): router-only scenarios unchanged; Start client bundles
grow 532-642 bytes from the upstream typed array and base64 handling.
react-start.minimal 98504 -> 99039 (+535).
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
---------
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
* perf(benchmarks): compress bundle-size outputs once
* add link to readme in skill
* ci: apply automated fixes
* fix(benchmarks): persist timing flag in measurement command
---------
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
* perf(router-core): split replaceEqualDeep into an equality scan and a copy phase
`replaceEqualDeep` compared and copied in one loop. Every entry, also on
the common all-equal path, paid for the copy bookkeeping (`copy ??=`,
`if (copy) copy[key] = n`), an `equal` flag and — for objects — a
`hasOwn.call(prev, key)` lookup, while arrays and objects shared the
same keyed accesses through `array ? i : keys[i]`, so every access site
saw both element and named keys.
The function now runs in two phases:
- Scan: walk `next` up to the first difference, sharing equal children
on the way. Arrays and objects have their own loop, so each keyed
access only ever sees one kind of key and nothing is allocated while
entries keep matching. A key at the same position of both key lists
is proven to be `prev`'s own key; only reordered keys still need
`hasOwn`. When everything matched and the key counts agree, `prev` is
returned.
- Copy: equality is ruled out, so the loop only builds the result. The
scanned prefix is shared from `prev`, the first differing entry keeps
the value the scan already computed, and the rest is resolved without
any equality bookkeeping.
Only an object entry of `prev` can share anything, so the recursion is
guarded by a single `typeof` check; `null` and mismatched types return
`next`'s entry through the entry checks. `isPlainArray` is no longer
used here: the array check reuses the `Object.keys` result that the
scan needs anyway. Semantics are unchanged: pass-through for
non-enumerable keys and for symbol keys on `next`, null-prototype
copies, the depth limit and the SSR early return all stay as they were,
and the tests pass against both implementations.
Bundle size (`benchmark:bundle-size`, gzip): react-router.minimal -1 B,
react-router.full -18 B, all 18 scenarios net -110 B (13 down, 5 up,
max +20 B on react-start.full for identical code).
Paired runs against the previous version (hz medians of 3 runs,
1000 calls per iteration; the machine was under load, so single-digit
differences are noise):
equal flat search 5.96k -> 6.98k (+17%)
equal nested search 2.47k -> 2.83k (+14%)
equal array of objects 524 -> 579 (+10%)
equal long primitive array (1024) 49 -> 69 (+39%)
long primitive array, last item changed 37 -> 41 (+11%)
wider flat object (64 keys), last changed 218 -> 229 (+5%)
flat search, one changed leaf 5.31k -> 5.59k (+5%)
array of objects, one changed item 483 -> 513 (+6%)
flat search, all leaves changed 5.29k -> 5.35k (+1%)
array of shared objects, one changed 1.61k -> 1.44k (-10%, ±29%)
Entries that change between an object and a primitive now pay one
recursive call instead of an inline four-way type check; guarding both
sides costs more bundle bytes than this branch is worth.
Adds tests for the scan/copy boundary (equal children and next-only
keys after the first difference, reordered keys, object/primitive
transitions, shorter and longer arrays, a change in the last of 1024
entries, the depth limit) and bench cases for the shapes that told the
candidate implementations apart.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
* fix(router-core): keep sparse arrays with extra keys opaque in replaceEqualDeep
The plain-array check compares `Object.keys(array).length` with
`array.length`. A hole and an extra enumerable key cancel out in that
count, so `Object.assign([1, ,], { extra: 'x' })` was admitted: the
index-based copy dropped `extra` and turned the hole into an explicit
`undefined`, and an index-wise equal `prev` was returned for it. The
same blind spot exists in the exported `isPlainArray`, which the
previous implementation used for this check.
Extra string keys always sort after the index keys, so once the count
matches, `next` is a dense index-only array exactly when its last key
is its last index. That is one string comparison per array instead of
a per-key validation, and it stays inline with the existing count
check. `prev` keeps the count check only: a result is either a copy
built from `next`'s entries or `prev` itself, which the caller already
holds.
Symbol keys on arrays stay admitted, as before this stack: checking
them costs an `Object.getOwnPropertySymbols` call per array pair, which
measured ~8% on the equal nested search shape (a record holding a
four-element array), and `react-router.minimal` +3 B on top of the
+13 B gzip of this fix.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
---------
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Every object pair `replaceEqualDeep` visited paid for three native key
lookups per side: `Object.keys`, `Object.getOwnPropertyNames` (to detect
non-enumerable props) and `Object.getOwnPropertySymbols`. Measured on a
4-key literal the first two cost 7.6 ns and 10 ns, the symbol lookup
34 ns — 31 ns even on `{}` — so two thirds of the enumeration cost went
into a key type that router data never carries. (`Reflect.ownKeys` as a
single replacement call was tried and is 100 ns.)
Symbol keys and non-enumerable keys still have to be handled correctly:
Apollo's `preloadQuery` refs carry symbol keys and broke under
`defaultStructuralSharing` when copies dropped them (#4237). Instead of
comparing and copying such objects key by key, they are now opaque: an
object with non-enumerable own keys on either side, or symbol keys on
`next`, makes `next` pass through untouched. That keeps both guarantees
that matter — no partial copy, no stale `prev` returned for it — and only
gives up structural sharing for those objects.
`prev` is not scanned for symbols on purpose. It is normally an earlier
`next`, so a symbol-carrying `prev` meets a symbol-carrying `next` and the
`next` check fires; a symbol-carrying `prev` with a symbol-free, otherwise
equal `next` returns `prev` (covered by a test). Plain objects are now
compared and copied by `Object.keys` alone, and `getEnumerableOwnKeys`
is gone.
Paired runs against the previous version (hz, 1000 calls per iteration):
equal empty objects 14.8k -> 18.3k (+24%)
equal empty null-proto objects 5.1k -> 6.3k (+24%)
equal flat search 7.3k -> 8.2k (+12%)
flat, one changed leaf 6.1k -> 6.9k (+12%)
equal nested search 3.0k -> 3.1k (+4%)
nested, sharing subtrees 2.6k -> 2.7k (+7%)
equal array of objects 609 -> 729 (+20%)
array, one changed item 551 -> 640 (+16%)
wide (12 keys) changed, null-proto 1.8k -> 2.0k (+9%)
Tests now document the pass-through contract for symbol-keyed objects,
including the deliberate `prev`-only asymmetry.
* perf(router-core): check plain objects by constructor
`isPlainObject` gates every recursion step of `replaceEqualDeep` and
`deepEqual`, so it runs at least twice per object pair, on every nested
level, on every navigation and Link build. The previous implementation
(copied from `is-plain-object`) called `Object.prototype.toString` on the
value and again on its constructor's prototype, plus a `hasOwnProperty`
lookup: up to four `toString` dispatches per compared pair, most of them
spent confirming that `{}` is a plain object.
The check is now a single expression:
!!o && typeof o === 'object' && (o.constructor ?? Object) === Object
Object literals, `JSON.parse` output and `Object.create(literal)` inherit
`Object` as their constructor; `Object.create(null)` objects (the router's
search and params objects) have none, which `?? Object` accepts. Class
instances, arrays, `Map`, `Date`, functions and primitives fail it, as
before. The only accept-set differences are objects from another realm
(an iframe's `Object` is not `===` ours) and objects with a custom
`Symbol.toStringTag`; neither occurs in router state.
Paired runs against the previous version (hz, 1000 calls per iteration):
deepEqual equal empty objects 25.6k -> 59.4k (+132%)
deepEqual nested, one changed leaf 11.3k -> 22.8k (+102%)
deepEqual equal flat (partial) 23.0k -> 39.7k (+73%)
replaceEqualDeep equal empty objects 10.6k -> 14.9k (+40%)
replaceEqualDeep equal array of objs 489 -> 604 (+24%)
replaceEqualDeep equal nested 2.4k -> 2.8k (+19%)
replaceEqualDeep equal flat search 6.0k -> 7.0k (+17%)
Adds an accept/reject table for `isPlainObject` and checks that class
instances stay opaque to structural sharing while null-prototype and
literal objects compare as equal.
* fix(router-core): keep records with a constructor key plain
`?constructor=foo` decodes to an own `constructor` data key on the
null-prototype search record, and `(o.constructor ?? Object) === Object`
read that key. Such records (and the `{ ...search }` copies of them) were
classified as non-plain, so `replaceEqualDeep` handed back `next` without
sharing and `deepEqual` reported them unequal.
Keep the constructor comparison as the fast accept: it is an inline-cache
load for literals and null-prototype records and is what the PR's speedup
comes from. When `constructor` is anything else, consult the actual
prototype instead of rejecting: `null` or one whose `constructor` is
`Object` means a record, anything else a class instance. The prototype
lookup is a builtin call (~6ns in megamorphic optimized code), so running
it unconditionally would return most of the gain: median hz over 3
rotated rounds, `replaceEqualDeep` equal empty 10.9k -> 8.6k (-21%),
equal array of objects 470 -> 386 (-18%), `deepEqual` equal empty
58.0k -> 35.9k (-38%). With the fallback only on the mismatch path the
hot cases stay within noise of the shortcut and the constructor-key
cases now do the sharing work at the same cost as other null-prototype
records. `react-router.minimal` gzip is +15 B against the shortcut and
still 44 B below the `toString` implementation.
Benchmarks the predicate directly (literal, null-prototype record, record
with a constructor key, class instance) and sharing of a search record
that carries a constructor key. Tests both record shapes and parser
output, all `constructor` value types, and that a class instance with an
own `constructor` key stays opaque.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
---------
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
`replaceEqualDeep` runs on every navigation and Link build: search,
params, state and loader data all go through it, and in the common case
`next` turns out to be deeply equal to `prev`. Until now the function
still allocated the result object (or array) up front and filled it key
by key while comparing, only to throw it away and return `prev`.
The copy is now created at the first difference. Everything compared
before that point is known to be equal and is taken from `prev` in one
pass (`copyItems`), so unchanged subtrees are shared exactly as before.
When nothing differs, nothing is allocated; when only the key sets
differ, the copy is built after the loop.
Smaller changes in the same function:
- deep equality is a single `equal` flag instead of a matched-key count
compared against the sizes afterwards; once unequal, the `hasOwn`
check for keys that only `next` has is skipped
- `nullReplaceEqualDeep` passes a boolean instead of an object factory,
so the plain variant no longer evaluates a default `() => ({})` per
call and the copy site has no indirect call
- an overload signature keeps the generic return type without the
`_next` alias in the emitted code
- `getEnumerableOwnKeys` loops over `getOwnPropertySymbols` directly;
an empty loop needs no early return
`tests/replace-equal-deep.bench.ts` was added first, with the shapes the
router feeds these helpers. Paired runs against the previous version
(hz, 1000 calls per iteration):
equal empty objects 10.0k -> 10.6k (+6%)
equal flat search 5.3k -> 5.9k (+12%)
equal nested search 2.2k -> 2.4k (+13%)
equal array of objects 445 -> 485 (+9%)
flat, one changed leaf 5.4k -> 5.2k (-3%)
wide (12 keys) changed 2.4k -> 2.2k (-11%)
The equal paths win and allocate nothing; the copy paths pay for the
extra call and the per-key `copy` check.
* refactor(router-core): parse masked locations without mutating shared state
`parseLocation` built the presented location of a masked entry by parsing
the stored `__tempLocation` and then patching and `delete`-ing keys on the
resulting `state`, which `replaceEqualDeep` may have shared with the
previous location, before spreading the result once more. The inner parser
now takes the state to use, so the masked branch passes the intended state
up front and assigns `maskedLocation` on the fresh object.
The slow parsing path only runs the input rewrite when one is configured,
and `resolvePathWithBase` is inlined into its two callers.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
(cherry picked from commit cc6159628cd22faf9c16e6e432cb35093b2826a8)
* refactor(router-core): remove redundant input rewrite guard
---------
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
`resolvePath(base, to, trailingSlash?, cache?)` replaces the options object,
so `resolvePathWithBase` — called from `buildLocation` and `matchRoute` —
no longer allocates per path resolution. `resolvePath` is an internal
helper. react-router.minimal shrinks by 17 B gzip (60 raw).
(cherry picked from commit de7bc72a952aaf77bbedfd4453a4d12edadaad53)
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
* perf(router-core): parse the location once in update and build rewrites without arrays
- update(): compute the basepath/rewrite before the single updateLatestLocation
call; the first update always saw basepathWasUnset, so every router
construction parsed the location twice and re-published to a store created
from the same location.
- invalidate(): fill the id set in one pass instead of spread/flat/filter/map.
- rewriteBasepath(basepath, caseSensitive?) takes positional arguments (it is
internal) and the output rewrite uses cleanPath on a template string instead
of joinPaths' array/filter/join.
- parseLocation(): inline the single-use fullPath local.
react-router.minimal 86019 -> 85989 gzip, react-router.full 89605 -> 89561 gzip.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
(cherry picked from commit 64978a1c8a8b5926c53797edcb528159c70ab093)
* perf(router-core): parse the location once in update and build rewrites without arrays [Self-Healing CI Rerun]
* test(router-core): cover basepath rewrite composition and updates
* perf(router-core): specialize internal basepath rewrites
* fix(router-core): key server route caches by case sensitivity
---------
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: nx-cloud[bot] <71083854+nx-cloud[bot]@users.noreply.github.com>
Mirrors what useLinkProps does on every location publication: 32 links, each
with a stable dest object, pointing _fromLocation at a fresh location and
calling router.buildLocation inside their selector. Covers the static-cache
hit, search updaters (with and without middleware), relative destinations,
inherited params and masks. Baseline (Node 24.8, hz, mean of two runs):
static cache hit 1,928,000 search updater 41,600
+ retainSearchParams 30,850 relative 29,800
params: true 35,050 masked 20,500
(cherry picked from commit d4787b65e25e0817f747fc3c6dc0209889ffe174)
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
`useLinkPropsFor` existed only to keep the `host` argument off the public
`useLinkProps` signature. Fold it into `useLinkProps` behind an `@internal`
overload; `stripInternal` removes that overload from the published
declarations, so the public signature stays `(options, forwardedRef?)`.
react-router.full shrinks by 24 B gzip.
(cherry picked from commit 918d3050850815abc8ae49518befda61cb29bf7b)
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
`deepEqual(a, b, partial?, explicitUndefined?)` replaces the options
object. The hot callers (Link option stabilization and active-state checks,
matchRoute) no longer allocate `{ partial }` / `{ ignoreUndefined: false }`
per comparison, and the comparator reads two booleans instead of an options
parameter that saw four object shapes. `explicitUndefined` (falsy default)
replaces `ignoreUndefined: false` and reuses the `activeOptions` vocabulary.
deepEqual is an internal helper; two-argument callers are unaffected.
react-router.minimal shrinks by 48 B gzip (129 raw) on top of the previous
commit; the Link stabilization micro-benchmark improves by ~10% and the
paired Link component runner resolves three cases as faster.
(cherry picked from commit d6f2c1ca55a4900b33868cfc115ac7120d68d26b)
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Compare array elements by identity before recursing, count the exact
comparison down with a single counter, and drop the `typeof` early exit,
which `Array.isArray`/`isPlainObject` already imply. Behavior, key
enumeration and getter read order are unchanged (pinned by the new contract
test).
Measured in one mixed-mode process (all option modes share the function's
type feedback, which is how the router uses it): equal numeric arrays ~+65%,
flat records +7-9%, nested records and mismatches +7-8%; every case
improves. Identity guards inside the object loops were rejected: they grow
the recursive function past what V8 keeps inlining and cost -31% on a
single-key mismatch. react-router.minimal shrinks by 4 B gzip.
(cherry picked from commit cb23ed54757255540cb203081c3423524d6483ca)
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
* chore(benchmarks): remove TSR_LINK_PERF opt-in flag
The router-core Link/path benchmarks and the react-link-performance
project are never part of the CodSpeed matrix or the client-nav/SSR
aggregate projects, so the env-var gate only added friction. Rely on
standard vitest name filtering (-t) to narrow runs instead.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
* fix(router-core): treat 0 and false as provided _splat values
Splat interpolation used a falsy check, so _splat: 0 was omitted like a
missing param while $id: 0 interpolated to '/0'. Only undefined, null,
and '' now omit a splat segment, matching how other path params are
stringified.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
* test(router-core): use path-derived ids in original-param-names fixtures
The matcher only uses route ids as routesById keys and for the pathless
'_' check, so unrelated ids worked but never occur in a real router.
Align the fixtures with the sibling test file's convention where each
id mirrors its fullPath.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
* perf(solid-router): shorten conditional Link class and style spreads
Spread `cond && { value }` instead of `cond ? { value } : undefined`,
matching the neighbouring `active && STATIC_ACTIVE_ATTRIBUTES` spread.
Falsy operands spread to nothing, so the emitted props are unchanged.
Measured with the bundle-size benchmark on solid-router.full:
gzip 39205 -> 39198 (-7), raw -12, brotli -33.
Covered by the existing `six-adults-open` changeset.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
* test(router-core): drop the unused server axis from interpolatePath tests
The `interpolatePath (server: $server)` block never read its `server`
argument since interpolation stopped taking a server flag, so it ran every
case twice under a misleading label. The remaining diff is re-indentation;
review with `git show -w`.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
* test(router-core): interpolate paths through the production API in tests
`interpolateTestPath` only survived as a compatibility layer from the
segment-reuse refactor: it emulated the removed
`(path, params, decoder, usedParams, keys, metadata)` signature by parsing
the template, re-implementing the param-name loop and folding
`hasMissingPathParams` into a metadata flag.
Call the real functions instead. Tests now parse templates with
`parseSegments(false, { fullPath }, 0)` exactly like `buildLocation` does
for templates without a processed route, pass the segments to
`interpolatePath`, and read names and availability from `getParamNames`
and `hasMissingPathParams`. The prepared-route tests compare route-owned
segments against that standalone parse directly, and the interpolation
bench derives its reference values the same way.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
---------
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
`buildLocation` matched the current location up front for every build,
although the result is only read by relative destinations, inherited
params, `search: true` or updater functions and search middlewares. An
absolute destination with its params given, on a branch without search
middlewares, never reads it, yet still paid three store reads and a
WeakMap lookup per call. The match is now computed on first read, and the
destination template is scanned for `$` once instead of twice.
Server `buildLocation` of `/items/$itemId` with params on a middleware-free
tree: 399 -> 382 ns per call (-4%). Builds that read the current match are
unchanged. react-router.minimal gzip +4 (86008 -> 86012, the stack base).
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
* perf(react-router): memoize Link and forward refs without an effect
When a layout re-renders on navigation, for instance because it reads
`useLocation`, every Link below it re-renders too. Profiling 200 mounted
Links showed that re-render dominated by React's per-hook update work, the
element creation and the anchor's prop diff, not by the Link's own logic.
A Link's output depends only on its props, the router context and the
location store, all of which React tracks for memoized components, so
`Link` is now wrapped in `React.memo`. Router options are compared by
value, because destinations are usually inline object literals; element
props are compared by reference, since they may hold arbitrary, even
cyclic, user data. The comparator reuses `ROUTER_OPTION_KEYS`.
The memo adds one fiber per Link. To pay for it, `useForwardedRef` goes:
its `useImperativeHandle` was the only layout effect on a Link and ran for
every Link although most never receive a ref. The link keeps a plain
`useRef`; when a ref is forwarded, one callback fills both. The hook had no
other consumer. `enqueuePreload` no longer doubles as the cleanup path: the
preload effect cancels the intent timer directly.
Measurements (macOS arm64, Node 24.8.0, local, against the previous commit):
- Link client paired runner, 200 Links under a re-rendering layout
(3 repeats): shared-params CPU -54%, masks -56%, rewrites -60%; links
whose props can never compare equal (updater functions, inline
`activeProps` functions) param-updaters +2.5% [-5.2, 10.9],
location-updaters -1.0%, active -2.0%, all inconclusive.
- retained heap per mounted app 2782 -> 2738 KB; mount unchanged within
noise (the memo fiber and the removed layout effect cancel out).
- react-router.minimal gzip 85968 -> 86008 (+40); the branch stays 4 bytes
under the stack base.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
* fix(react-router): memoize the Link's merged ref callback
The merged ref that fills a forwarded ref alongside the link's own ref was
an inline closure, so every Link render produced a new callback and React
detached and re-attached it: a consumer's callback ref was called with
`null` and then the element again on each location-driven re-render
(3 calls after one navigation instead of 1), and an object ref was cleared
and refilled inside the commit. `useImperativeHandle(ref, ..., [])` on main
only re-ran when the consumer's ref changed.
The callback is now memoized with `useCallback` on the forwarded ref, which
restores that contract: the consumer is notified on mount, when their ref
changes and on unmount. A cleanup returned by a consumer callback is still
passed through to React. Nothing reads `innerRef.current` after a detach
without a re-attach, so the wrapper that would clear it on cleanup is left
out (+19 gzip for no observable behavior).
`areLinkPropsEqual` keeps the same rule but states it in two steps, since
the nested condition read as if `children` were deep-compared: element
props (`children`, handlers, `style`, ...) only match by reference, and
only router options fall through to `deepEqual`.
Tests pin all three: a stable callback ref stays at one call across a
location change and is released when swapped, a returned cleanup runs on
unmount instead of a `null` call, and a new JSX child or a cyclic element
prop re-renders the Link instead of being compared deeply. The ref test
fails on the previous commit with `expected 1 call, got 3`.
Measurements (local: macOS arm64, Node 24.8.0, production React 19.2.3):
- `react-router.minimal` gzip 86008 -> 86004 (-4). The comparator
restructure alone is -2; `useCallback` without the cleanup wrapper is
neutral, the wrapper would have been +19.
- Mount of the 200-Link benchmark app, medians of 60 runs: 4.97 ms with
`useImperativeHandle` (main's mechanism on top of this branch), 4.71 ms
with the inline callback, 4.69 ms memoized. Retained heap per mounted app:
-23 KB against `useImperativeHandle` (its layout effect keeps an effect
node, a bound function and two deps arrays per fiber pair).
- Paired client runner, 3 repeats, memoized vs `useImperativeHandle`: 12/13
workloads inconclusive, `rewrites` -4.6% [-9.0, -0.2]. Memoized vs the
inline callback: +2.5% [1.4, 3.7] on `param-updaters` and +1.4% [0.4, 2.5]
on `relative`, where every Link re-renders per navigation and pays the
extra hook; the other 11 workloads are inconclusive.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
---------
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
A Link render ran about 25 hook slots. React allocates a hook object per
slot per render, plus a deps array for every memo, callback and effect, so
the slots set both the re-render cost and the retained fiber memory of a
mounted Link. Five of them did not need to exist:
- The three `useValueStable` refs for `search`, `params` and `activeOptions`
become one `useStableValues` ref that replaces each entry only when its
own contents change, so identities behave exactly as before.
- `_options` and its `dest` copy come out of one memo instead of two.
- `doPreload` is a module function, `preloadLink(router, options)`; the
callback existed only to give the effects a stable identity.
- The IntersectionObserver effect and the render-preload effect merge into
one preload effect whose cleanup also cancels a pending intent timer, as
the observer hook's cleanup did. `useIntersectionObserver` had no other
consumer and is removed.
`hasRenderFetched` stays: without it a link with an updater-function
`search` would preload on every render.
Measurements (macOS arm64, Node 24.8.0, local, 200 mounted Links):
- retained heap per mounted app 2949 -> 2782 KB (-6%, about -0.8 KB per Link)
- mount (router creation + first render) median 2.05 -> 1.90 ms
- Link client paired runner (4 repeats): shared-params CPU -3.0%
[-5.3, -0.6], active -3.3% [-8.4, 2.1]
- react-router.minimal gzip 85984 -> 85968 (-16)
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
The client and the server each kept their own copy of the 35 option names:
the client as an object-rest destructure, the server as a Set. The two
paths then assembled the result differently, with an eleven-spread external
return and a fourteen-entry literal on the client and a fill-in-place
sequence on the server.
Both now share two helpers. `collectElementProps` copies every option the
router does not consume, using one `ROUTER_OPTION_KEYS` set plus the two
host rules (`Link` hosts never render `type`, an anchor has no `disabled`).
`applyLinkState` finishes a router-controlled link: the selected state
props, then the routing attributes and the merged class and style. It is
the one place that defines precedence and absorbs `resolveStateProps`. The
client adds its composed handlers between the two; the server adds
nothing. External links return the collected props with `ref` and `href`.
Element props therefore pass through as given instead of being stripped
and re-added: external links forward them verbatim, falsy values included,
and `useLinkProps` returns `children` for router-controlled links as it
already did for external ones. Class and style are assigned only when the
link or its state props provide one, so links without them carry no
`undefined` keys and empty strings are still dropped.
Measurements (macOS arm64, Node 24.8.0, local, against the previous commit):
- react-router.minimal gzip 86019 -> 85984 (-35); -28 against the stack
base, which this branch previously exceeded by 7.
- Link client paired runner (3 repeats): shared-params CPU -13.8%,
unique-params -11.4%, middleware -8.6%, encoding -13.2%, active -16.9%,
all "faster". A 35-key object rest costs about 440 ns per call, the key
set copy about 50 ns.
- Link SSR paired runner (6 repeats): +0.4% to +1.5%, inside the runner's
+/-4% noise floor measured head-against-head. SSR bundle 189850 -> 189523.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>