Why do I get an error on refresh with dynamic content?
Hi,
I'm having a really big issue right now. When I refresh my page on localhost everything is working fine. But when I deploy my site to netlify my page gives the
Error.vue
page only on refresh.
https://uebler.netlify.app/ -> if you go to fietsendragers
in the menu. It all works. But if you refresh it triggers my Error.vue
page.
I don't have a single clue why ....
Can someone spot my bug?Homepagina - Uebler Benelux | Voor al uw fietsendragers
Uebler Benelux is de importeur van Uebler fietsendrager. Wij leveren fietsendragers voor autos, aanhangers, campers, caravans en bestelwagens.
68 Replies
I'm using Directus CMS
@Thijs could you provide a stackblitz or codesandbox π
@manniL / TheAlexLichter can it be this?
absolutely, yes
I googled the error
But can't find a fix
This is for sure a problem but there can be other issues "on top" too
The fix really depends on your project
These are the only warnings
^
What does it mean then?
Simple said
I summarized that here: https://blog.lichter.io/posts/vue-hydration-error/
blog.Lichter.io
What to do when Vue hydration fails
SSR is amazing but also comes with errors you might have not seen before. Especially one problem still boggles lots of minds: When Vue Hydration fails. In this article we will take a look at possible reasons, explain what the error means and how to fix it
I guess its because I render dynamic content in a v-for
But the strange thing is it only gets triggered on a refresh on live
Not when you're coming from another page @manniL / TheAlexLichter
What is the
Click on one of the hydrate calls.
?Over here @manniL / TheAlexLichter
This article was written for nuxt 2 so the debugging won't work 1:1
But the concept is the same
yep, that's also described in the article (and why)
@manniL / TheAlexLichter I already get a mismatch here
wtf
I have NO CLUEwhy
@Thijs middleware/plugins?
layouts/app.vue?
Had to restart my server
Happens a lot
@manniL / TheAlexLichter cache i guess?
@Thijs Which OS you use? Windows?
Yes
Which Nuxt version you run? That should be resolved since 3.2.2
GitHub
Server side not updating when in dev mode on Windows Β· Issue #18635...
Environment Operating System: Windows_NT Node Version: v18.12.1 Nuxt Version: 3.1.1 Nitro Version: 2.1.1 Package Manager: [email protected] Builder: vite User Config: - Runtime Modules: - Build Modules: -...
I think I fixed it.... @manniL / TheAlexLichter
Is this the way to go to fetch?
no, not really
you would rather do
const { data: page } = await useFetch('URL')
βΊοΈ
But for directus you can also use the nuxt directus module straight away
this is easier for now I'd sayHero
Thanks
@manniL / TheAlexLichter 1 last question
I want to update my
data: page
object when applying filters. But you can't because it isn't a ref.How would you tackle this?
Then you need to do something like this right?
promise.all π
page
is a ref though when using useFetch
Is it already a red?
So that should work
So you could overwrite
not overwrite, no
With just page.value =
you rather want to use a
computed
like const filteredEntries = computed(() => entries.value.filter(() => {...}))
Yeh
But the template needs to update
Now you have 2 refs.
Your way
Isn't it better to make a ref.
Fill that one on load
Then replace the
ref.value
with the new await call
?Not sure I understand your issue π€
The first ref from
useFetch
contains the "raw" data
the computed
ref contains the data you'll show
no filter = "all" of the data
filter = filtered dataIf I filter, I fetch again from Directus
So the
carriers.data
in my template. Needs to be replaced with the new carriers.data
from the new fetchOh, you would fetch again from directus on filter?
Yes
by passing new parameters?
YEs
Then you just need one ref indeed
but you better pass the params to
useFetch
so it can re-fetch whenever they changeHow would you trigger it then?
Say i have a Filter function
Which fetches again
Well, it depends how your call to the carriers api would look like. Right now they seemed independent
I want to refetch the
carriers
can you do carriers.refresh
then?but what has changed when you refetch?
you don't pass any query params/body or arguments to the call, right?
If I refetch I'll apply filters
So I add params
for example?
(right now, the calls shown above look independent)
The filters should be stored in a ref ideally. This ref is then passed to the
useFetch
as query/body/... (however it is required) or even as part of the URL.
useFetch
will refetch when the ref (URL, query params) changes.@manniL / TheAlexLichter here I would pass the filters
When I call the function.
yeah but you can't destructure a ref like that
make a computed out of the "standard" filter + the "variable ones"
and pass it as
params: { filter: myComputedFilter }
or so.
also, don't set carries.value
do const { data: carries }
setting ref's like you do there would be a one-off thingOkay fixed it like this:
But how can I say now when I press a button.
Refetch
my data: carriers
with given params?
Sorry never worked like this before so I don't understand the syntax yetThis is what I want @manniL / TheAlexLichter
no worries. it is more the mental modal π
So
initial fetch should not be for published only too?
Just an example
give me 1 more example and then I show you π
Changed it
π
Just think of it as a very basic implementation. Filters can be set as you like and be more sophisticated
So when you change the computed
It automatically refetches?
Because you trigger a
refetch function
nowhere?it will refetch because you pass it to
useFetch
before
and whenever the computed updates, useFetch
will do a refetch because it watches the computed internally
This is a common pattern for composables.Ah wow
Thanks ma
Appreciate it
Say I put this in a
/composable/fietsendragers.js
How can I load the content then in my /pages/fietsendragers/index.vue
?you would wrap it in a function and return the result. You also want to pass the filters as argument to the function