Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nunjucks templates do not dynamically reload in development #362

Closed
2 tasks done
autonordev opened this issue Jan 18, 2023 · 4 comments
Closed
2 tasks done

Nunjucks templates do not dynamically reload in development #362

autonordev opened this issue Jan 18, 2023 · 4 comments

Comments

@autonordev
Copy link

autonordev commented Jan 18, 2023

Prerequisites

  • I have written a descriptive issue title
  • I have searched existing issues to ensure the bug has not already been reported

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
Copy link

trim21 commented Jan 20, 2023

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
Copy link

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

@Fdawgs
Copy link
Member

Fdawgs commented Jun 3, 2023

Did you manage to solve this @autonordev?

@autonordev
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants