webdiscus / html-bundler-webpack-plugin

Alternative to html-webpack-plugin ✅ Renders Eta, EJS, Handlebars, Nunjucks, Pug, Twig templates "out of the box" ✅ Resolves source files of scripts, styles, images in HTML ✅ Uses a template as entry point
ISC License
138 stars 14 forks source link

new eta template function only works if some data is specified in loaderOptions #60

Closed Kiirani closed 9 months ago

Kiirani commented 9 months ago

Current behaviour

If you create a partial eta template and import it into js without configuring any data in loaderOptions, an exception is thrown because __data__ is null, and the template doesn't work.

Uncaught TypeError: can't convert null to object
    templateFn file://///wsl$/Debian/home/kiirani/code/tmp/hbwp-template-repro/dist/app.js:30
    updatePage file://///wsl$/Debian/home/kiirani/code/tmp/hbwp-template-repro/dist/app.js:131
    <anonymous> file://///wsl$/Debian/home/kiirani/code/tmp/hbwp-template-repro/dist/app.js:126
    EventListener.handleEvent* file://///wsl$/Debian/home/kiirani/code/tmp/hbwp-template-repro/dist/app.js:125
    <anonymous> file://///wsl$/Debian/home/kiirani/code/tmp/hbwp-template-repro/dist/app.js:134
    <anonymous> file://///wsl$/Debian/home/kiirani/code/tmp/hbwp-template-repro/dist/app.js:136

Expected behaviour

The template should work without requiring developers to pass data in through the preprocessor config.

Reproduction Example

https://github.com/Kiirani/hbwp-template-repro

Environment

Additional context

The test case for this feature (https://github.com/webdiscus/html-bundler-webpack-plugin/tree/master/test/cases/js-tmpl-eta-compile) tests multiple methods of passing data, including through through the config - that's actually how I figured out why it wasn't working....

... possibly splitting that case into separate tests for each data passing mechanism would have caught this? I'm not very familiar with the tooling involved here.

it also might be worth looking at whether this is a problem with the other templating engines

webdiscus commented 9 months ago

Hello @Kiirani,

thank you for the issue report. I will fix it.

webdiscus commented 9 months ago

@Kiirani

the issue is fixed in the version 3.4.2. Can you please test your code with new version? Thank you!

Kiirani commented 9 months ago

Yes, it works now, thank you!