Skip to content

onServerPrefetch with useId cause hydration issue if treeshaken client-side #12591

Open
@huang-julien

Description

@huang-julien

Vue version

3.5.13

Link to minimal reproduction

https://stackblitz.com/edit/vue-ssr-example-bsqzmafk?file=app.js,client.js,server.js

Steps to reproduce

open your console and see there's a hydration mismatch.

Comp.vue's useId is not retturning the same value server side and client side

What is expected?

no hydration issue due to useId

What is actually happening?

The cause of this issue is that we run onServerPrefetch only server-side.

This happen in Nuxt because we treeshake onServerPrefetch in client-bundle and we also wrap onServerPrefetch with import.meta.server flag in useAsyncData composable.

In runtime, this results into the component being marked as async boudary only server side with markAsyncBoundary but not client side --> resulting to a hydration issue because useId returns different strings.

System Info

No response

Any additional comments?

Nuxt issue nuxt/nuxt#30289

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions