Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hydration mismatch error in production at Cloudflare/Netlify when using folder component prefixes #2853

Open
Givemeurcookies opened this issue Nov 19, 2024 · 0 comments
Labels
v2 Relevant for @nuxt/content v2

Comments

@Givemeurcookies
Copy link

Environment

Reproduction

Setup Nuxt project with Nuxt Content.

The components folder will have a content folder. If you create a new folder in the components folder, i.e a folder called layouts, create a new component and name it SideMenu.

In a page, use the component as LayoutSideMenu. This will work when you do dev, build and serve locally. But if you then use a CICD pipeline and push it to Cloudflare either through Wrangler (or by using Cloudflare's own build pipeline), the error Hydration mismatch error appears with no additional warning/error context. The same happens if you build with Netlify, I haven't tested other providers. If you upload the assets directly to Cloudflare without Wrangler, the error doesn't seem to occur.

I was able to reproduce it for a short while locally, but it seems like running the dev command once before building might do something that fixes it locally.

Describe the bug

It seems like Nuxt Content does something that breaks being able to use folders to automatically prefix components in Nuxt, but it only happens in production/some CDN providers. Meaning if you put your component in a folder and then use it as described in the reproduction section, it will cause a "hydration mismatch".

The workaround is to simply put components in the root of the components folder and instead prefix the name manually i.e LayoutSideMenu.vue instead of layout/SideMenu.vue. Using the presets for Cloudflare or Netlify will not help to fix this issue, neither will turning off optimisations (as recommended to fix hydration errors) for the respective providers.

Additional context

The following nuxt.config might be relevant to reproduce the issue:

components: {
    dirs: [
      {
        path: './components',
        ignore: ['**/*.ts'],
      },
    ],
  },

I originally based my project on the shadcn-docs project but have since modified it heavily. If reproducing the issue isn't straightforward, I can share more of the config.

Logs

@Givemeurcookies Givemeurcookies added the v2 Relevant for @nuxt/content v2 label Nov 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
v2 Relevant for @nuxt/content v2
Projects
None yet
Development

No branches or pull requests

1 participant