mirabeau-nl / frontend-boilerplate

An opinionated blueprint environment to quick start new front-end codebases
https://www.mirabeau.nl/
BSD 3-Clause "New" or "Revised" License
68 stars 30 forks source link

NJK crashes if component name is the same as the template name #99

Open DaveBitter opened 5 years ago

DaveBitter commented 5 years ago

The build process of NJK crashes if the component name is the same as the template name while using the component plugin.

Steps to reproduce:

  1. create a example template in templates/example/example.njk
  2. create a example component in components/example/example.njk
  3. load the example component in the example template file using the component plugin.
colin-aarts commented 5 years ago

Nice catch, I'll check it out.

colin-aarts commented 5 years ago

It has to do with the fact that we configure multiple "entry points" in the nunjucks render call (for layouts, templates and components; html.js L29-31). It seems to try them in the specified order, which happens to have templates before components. It then finds a matching template with the same path as the component, causing an infinite loop and then a call stack overflow.

I've tried to be explicit in passing the full path to the {% component %} tag's render call, but it won't accept it. It seems like it needs to be relative to one of the previously provided entry points.

Quick fix for this scenario would be to switch the order of the templates and components entry point listing (tested; works) but I'm not sure if that won't cause other issues.

Thoughts, @mirabeau-nl/front-end-developers ?