Skip to content
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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Layout chaining should check for recursion #1131

Closed
fhemberger opened this issue Apr 28, 2020 · 3 comments
Closed

Layout chaining should check for recursion #1131

fhemberger opened this issue Apr 28, 2020 · 3 comments

Comments

@fhemberger
Copy link

Describe the bug
I ran into a loop during build because I was carelessly using search & replace in my code. 馃槈

To Reproduce

  1. Create a layout page.njk with the frontend matter

    ---
    layout: page.njk
    ---
  2. Create a page using this layout

  3. Run npx eleventy

Eleventy seemed to be happy to oblige and I just noticed my mistake because the build seemed to run forever. (I didn't wait for a memory issue to occur.)

Expected behavior
Either:

  • Eleventy should detect accidental layout recursion and stop the build immediately with an error message.

Or:

  • Eleventy should issue a performance warning after the n-th nested layout (n=10?) in general
  • Eleventy should stop the build with an error message after the n-th nested layout (n=?)

Environment:

  • OS and Version: macOS 10.15.4
  • Eleventy Version: 0.10.0
@Ryuno-Ki
Copy link
Contributor

Ryuno-Ki commented May 3, 2020

I find the OR variant easier to realise technical (less bookkeeping). There are examples in the wild for it, e.g. preventing fork bombs.

@fhemberger
Copy link
Author

Hmm, I'd rather say the first variant is easier to implement:

Have an array layouts, and whenever you process frontend matter with layout: ..., check if the layout is already in the layouts array stop immediately, otherwise store the layout name in the array.

And if you produce a loop within the template using the template language's include mechanisms, this should be handled by the template language parser itself.

@zachleat
Copy link
Member

zachleat commented Dec 5, 2022

This was fixed with #2076 and is available on 2.0

@zachleat zachleat closed this as completed Dec 5, 2022
@zachleat zachleat added this to the Eleventy 2.0.0 milestone Dec 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants