fastify / point-of-view

Template rendering plugin for Fastify
MIT License
338 stars 86 forks source link

Nunjucks templates do not dynamically reload in development #362

Closed autonordev closed 1 year ago

autonordev commented 1 year ago

Prerequisites

Fastify version

4.11.0

Plugin version

7.4.0

Node.js version

18.12.1

Operating system

Windows

Operating system version (i.e. 20.04, 11.3, 10)

10 (21H2)

Description

During development, it's expected that templates reload every page request. This means that if the file content has changed since the process begun, the changes would be present on the next page load.

However, it appears that -- at least when using Nunjucks -- this is not occurring, and a reload of the process is needed in order to cause changes to start appearing.

Steps to Reproduce

app.register(require('@fastify/view'), {
    engine: {
      nunjucks: require('nunjucks'),
    },
    templates: [ ... ],
    production: app.config.NODE_ENV === 'production', // false
  })

I've checked and do not have any type of caching plugin running on the project, also any types of changes to locals/data work; it's just the template file where the issue lies.

trim21 commented 1 year ago

haveyou try disable cache by setting maxCache and also use noCache option of nunjucks (use .options ) in development?

const production = app.config.NODE_ENV === 'production' // false
app.register(require('@fastify/point-of-view'), {
    engine: {
      nunjucks: require('nunjucks'),
    },
    templates: [ ... ],
    production,
    options: {
        noCache: !production,
    }, 
  })

(maybe we should make this default behavior)

quiquelhappy commented 1 year ago

I use this setup and it works fine, so unless there is anything else to add, this issue could be closed

Fdawgs commented 1 year ago

Did you manage to solve this @autonordev?

autonordev commented 1 year ago

Hi, sorry for the inactivity here. Happy to confirm that I was able to solve this issue using the instructions provided by trim21.