Skip to content

Commit b963f52

Browse files
[fix] overly restrictive route breakout regex (#6224)
* [fix] overly restrictive regex for route breakouts * add changeset * add test Co-authored-by: Rich Harris <hello@rich-harris.dev>
1 parent 9c7a6a9 commit b963f52

File tree

4 files changed

+17
-3
lines changed

4 files changed

+17
-3
lines changed

.changeset/plenty-shirts-pull.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@sveltejs/kit': patch
3+
---
4+
5+
[fix] allow `@` route breakouts to layouts in `[foo]` or `(foo)` directories

packages/kit/src/core/sync/create_manifest_data/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ function analyze(project_relative, file, component_extensions, module_extensions
321321
const component_extension = component_extensions.find((ext) => file.endsWith(ext));
322322
if (component_extension) {
323323
const name = file.slice(0, -component_extension.length);
324-
const pattern = /^\+(?:(page(?:@([a-zA-Z0-9_-]*))?)|(layout(?:@([a-zA-Z0-9_-]*))?)|(error))$/;
324+
const pattern = /^\+(?:(page(?:@(.*))?)|(layout(?:@(.*))?)|(error))$/;
325325
const match = pattern.exec(name);
326326
if (!match) {
327327
// TODO remove for 1.0

packages/kit/src/core/sync/create_manifest_data/index.spec.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,11 @@ test('creates routes with named layouts', () => {
494494
{ component: 'samples/named-layouts/b/c/c2/+page@.svelte', parent_id: '' }, // 11
495495
{ component: 'samples/named-layouts/b/d/(special)/+page.svelte' }, // 12
496496
{ component: 'samples/named-layouts/b/d/(special)/(extraspecial)/d2/+page.svelte' }, // 13
497-
{ component: 'samples/named-layouts/b/d/d1/+page.svelte' } // 14
497+
{
498+
component: 'samples/named-layouts/b/d/(special)/(extraspecial)/d3/+page@(special).svelte',
499+
parent_id: '(special)'
500+
}, // 14
501+
{ component: 'samples/named-layouts/b/d/d1/+page.svelte' } // 15
498502
]);
499503

500504
assert.equal(routes.filter((route) => route.page).map(simplify_route), [
@@ -521,7 +525,7 @@ test('creates routes with named layouts', () => {
521525
{
522526
id: 'b/d/d1',
523527
pattern: '/^/b/d/d1/?$/',
524-
page: { layouts: [0], errors: [1], leaf: 14 }
528+
page: { layouts: [0], errors: [1], leaf: 15 }
525529
},
526530
{
527531
id: '(special)/(alsospecial)/b/c/c1',
@@ -532,6 +536,11 @@ test('creates routes with named layouts', () => {
532536
id: 'b/d/(special)/(extraspecial)/d2',
533537
pattern: '/^/b/d/d2/?$/',
534538
page: { layouts: [0, 6, 7], errors: [1, undefined, undefined], leaf: 13 }
539+
},
540+
{
541+
id: 'b/d/(special)/(extraspecial)/d3',
542+
pattern: '/^/b/d/d3/?$/',
543+
page: { layouts: [0, 6], errors: [1, undefined], leaf: 14 }
535544
}
536545
]);
537546
});

packages/kit/src/core/sync/create_manifest_data/test/samples/named-layouts/b/d/(special)/(extraspecial)/d3/+page@(special).svelte

Whitespace-only changes.

0 commit comments

Comments
 (0)