feat: automatically track changes to `head` within `useFetch`
See original GitHub issue🐛 The bug
When you edit the meta in the useFetch
, once the page is loaded the metas are erased.
Note: all the metas are in place when you look at the code generated from the SSR
🛠️ To reproduce Here is the sandbox https://codesandbox.io/s/cool-glitter-ykhpv
You can have a look in the pages/posts/_id.vue
to see how the metas are set. I believe we can write the code like that, but please let me know if I made a mistake.
Note: the title
is initialized in the nuxt.config.js
When you load a page from a post (better to test in a new window and not in the sandbox UI), you can first see that the title is right, but when the page is loaded the title goes back to Test
.
If you look at the source generated from the SSR everything is in place, but if you inspect the code once the page is loaded you can see that the meta twitter:title
is missing for example.
Also, if you go from the homepage to a post (so without reloading the entire website), you can see that the title is right.
🌈 Expected behaviour The metas are kept once the page is loaded
Thank you
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (2 by maintainers)
I tried to run code with your suggestion but still can’t get data from API and set it to meta. it doesn’t seem to run sequentially. Please help
@nicolashmln This is not a bug; just make sure you don’t set the metadata within
useFetch
. However, I agree it could be nice if that worked as you have it and I’ll consider adding that as a feature. For now, I would avoid setting your meta withinuseFetch
and instead do something more like this: