Skip to content

refactor(router): orphan revalidation → shared parallel helper via policy args (#568 sub-item 2) - #578

Merged
ivogt merged 1 commit into
mainfrom
refactor/orphan-shared-parallel-helper
Jun 14, 2026
Merged

ivogt merged 1 commit into
mainfrom
refactor/orphan-shared-parallel-helper

Conversation

@ivogt

@ivogt ivogt commented Jun 14, 2026

Copy link
Copy Markdown
Collaborator

Summary

Sub-item 2 of #568 (the M11 item): resolveOrphanLayoutWithRevalidation inlined ~130 lines of parallel-slot resolution that duplicated resolveParallelSegmentsWithRevalidation. This folds the orphan loop into the shared helper, carrying the two divergences as explicit policy args — byte-for-byte behavior-preserving for both paths, no consumer-observable change.

This is a refactor, but it touches the partial-revalidation hot path, so the bar is provable behavior-preservation. The headline is the coverage built first: the existing pinning suite silently failed to lock the divergence the issue is about, and that gap is now closed.

The two divergences, carried as policy args

Arg main (default) orphan Verdict
parentChainDefault "type-derived" → seed an unknown parent-chain slot with belongsToRoute || isNewParent "force-render" → seed unconditional true (A) INTENTIONAL — orphan parallels always belong to the route; force-render is the #482 blank-parent-chain-slot guard. Reachable at belongsToRoute=false. Carried, never normalized.
loaderOrder "after" → emit a slot's loaders after the slot segment "before" → emit them first (B) cosmetic — only the segments/matchedIds emission order, which the client reconciler is insensitive to (loader sub-ids filtered, slots re-grouped by parent). Carried exactly.

The orphan loop is now a single call:

const parallelResult = await resolveParallelSegmentsWithRevalidation(
  orphan, params, context, belongsToRoute, clientSegmentIds, prevParams,
  request, prevUrl, nextUrl, routeKey, deps, actionContext, stale,
  { parentChainDefault: "force-render", loaderOrder: "before" },
);

entry.shortCode === orphan.shortCode (orphan is passed as entry), so all parallel ids and the loader shortCodeOverride are unchanged. The orphan layout's own loader / inherited-parent-loader / handler resolution (everything before the loop) is untouched.

Coverage-first — the part that matters

The existing parallel-revalidate-fns-invocation.test.ts did not actually lock either divergence: every orphan case used belongsToRoute=true, where (A)'s two policies coincide, and the revalidate fns overrode the seed. It would stay green under any unification. So before refactoring, I added pinning tests (written and verified green on the unmodified code):

  • (A) belongsToRoute=false, slot ∉ client, parent ∈ client (isNewParent=false), zero revalidate fns (so the seed is the final decision), sentinel-returning handler so "resolved vs skipped" is observable: the main path SKIPS the slot (component null, handler never runs); the orphan path FORCE-RENDERS it (handler runs). Empirically non-vacuous — flipping the orphan to "type-derived" turns the orphan test red while main stays green.
  • (B) loaderOrder flips slot-vs-loader emission order, and the orphan path chooses "before" (a slot's loaders precede its slot segment).

These stay green after the refactor — that is the behavior-preservation proof for the policy semantics.

Test plan

  • pnpm run typecheck — 12/12
  • pnpm run test:unit:all (repo root) — 0 failures
  • pnpm run lint / pnpm run format — clean
  • semantic-matrix — 61/61 dev + production, no row changes
  • parallel e2e (parallel-reval-after-action, parallel-loader-reval, parallel-loader-inherit, parallel-meta) — 65/65 dev + production (incl. the fix(router): invoke parallel slot revalidate() fns when slot missing from clientSegmentIds #482 orphan-parallel-after-action scenario)
  • New pinning tests for (A) + (B), green before and after the refactor; the (A) test proven non-vacuous
  • Adversarially verified byte-identical for both paths (seed equivalence incl. the reason string, emission order for 1-slot / 2-slots-same-entry / 2-slots-different-entries, shortCodeOverride, all other invariants) — refuted: false, high confidence

Notes

…r via policy args (#568)

resolveOrphanLayoutWithRevalidation inlined ~130 lines of parallel-slot
resolution that duplicated resolveParallelSegmentsWithRevalidation. The two
diverged in exactly two ways; both are now explicit args on the shared helper,
preserving each path BYTE-FOR-BYTE:

  - parentChainDefault: "type-derived" (main) seeds an unknown parent-chain
    slot with belongsToRoute || isNewParent; "force-render" (orphan) seeds
    unconditional true -- orphan parallels always belong to the route (the #482
    blank-parent-chain-slot guard). Divergence (A): INTENTIONAL, carried, not
    normalized.
  - loaderOrder: "after" (main) emits a slot's loaders after the slot segment;
    "before" (orphan) emits them first. Divergence (B): cosmetic emission order
    (the client reconciler is order-insensitive), carried exactly.

The orphan loop becomes a single call; the orphan layout's own loader/inherited/
handler resolution is untouched.

Coverage-first: the existing parallel-revalidate-fns suite never exercised the
divergent case (all orphan tests used belongsToRoute=true, where the policies
coincide). Added pinning tests, written + verified green BEFORE the refactor:
  - (A) belongsToRoute=false, slot not in client, parent in client, zero
    revalidate fns -> main SKIPS the slot (component null), orphan FORCE-RENDERS
    it. Non-vacuous: normalizing the orphan policy turns the orphan test red.
  - (B) loaderOrder flips slot-vs-loader emission order; orphan chooses "before".

Behavior-preserving: semantic matrix 61/61 dev+prod (no row changes), parallel
e2e 65/65 dev+prod, adversarially verified byte-identical for both paths.
@pkg-pr-new

pkg-pr-new Bot commented Jun 14, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@rangojs/router@578

commit: b403d27

@ivogt
ivogt merged commit 7fb5825 into main Jun 14, 2026
25 checks passed
@ivogt
ivogt deleted the refactor/orphan-shared-parallel-helper branch June 14, 2026 07:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant