Double run on generate

scottsweb
16
scottsweb
commented a year ago

Version

0.1.1

Reproduction link

https://github.com/nuxt-community/sitemap-module

Steps to reproduce

Create a new routes section in your nuxt.config.js file with a console.log statement like so:

  sitemap: {
    path: '/sitemap.xml',
    cacheTime: 1000 * 60 * 15,
    generate: true, 
    gzip: true,
    async routes() {
        console.log( '....routes()' )
                ...

What is expected ?

Only one log is output during generate.

What is actually happening?

Multiple log entries are output:

nuxt:generate Generating... +0ms ....routes() nuxt: Call build:before hooks (3) +0ms nuxt:pwa Adding icons +0ms nuxt:pwa Adding manifest +0ms nuxt:pwa Adding meta +0ms nuxt:build Generating files... +4ms nuxt:build Generating routes... +8ms ....routes()

Additional comments?

This is an issue because with a dynamically generated set of routes, the API gets hit twice for every request (as far as I can tell).

Using 1.4.0 of nuxt.

bug
0
scottsweb
16
scottsweb
commented a year ago

Looking at this some more, I think it would be best to trigger the sitemap generation on the generate:done hook as documented here: https://nuxtjs.org/api/internals-generator#hooks

This will allow people to generate routes (via an api) for the generate routes method in nuxt.config.js, cache the results and then pass the cache on to this sitemap module.

0
NicoPennec
1.4k
NicoPennec
commented a year ago

Hi Scott, thanks for your report. It's a known issue due to Nuxt <1.x limitation.

I'm working on a refactoring based on the new hooks from Nuxt >=1.x, so It's a breaking change.
It will be release very soon.

0
pSchaub
90
pSchaub
commented a year ago

@NicoPennec Any updates on this?

0
Informations
Bug Report โ€ข Open
#c25 - Created a year ago