https://github.com/pju-/nuxt-generate-bugreport
When using the very basic repo I've provided:
After install, run npm run generate
What the repo does:
/index
|-- _id.vue
|-- index.vue
index.vue
Then run npm run generate
The index route (/) should be rendered normally.
The resulting html should be a static representation of the page.
Expected console output:
✔ Generated /page
✔ Generated /
The / route is rendered, but also a route with an empty name is rendered.
Console output:
✔ Generated /page
✔ Generated /
✔ Generated
Depending on if / or the empty route is rendered last, the resulting html is a mess:
If / is rendered last, everything is fine.
If the empty route is rendered last, the html is a mess (content not injected, script tag wrong).
For /page, everything works as expected.
I'm experiencing a very similar issue (probably from the same cause) and have taken some hours to investigate.
I've written down what I have found out so far in the readme of this minimal reproduction repository: Loilo/repro-nuxt-generate-slicing.
@Loilo That seems to be the same issue indeed. If you check the log output from generate, it is creating a route with empty name.
The reason why you are sometimes getting the right output is probably because the generation is async, so the correct route is produced after the empty one. In that case, the resulting index.html is overwritten and everything looks as it should.
Oh. So it's race conditions all the way down.
Thanks for your contribution to Nuxt.js!
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.
If you would like this issue to remain open:
Issues that are labeled as 🕐Pending will not be automatically marked as stale.
I am experimenting the same issue! It took me two days to find the issue... I was beginning to think I was crazy :D
When I read it might be a race condition issue, I found a quick fix by setting the generate concurrency setting to 1 and now the generated index.html is ok.
module.exports = {
mode: 'universal',
generate: {
concurrency: 1,
},
};
I think it's a major bug!
Actually, it was not fixed with the concurrency hack, I think I fixed the bug by removing the dummy route in the 'generate:extendRoutes' hook:
hooks: {
generate: {
// Fix for race condition bug with the generated route '/' and ''
// @see: https://github.com/nuxt/nuxt.js/issues/4982
extendRoutes(generatedRoutes) {
const index = generatedRoutes.findIndex(({ route }) => route === '');
generatedRoutes.splice(index, 1);
},
},
},
Nice workaround, @davidbillamboz. Can confirm that this works for my repro as well. 👍
Thanks for your contribution to Nuxt.js!
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.
If you would like this issue to remain open:
Issues that are labeled as 🕐Pending will not be automatically marked as stale.
Still reproducible with the reproduction repository.
I still have this issue in [email protected]. Setting the generate.exclude option to [''] fixed the issue.
Most helpful comment
Actually, it was not fixed with the concurrency hack, I think I fixed the bug by removing the dummy route in the 'generate:extendRoutes' hook: