frontend-boilerplate
frontend-boilerplate copied to clipboard
NJK crashes if component name is the same as the template name
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:
- create a example template in
templates/example/example.njk
- create a example component in
components/example/example.njk
- load the example component in the example template file using the component plugin.
Nice catch, I'll check it out.
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 ?