Skip to content

[fix] overly restrictive route breakout regex #6224

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Aug 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/plenty-shirts-pull.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/kit': patch
---

[fix] allow `@` route breakouts to layouts in `[foo]` or `(foo)` directories
2 changes: 1 addition & 1 deletion packages/kit/src/core/sync/create_manifest_data/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ function analyze(project_relative, file, component_extensions, module_extensions
const component_extension = component_extensions.find((ext) => file.endsWith(ext));
if (component_extension) {
const name = file.slice(0, -component_extension.length);
const pattern = /^\+(?:(page(?:@([a-zA-Z0-9_-]*))?)|(layout(?:@([a-zA-Z0-9_-]*))?)|(error))$/;
const pattern = /^\+(?:(page(?:@(.*))?)|(layout(?:@(.*))?)|(error))$/;
const match = pattern.exec(name);
if (!match) {
// TODO remove for 1.0
Expand Down
13 changes: 11 additions & 2 deletions packages/kit/src/core/sync/create_manifest_data/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,11 @@ test('creates routes with named layouts', () => {
{ component: 'samples/named-layouts/b/c/c2/+page@.svelte', parent_id: '' }, // 11
{ component: 'samples/named-layouts/b/d/(special)/+page.svelte' }, // 12
{ component: 'samples/named-layouts/b/d/(special)/(extraspecial)/d2/+page.svelte' }, // 13
{ component: 'samples/named-layouts/b/d/d1/+page.svelte' } // 14
{
component: 'samples/named-layouts/b/d/(special)/(extraspecial)/d3/+page@(special).svelte',
parent_id: '(special)'
}, // 14
{ component: 'samples/named-layouts/b/d/d1/+page.svelte' } // 15
]);

assert.equal(routes.filter((route) => route.page).map(simplify_route), [
Expand All @@ -521,7 +525,7 @@ test('creates routes with named layouts', () => {
{
id: 'b/d/d1',
pattern: '/^/b/d/d1/?$/',
page: { layouts: [0], errors: [1], leaf: 14 }
page: { layouts: [0], errors: [1], leaf: 15 }
},
{
id: '(special)/(alsospecial)/b/c/c1',
Expand All @@ -532,6 +536,11 @@ test('creates routes with named layouts', () => {
id: 'b/d/(special)/(extraspecial)/d2',
pattern: '/^/b/d/d2/?$/',
page: { layouts: [0, 6, 7], errors: [1, undefined, undefined], leaf: 13 }
},
{
id: 'b/d/(special)/(extraspecial)/d3',
pattern: '/^/b/d/d3/?$/',
page: { layouts: [0, 6], errors: [1, undefined], leaf: 14 }
}
]);
});
Expand Down