Cannot read properties of null (reading 'insertBefore')
Hello guys, i have a problem with a site, locally it works fine but in production when i try to access a dynamic content that is fetched from an API like this url here (https://jumisluxury.mk/categories/6-sofas) i get this error
TypeError: Cannot read properties of null (reading 'insertBefore')
at insert (Bg-j_vi9.js:23:178)
at y (Bg-j_vi9.js:19:35157)
at C (Bg-j_vi9.js:19:34790)
at F (Bg-j_vi9.js:19:37217)
at A (Bg-j_vi9.js:19:36586)
at v (Bg-j_vi9.js:19:35509)
at C (Bg-j_vi9.js:19:34888)
at Oi.$ [as fn] (Bg-j_vi9.js:19:38710)
at Oi.run (Bg-j_vi9.js:15:1517)
at G.d.update (Bg-j_vi9.js:19:39416)
if i access this url with navigating from a button it works
any suggestions?
Jumis Luxury
Почетна
Jumis Luxury е водечки производител на мебел, кои нуди целосни ентериерни уредувања, од 3D визуелизација на проекти до целосно производство на мебел по мерка.
35 Replies
i build the website using
pnpm generate
.to me that looks like a hydration error
is there a way to solve it?
and what does that mean?
here is the full component from that route
ah, in the code I already see a few things
like that you don't use useFetch or useAsyncData
i will watch the full video right away.
so instead of $fetch i need useFetch?
"it depends" 🙂
The docs should explain in which scenario you should use which
Alexander Lichter
YouTube
You are using useFetch WRONG! (I hope you don't)
💪🏻 useFetch is a mighty composable to fetch data in your Nuxt.js application. It can do so many things, from updating state to refreshing calls easily and even data caching is possible. But often I see that people misuse useFetch because it is so tempting to use all the features, even when you shouldn't. In this video I show the most common mist...
will watch this as well
and one more thing, since i want the useSeoMeta to be added from the api call data, is the way i'm doing correct or wrong?
since when i send for example a link i do not see the meta from the server, but the default meta.
it'll be easier + more clear with useFetch 🙂
it should be also correct on the server then
did not understand this last one
i'm using Laravel Server and the frontend is built with
pnpm generate
does this mean something or not?server as in "during generation"
if you use static site generation
I just watched this whole video and it looks great, but the problem is that i do not get why is my way of doing it with $fetch wrong? in my case i only want to solve the problem that is caused when you refresh a component that loads data from a server.
And the error i get is nothing like the errors that are explained in the first video, so i'm a bit confused what should i do to solve it.
The problem is that when navigating to the page the data from fetch is not there - error. And your code is not made either 1. wait for data, not throw error or 2. Fetch data and save it during generate so it doesn't have to be downloaded again
can you give me advice on how to solve it?
how can i make it to wait for data?
any help would be appreciated.
so, do you want to have the data available in the HTML you generate?
yes, i would like to use the current setup with pnpm generate while i escape this error that i get on refreshing the page where the dynamic route is fetched
for example something like this, how i should rewrite it in order to be working fine.
and should i put
ssr: false
if i use pnpm generate to have a SSG site?no
unless you want an SPA
if you need SEO you should not disable SSR
aham, yes indeed
the problem with SSG is that your data (relevant for SEO) will always be "outdated"
and fixed to the point of building
even if you load/refresh them on the client
so in order to have a better SEO i need SSR instead of SSG to get the dynamic data as the SEO meta data?
btw the problem when i disable ssr: false is now gone that i explained above, if that means something
yes, that's correct because you don't have any hydration anymore 🙂
static data + SEO = SSG
dynamic data + SEO = SSR
no SEO needed = SPA
Perfect explained, thank you so much.
that's the basic decision tree IMO
you are welcome!
also have a listen/look into https://share.transistor.fm/s/90ce0fd6
Michael and I discuss that there a bit more
also how can i rewrite this with useFetch in order to fix the issue?
or is using useFetch not going to solve my problem now?
try sth like this
thank you let me check
untested 🙂
but you get the idea
yes sure, sorry for bothering you
np 👍