Skip to content

Commit

Permalink
throw error for recursive layout (#4730)
Browse files Browse the repository at this point in the history
* throw error for recursive layout

* Create ten-apricots-admire.md

Co-authored-by: Rich Harris <[email protected]>
  • Loading branch information
tanhauhau and Rich-Harris authored Apr 25, 2022
1 parent 085f3a1 commit b05ebf4
Show file tree
Hide file tree
Showing 11 changed files with 25 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/ten-apricots-admire.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@sveltejs/kit": patch
---

throw error on encountering infinite layout loop
4 changes: 4 additions & 0 deletions packages/kit/src/core/sync/create_manifest_data/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,10 @@ function trace(file, path, tree, extensions) {
const node = tree.get(parts.join('/'));
const layout = node?.layouts[layout_id];

if (layout?.file && layouts.indexOf(layout.file) > -1) {
throw new Error(`Recursive layout detected: ${layout.file} -> ${layouts.join(' -> ')}`);
}

// any segment that has neither a __layout nor an __error can be discarded.
// in other words these...
// layouts: [a, , b, c]
Expand Down
16 changes: 16 additions & 0 deletions packages/kit/src/core/sync/create_manifest_data/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,22 @@ test('errors on duplicate layout definition', () => {
);
});

test.only('errors on recursive name layout', () => {
assert.throws(
() => create('samples/named-layout-recursive-1'),
/Recursive layout detected: samples\/named-layout-recursive-1\/__layout-a@b\.svelte -> samples\/named-layout-recursive-1\/__layout-b@a\.svelte -> samples\/named-layout-recursive-1\/__layout-a@b\.svelte/
);
assert.throws(
() => create('samples/named-layout-recursive-2'),
/Recursive layout detected: samples\/named-layout-recursive-2\/__layout-a@a\.svelte -> samples\/named-layout-recursive-2\/__layout-a@a\.svelte/
);

assert.throws(
() => create('samples/named-layout-recursive-3'),
/Recursive layout detected: samples\/named-layout-recursive-3\/__layout@a\.svelte -> samples\/named-layout-recursive-3\/__layout-a@default\.svelte -> samples\/named-layout-recursive-3\/__layout@a\.svelte/
);
});

test('allows for __tests__ directories', () => {
const { routes } = create('samples/legal-dunder');

Expand Down
Empty file.
Empty file.
Empty file.
Empty file.

0 comments on commit b05ebf4

Please sign in to comment.