0
Fork 0
mirror of https://github.com/TanStack/router.git synced 2026-11-16 19:38:07 +00:00

refactor(router-utils): one predicate per placement rule

The placement core had grown copies of its own rules: two "reads what the env
module keeps" predicates (one for an extraction candidate, one for what its
output reaches), two effect-order predicates (one per direction), an import
pin computed from pristine references next to an import drop computed from
final needers (each with a route-module clause, with the TypeScript-only
specifier rules in the plan on top), four scans of the references for the
writes each rule needs, and a planner pre-filter duplicating the core's
extraction-candidate filter.

- `readsKeptEagerly` is the one "reads kept" predicate; `extractable` is
  built on it. The two copies disagreed on copyable targets: the merged
  predicate skips them (the reading output gets its own copy, so there is no
  read through the re-export cycle), which lets an exported declaration that
  reads a copyable constant the route module keeps be extracted (test).
- `effectStays` is the one effect-order predicate: for a lazily imported
  output, a surviving effect after the cluster's first effect that stays
  behind; for a static output, any other surviving effect at all.
- `importStays`, next to the declaration orphans, owns the import rule:
  provenance for value specifiers (an import the source never read stays; one
  our edits orphaned, or read only by a dropped dead pure cluster, leaves;
  type-only use leaves route modules), and the TypeScript-only forms (inline
  `type` specifiers, `export { X }` of a type-only binding) after inclusion,
  following their statement's value specifiers. The plan reads inclusion for
  them instead of its own route-module branches; a vacuous branch of the
  source-edge pass goes.
- One table of top-level writes (assignments, augmentations; live, eager,
  owner) feeds clustering, ordered evaluation and the movable test's two
  mutation checks. Both round caps become plain fixed points: every changed
  round merges two clusters, or copies a cluster into an output, so they end.
- A dev-only check after inclusion: no cluster of an extracted export's
  module reads a non-copyable env-module cluster at its evaluation.
- `sideEffectFree` is computed from the content: an output the planner opted
  in is flagged only when no effectful cluster was placed in it (a cluster
  that moved with its only needer keeps the flag off; test).
- The core's candidate filter is the only one (it gains the per-symbol write
  check the planners had); the router and Hydrate planners allow every local
  value export out.
- `Placement` loses the fields nothing read (`movable`, `orphaned`,
  `needers`, `clusterOfSym`, `readsIn`); the claim sequence base is one
  helper; `MUTATORS`/`isObjectMutator` are module-private; source comments
  and the README state the rules instead of citing design notes; the route
  registry's identity contract is on its type (a read-only snapshot).

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
Sheraff 2026-10-27 21:55:49 +01:00
commit 6e28afea28
No known key found for this signature in database
11 changed files with 374 additions and 403 deletions