nuxt-modules / og-image

Generate OG Images with Vue templates in Nuxt.
https://nuxtseo.com/og-image
361 stars 23 forks source link

Not receiving default params on larger projects(race condition maybe?) #135

Closed jpengelbrecht closed 5 months ago

jpengelbrecht commented 5 months ago

Describe the bug

So i noticed that in larger projects a lot of the OG-image fails to receive default params from the meta fields on the project becomes larger. I imagine this is some sort of race condition where it isnt actaully done writing those files yet as every file after that initial breakage seems to work. This is just a guess, i tried reproducing this on smaller projects, but i think this only fails on large projects.

image

i guess my question is, is there a way we can write the images only after the pre-render is done? or somehow trigger it slightly later on the build?

also as a side note, this is a project that is currently behaving as expected on nuxt seokit 1.3.13 this seems to only be a bug when doing the upgrade

Reproduction

No response

System / Nuxt Info

------------------------------
- Operating System: Darwin
- Node Version:     v18.10.0
- Nuxt Version:     3.9.0
- CLI Version:      3.10.0
- Nitro Version:    2.8.1
- Package Manager:  npm@8.19.2
- Builder:          -
- User Config:      modules, site, linkChecker, css, turnstile, robots, ogImage, head, routeRules, typescript, sourcemap, devServer, devtools, htmlValidator, image, runtimeConfig, schemaOrg, nitro, appConfig, ignore, hooks, vite
- Runtime Modules:  @nuxt/devtools@1.0.6, @pinia/nuxt@0.4.11, @nuxt/content@2.7.2, @vueuse/motion/nuxt@2.0.0, nuxt-calendly@0.1.14, vue3-carousel-nuxt@1.1.0, @nuxtjs/turnstile@0.6.3, @nuxtjs/tailwindcss@6.8.0, @nuxtseo/module@2.0.0-beta.55, @nuxt/image@1.0.0
- Build Modules:    -
------------------------------
harlan-zw commented 5 months ago

Hi, thanks for the issue.

Would you mind elaborating on what you mean by this exactly

fails to receive default params from the meta fields

Are you saying the title/description isn't coming through from the useHead title and meta description?

Can you share some code either way just as a sanity check?

I can't imagine that this would be a race condition issue as the the og image routes are only registered when the route using it is prerendered. The logic for prerendering works a bit differently though, as we cache all of the payloads where possible to avoid extra prerender time. Might be related to this.

jpengelbrecht commented 5 months ago

@harlan-zw yea so basically the by default params the title and description is empty even though they are set with useHead().

out of the 300+ routes, the only ones that suffer from this is that first batch of OG images, every single of them have no parms and after that first batch every single one works. If i move those exact files with those exact same file structure to smaller projects to replicate this, it works all of a sudden. So the fact that this only happens on larger projects and the fact that it only happens to the first one, makes it seem that something is starting something a tiny bit to early.

As for "I can't imagine that this would be a race condition issue as the the og image routes are only registered when the route using it is prerendered. " this is true, if i look at the logs i can confirm the routes return that is has been pre-rendered successfully before OG image starts.

As for the reproduction i will continue to try get one for you that i can share, but at the moment iv been struggling to replicated it on smaller projects as i said i think size and complexity might be adding that extra lag that is causing the first batch to break

harlan-zw commented 5 months ago

Thanks for the extra details. Will attempt to make a reproduction myself, are you using any special nitro configuration?

jpengelbrecht commented 5 months ago

na its all vanilla base settings.

harlan-zw commented 5 months ago

I tried to replicate this by generating 300 routes all inheriting metadata for the og image and they all seem to work.

...Array.from({ length: 300 }, (_, i) => {
          return `/post/${i}`
        }),

Not really sure what else I can do on my end to help :thinking:

jpengelbrecht commented 5 months ago

ok @harlan-zw I figured it out. it seems this bug was caused by having a layout conditionally render the slot for the content. honestly I think this issue was on my side and works as expected. The reason it only broke for that subset was because this issue was on my default layout, and that's why I also couldn't break it on the other projects. Sorry for the bother