primevue icon indicating copy to clipboard operation
primevue copied to clipboard

feat: uniqueId mixin

Open i7slegend opened this issue 1 year ago • 4 comments

Half-duplicate of #5486

#5486 not SSR-friendly (hydration warnings), so i could not find best way for Nuxt. This MR implements uniqueId mixin (with UniqueComponentId under hood). This mixin uses mounted hook for SSR (like it was before my requests) but for not-SSR calculate unique id before mount that remove redudant re-render (bcz id changes after mount and this trigger re-render for component and his children in the dom tree).

New file: components/lib/utils/UniqueIdMixinFactory.js (placed in primevue/utils). Nuxt is detect by this condition: typeof window === 'undefined' || (typeof process !== 'undefined' && Boolean(process.client || process.server));

i7slegend avatar Apr 11 '24 06:04 i7slegend

The latest updates on your projects. Learn more about Vercel for Git ↗︎

2 Ignored Deployments
Name Status Preview Comments Updated (UTC)
primevue ⬜️ Ignored (Inspect) Visit Preview Apr 11, 2024 0:27am
primevue-v4 ⬜️ Ignored (Inspect) Visit Preview Apr 11, 2024 0:27am

vercel[bot] avatar Apr 11 '24 06:04 vercel[bot]

Good job, @i7slegend! This is exactly what I wanted to do in v4. Currently, I'm working on v4.beta.2 release. I'll review this PR in more detail after beta.2.

mertsincan avatar Apr 19 '24 09:04 mertsincan

Many hydration issue in console. Thanks @i7slegend. Waiting for the merge :)

GhostvOne avatar Apr 21 '24 16:04 GhostvOne

https://github.com/i7slegend/primevue/commit/2fc05735774f0ad1a08be791054dcd9cf1812af6

I rewrote from mixin to composable, i bet it's best way to line with vue3 recommendations. Under SSR i not found any hydration warnings. As Vue library (only client, without ssr) i will test soon time, i think no problems there.

Btw nuxt (since 3.10) have useId built-in composable (https://nuxt.com/docs/api/composables/use-id), maybe should to support it in the SSR environment? But one cons - useId seems doesn't support reactive-based property

i7slegend avatar May 10 '24 14:05 i7slegend

Could you check the latest updates? If you think the problem still exists, please let us know. Closing due to conflicts.

Thanks for your contribution!

tugcekucukoglu avatar Aug 01 '24 11:08 tugcekucukoglu