From fa5ae66bd6f565d10c16de8966df04058d904671 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 29 Oct 2026 12:51:24 +0000 Subject: [PATCH] refactor(router): lower the shared-parts count once per braced part `expand` lowered `literals` in both the wait branch and the param branch. Doing it once for every part starting with `{` covers both, and a literal part starting with `{` only shares fewer parts with the next route. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01VVaw7Sutbw6xMTMyDFeNfw --- packages/router/src/index.ts | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/packages/router/src/index.ts b/packages/router/src/index.ts index 7abedee..3496e95 100644 --- a/packages/router/src/index.ts +++ b/packages/router/src/index.ts @@ -371,8 +371,8 @@ function indexStatics(routes: MethodRoutes): void { function expand(node: Node, pending: unknown[], start: number, whole: boolean): void { node.pending = undefined // The parts of the previous route, how many of them come before its first - // param or wait, and the node after each of those, so that the next route - // skips parsing the parts it shares with them. + // part starting with `{` once decoded, and the node after each of those, so + // that the next route skips parsing the parts it shares with them. let shared: string[] = [] let literals = 0 const nodes: Node[] = [node] @@ -399,10 +399,10 @@ function expand(node: Node, pending: unknown[], start: number, whole: bool // which keeps the first of two that read the same. A route added whole // goes after the routes waiting there. if (segment[0] === '{') { + if (index < literals) { + literals = index + } if (!whole && index > start) { - if (index < literals) { - literals = index - } ;(child.pending ??= []).push(parts, data, params) continue next } @@ -418,9 +418,6 @@ function expand(node: Node, pending: unknown[], start: number, whole: bool continue } - if (index < literals) { - literals = index - } // An array literal holds just its items, where a push to `[]` reserves 17. if (params === undefined) { params = [segment]