Skip to content

Commit 236f96f

Browse files
authored
[feat] add fallback component for layouts without one (#7619)
Closes #5967
1 parent 41767a7 commit 236f96f

File tree

4 files changed

+16
-5
lines changed

4 files changed

+16
-5
lines changed

.changeset/purple-parrots-tell.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+
[feat] add fallback component for layouts without one

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,12 @@ function create_routes_and_nodes(cwd, config, fallback) {
258258
// and smaller indexes take fewer bytes. also, this guarantees that
259259
// the default error/layout are 0/1
260260
for (const route of routes) {
261-
if (route.layout) nodes.push(route.layout);
261+
if (route.layout) {
262+
if (!route.layout?.component) {
263+
route.layout.component = posixify(path.relative(cwd, `${fallback}/layout.svelte`));
264+
}
265+
nodes.push(route.layout);
266+
}
262267
if (route.error) nodes.push(route.error);
263268
}
264269

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -635,6 +635,7 @@ test('handles pages without .svelte file', () => {
635635
default_error,
636636
{ component: 'samples/page-without-svelte-file/error/+error.svelte' },
637637
{ component: 'samples/page-without-svelte-file/layout/+layout.svelte' },
638+
{ ...default_layout, shared: 'samples/page-without-svelte-file/layout/exists/+layout.js' },
638639
{ component: 'samples/page-without-svelte-file/+page.svelte' },
639640
{ shared: 'samples/page-without-svelte-file/error/[...path]/+page.js' },
640641
{ component: 'samples/page-without-svelte-file/layout/exists/+page.svelte' },
@@ -645,7 +646,7 @@ test('handles pages without .svelte file', () => {
645646
{
646647
id: '/',
647648
pattern: '/^/$/',
648-
page: { layouts: [0], errors: [1], leaf: 4 }
649+
page: { layouts: [0], errors: [1], leaf: 5 }
649650
},
650651
{
651652
id: '/error',
@@ -654,7 +655,7 @@ test('handles pages without .svelte file', () => {
654655
{
655656
id: '/error/[...path]',
656657
pattern: '/^/error(?:/(.*))?/?$/',
657-
page: { layouts: [0, undefined], errors: [1, 2], leaf: 5 }
658+
page: { layouts: [0, undefined], errors: [1, 2], leaf: 6 }
658659
},
659660
{
660661
id: '/layout',
@@ -663,12 +664,12 @@ test('handles pages without .svelte file', () => {
663664
{
664665
id: '/layout/exists',
665666
pattern: '/^/layout/exists/?$/',
666-
page: { layouts: [0, 3], errors: [1, undefined], leaf: 6 }
667+
page: { layouts: [0, 3, 4], errors: [1, undefined, undefined], leaf: 7 }
667668
},
668669
{
669670
id: '/layout/redirect',
670671
pattern: '/^/layout/redirect/?$/',
671-
page: { layouts: [0, 3], errors: [1, undefined], leaf: 7 }
672+
page: { layouts: [0, 3], errors: [1, undefined], leaf: 8 }
672673
}
673674
]);
674675
});

packages/kit/src/core/sync/create_manifest_data/test/samples/page-without-svelte-file/layout/exists/+layout.js

Whitespace-only changes.

0 commit comments

Comments
 (0)