frontend-boilerplate icon indicating copy to clipboard operation
frontend-boilerplate copied to clipboard

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

Open DaveBitter opened this issue 5 years ago • 2 comments

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.

DaveBitter avatar Mar 01 '19 13:03 DaveBitter

Nice catch, I'll check it out.

colin-aarts avatar Mar 01 '19 16:03 colin-aarts

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 ?

colin-aarts avatar Mar 05 '19 09:03 colin-aarts