Skip to content

Commit

Permalink
layout resets - closes #626
Browse files Browse the repository at this point in the history
  • Loading branch information
Rich-Harris committed Apr 17, 2021
1 parent 197860f commit 6d4482f
Show file tree
Hide file tree
Showing 10 changed files with 51 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .changeset/modern-donkeys-invite.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/kit': patch
---

Implement layout resets
3 changes: 0 additions & 3 deletions packages/kit/src/core/build/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -340,9 +340,6 @@ async function build_server(
const metadata_lookup = ${s(metadata_lookup)};
async function load_component(file) {
if (!module_lookup[file]) {
console.log({ file });
}
return {
module: await module_lookup[file](),
...metadata_lookup[file]
Expand Down
10 changes: 8 additions & 2 deletions packages/kit/src/core/create_manifest_data/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,18 +140,24 @@ export default function create_manifest_data({ config, output, cwd = process.cwd
params.push(...item.parts.filter((p) => p.dynamic).map((p) => p.content));

if (item.is_dir) {
const layout_reset = find_layout('$layout.reset', item.file);
const layout = find_layout('$layout', item.file);
const error = find_layout('$error', item.file);

if (layout_reset && layout) {
throw new Error(`Cannot have $layout next to $layout.reset: ${layout_reset}`);
}

if (layout_reset) components.push(layout_reset);
if (layout) components.push(layout);
if (error) components.push(error);

walk(
path.join(dir, item.basename),
segments,
params,
layout_stack.concat(layout),
error_stack.concat(error)
layout_reset ? [layout_reset] : layout_stack.concat(layout),
layout_reset ? [error] : error_stack.concat(error)
);
} else if (item.is_page) {
components.push(item.file);
Expand Down
38 changes: 38 additions & 0 deletions packages/kit/src/core/create_manifest_data/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -357,4 +357,42 @@ test('includes nested error components', () => {
]);
});

test('resets layout', () => {
const { routes } = create('samples/layout-reset');

assert.equal(routes, [
{
type: 'page',
pattern: /^\/$/,
params: [],
path: '/',
a: [layout, 'samples/layout-reset/index.svelte'],
b: [error]
},
{
type: 'page',
pattern: /^\/foo\/?$/,
params: [],
path: '/foo',
a: [
layout,
'samples/layout-reset/foo/$layout.svelte',
'samples/layout-reset/foo/index.svelte'
],
b: [error]
},
{
type: 'page',
pattern: /^\/foo\/bar\/?$/,
params: [],
path: '/foo/bar',
a: [
'samples/layout-reset/foo/bar/$layout.reset.svelte',
'samples/layout-reset/foo/bar/index.svelte'
],
b: ['samples/layout-reset/foo/bar/$error.svelte']
}
]);
});

test.run();
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.

0 comments on commit 6d4482f

Please sign in to comment.