diff --git a/.changeset/six-ravens-attack.md b/.changeset/six-ravens-attack.md new file mode 100644 index 000000000000..c2217a344876 --- /dev/null +++ b/.changeset/six-ravens-attack.md @@ -0,0 +1,5 @@ +--- +'@sveltejs/kit': patch +--- + +[fix] continuous optionals should not throw conflict error diff --git a/packages/kit/src/core/sync/create_manifest_data/index.js b/packages/kit/src/core/sync/create_manifest_data/index.js index 4fc738f92ea3..8beb9b53c239 100644 --- a/packages/kit/src/core/sync/create_manifest_data/index.js +++ b/packages/kit/src/core/sync/create_manifest_data/index.js @@ -486,10 +486,11 @@ function prevent_conflicts(routes) { const matcher = split[i]; const next = split[i + 1]; - permutations = [ - ...permutations.map((x) => x + next), - ...permutations.map((x) => x + `<${matcher}>${next}`) - ]; + permutations = permutations.reduce((a, b) => { + a.push(b + next); + if (!(matcher === '*' && b.endsWith('//'))) a.push(b + `<${matcher}>${next}`); + return a; + }, /** @type {string[]} */ ([])); } for (const permutation of permutations) { diff --git a/packages/kit/src/core/sync/create_manifest_data/index.spec.js b/packages/kit/src/core/sync/create_manifest_data/index.spec.js index c386d8ac0614..ff52bda7cf43 100644 --- a/packages/kit/src/core/sync/create_manifest_data/index.spec.js +++ b/packages/kit/src/core/sync/create_manifest_data/index.spec.js @@ -386,6 +386,35 @@ test('optional parameters', () => { ]); }); +test('nested optionals', () => { + const { nodes, routes } = create('samples/nested-optionals'); + assert.equal(nodes.map(simplify_node), [ + default_layout, + default_error, + { component: 'samples/nested-optionals/[[a]]/[[b]]/+page.svelte' } + ]); + + assert.equal(routes.map(simplify_route), [ + { + id: '/', + pattern: '/^/$/' + }, + { + id: '/[[a]]/[[b]]', + pattern: '/^(?:/([^/]+))?(?:/([^/]+))?/?$/', + page: { + layouts: [0], + errors: [1], + leaf: nodes.findIndex((node) => node.component?.includes('/[[a]]/[[b]]')) + } + }, + { + id: '/[[a]]', + pattern: '/^(?:/([^/]+))?/?$/' + } + ]); +}); + test('ignores files and directories with leading underscores', () => { const { routes } = create('samples/hidden-underscore'); diff --git a/packages/kit/src/core/sync/create_manifest_data/test/samples/nested-optionals/[[a]]/[[b]]/+page.svelte b/packages/kit/src/core/sync/create_manifest_data/test/samples/nested-optionals/[[a]]/[[b]]/+page.svelte new file mode 100644 index 000000000000..e69de29bb2d1