Skip to content

[feat] add fallback component for layouts without one #7619

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 1 commit into from
Nov 11, 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/purple-parrots-tell.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/kit': patch
---

[feat] add fallback component for layouts without one
7 changes: 6 additions & 1 deletion packages/kit/src/core/sync/create_manifest_data/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,12 @@ function create_routes_and_nodes(cwd, config, fallback) {
// and smaller indexes take fewer bytes. also, this guarantees that
// the default error/layout are 0/1
for (const route of routes) {
if (route.layout) nodes.push(route.layout);
if (route.layout) {
if (!route.layout?.component) {
route.layout.component = posixify(path.relative(cwd, `${fallback}/layout.svelte`));
}
nodes.push(route.layout);
}
if (route.error) nodes.push(route.error);
}

Expand Down
9 changes: 5 additions & 4 deletions packages/kit/src/core/sync/create_manifest_data/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -635,6 +635,7 @@ test('handles pages without .svelte file', () => {
default_error,
{ component: 'samples/page-without-svelte-file/error/+error.svelte' },
{ component: 'samples/page-without-svelte-file/layout/+layout.svelte' },
{ ...default_layout, shared: 'samples/page-without-svelte-file/layout/exists/+layout.js' },
{ component: 'samples/page-without-svelte-file/+page.svelte' },
{ shared: 'samples/page-without-svelte-file/error/[...path]/+page.js' },
{ component: 'samples/page-without-svelte-file/layout/exists/+page.svelte' },
Expand All @@ -645,7 +646,7 @@ test('handles pages without .svelte file', () => {
{
id: '/',
pattern: '/^/$/',
page: { layouts: [0], errors: [1], leaf: 4 }
page: { layouts: [0], errors: [1], leaf: 5 }
},
{
id: '/error',
Expand All @@ -654,7 +655,7 @@ test('handles pages without .svelte file', () => {
{
id: '/error/[...path]',
pattern: '/^/error(?:/(.*))?/?$/',
page: { layouts: [0, undefined], errors: [1, 2], leaf: 5 }
page: { layouts: [0, undefined], errors: [1, 2], leaf: 6 }
},
{
id: '/layout',
Expand All @@ -663,12 +664,12 @@ test('handles pages without .svelte file', () => {
{
id: '/layout/exists',
pattern: '/^/layout/exists/?$/',
page: { layouts: [0, 3], errors: [1, undefined], leaf: 6 }
page: { layouts: [0, 3, 4], errors: [1, undefined, undefined], leaf: 7 }
},
{
id: '/layout/redirect',
pattern: '/^/layout/redirect/?$/',
page: { layouts: [0, 3], errors: [1, undefined], leaf: 7 }
page: { layouts: [0, 3], errors: [1, undefined], leaf: 8 }
}
]);
});
Expand Down