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

Fix SSR hydration mismatches caused by createId function #1521

Closed
2 tasks done
markbrockhoff opened this issue Jul 5, 2024 · 4 comments
Closed
2 tasks done

Fix SSR hydration mismatches caused by createId function #1521

markbrockhoff opened this issue Jul 5, 2024 · 4 comments
Assignees
Labels
bug Something isn't working or not shown correctly dependencies Pull requests that update a dependency file dev Requires technical expertise

Comments

@markbrockhoff
Copy link
Member

markbrockhoff commented Jul 5, 2024

This bug is intended to work as a "TODO" to fix this issue once vue 3.5 is out.

Version

1.0.0-beta.0

Description

Some of the onyx components cause hydration mismatches when using server side rendering.
This is caused by the ids generated to e.g. link labels or other aria attributes. At the moment the ids for that are generated using a global counter variable stored inside a IIFE (see packages/headless/src/utils/id.ts). Using a global counter causes issues during SSR as the state of the counter will be preserved on the server across requests while being reset on the client:

image

The easiest solution to the problem would probably be to wait vor vue 3.5 which should include a new composable called useId(). This composable creates SSR safe unique ids for such usecases. (There is a discussion in progress regarding this issue: vuejs/rfcs#557)

Reproduction steps

Use a SSR framework like e.g. Nuxt Js to render Onyx components on the server and hydrate them on the client.

Confirmations

  • I have checked that there is not already a bug report for my issue.
  • I confirm that are no sensitive information included in this bug report. e.g. credentials, internal project details (for employees of the Schwarz Group) etc.
@markbrockhoff markbrockhoff added the bug Something isn't working or not shown correctly label Jul 5, 2024
@mj-hof mj-hof added the dev Requires technical expertise label Jul 29, 2024
@JoCa96
Copy link
Contributor

JoCa96 commented Jul 29, 2024

We will wait for release of 3.5: vuejs/core#11404

@mj-hof mj-hof added this to the Product improvements milestone Aug 2, 2024
@mj-hof mj-hof added the dependencies Pull requests that update a dependency file label Aug 14, 2024
@markbrockhoff
Copy link
Member Author

Vue 3.5 is finally out including the new useId composable. So this is no longer blocked ;)

@larsrickert
Copy link
Collaborator

Vue 3.5 is finally out including the new useId composable. So this is no longer blocked ;)

I already created a PR (#1844) but unfortunately there is currently a Storybook blocker that we need to wait for before we are able to release the update/fix to Vue 3.5, see #1844 (comment)

@JoCa96 JoCa96 changed the title [Bug]: SSR hydration mismatches caused by createId function Fix SSR hydration mismatches caused by createId function Sep 11, 2024
larsrickert added a commit that referenced this issue Sep 13, 2024
…e components (#1844)

Relates to #1521

Support SSR for OnyxSelect, OnyxNavButton, OnyxUserMenu and more
components by:

- update to Vue 3.5
- replace custom `createId()` with Vue's new `useId()` which is SSR
compatible
- a few other SSR fixes
- also fixes the missing JSDoc for properties (see #1498)
@larsrickert
Copy link
Collaborator

@markbrockhoff The issue is fixed now with onyx version 1.0.0-beta.42 👍🏼

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working or not shown correctly dependencies Pull requests that update a dependency file dev Requires technical expertise
Projects
Status: Done
Development

No branches or pull requests

4 participants