Comments (13)
We need the ability to v-bind attrs to the root element as useId
needs to access them when it hydrates.
from nuxt.
Same here 👍
<script lang="ts" setup>
// ...
const uniqueIdentifier = useId();
// ...
</script>
<template>
<input
:id="uniqueIdentifier"
v-model="field"
v-bind="$attrs"
/>
</template>
<style scoped></style>
This workaround helped, ofc as temp solution
const uniqueIdentifier = useId().replace(':', '_');
from nuxt.
@gregdev00 no, see #26315
from nuxt.
I believe it's because of how the useId composable was implemented, it had different separators. It is fixed in this commit.
from nuxt.
I'm still getting this error in various components (not all):
- rendered on server: id="nnOfIU4QIk8-0"
- expected on client: id="nnOfIU4QIk8_0"
There still seem to be cases, where a different seperator character is used (-
vs _
).
I think it happens in dynamically loaded components.
useId().replace('_', '-')
is a workaround then.
from nuxt.
Would you be able to provide a reproduction? 🙏
More info
Why do I need to provide a reproduction?
Reproductions make it possible for us to triage and fix issues quickly with a relatively small team. It helps us discover the source of the problem, and also can reveal assumptions you or we might be making.
What will happen?
If you've provided a reproduction, we'll remove the label and try to reproduce the issue. If we can, we'll mark it as a bug and prioritize it based on its severity and how many people we think it might affect.
If needs reproduction
labeled issues don't receive any substantial activity (e.g., new comments featuring a reproduction link), we'll close them. That's not because we don't care! At any point, feel free to comment with a reproduction and we'll reopen it.
How can I create a reproduction?
We have a couple of templates for starting with a minimal reproduction:
👉 https://stackblitz.com/github/nuxt/starter/tree/v3-stackblitz
👉 https://codesandbox.io/s/github/nuxt/starter/v3-codesandbox
A public GitHub repository is also perfect. 👌
Please ensure that the reproduction is as minimal as possible. See more details in our guide.
You might also find these other articles interesting and/or helpful:
from nuxt.
I've had that in my project when using client-only and fallback inside of it (needed to render empty input). Fixed by removing client-only and by relying on hydration end.
from nuxt.
I have a reproduction link here, with @manchenkoff's suggestion:
https://stackblitz.com/edit/github-rq89e8?file=app.vue,components%2FTestId.vue
This way you don't get the hydration mismatch warning, but you still get the warning added here
[nuxt] `useId` is not compatible with components that have `inheritAttrs: false`.
@manniL, @danielroe are there any plans to support inheritAttrs: false
in the future?
from nuxt.
We need the ability to v-bind attrs to the root element as
useId
needs to access them when it hydrates.
Why do you need them on the root element?
It's not uncommon to have custom form elements that have a wrapper div with input/label nested inside where you need the attrs to be bound to the input.
And even then, the attributes are still available (just not on the root element), no?
from nuxt.
Why do you need them on the root element?
It is because of the mechanics of how we ensure a stable ID that matches between server and client. Of course there are other locations they could be stored, but how can the composable 'know' where to access them?
from nuxt.
how can the composable 'know' where to access them?
maybe we can pass a ref
of the element we use it on as an optional argument to the composable ?
from nuxt.
It is still producing this issue as of nuxt 3.11.0, the problem is that the return statement at the bottom of the packages/nuxt/src/app/composables/id.ts file has a different separator than the one specified at the top in a constant
const SEPARATOR = '-'
.
.
.
// this line needs to be changed to use SEPARATOR instead of the hardcoded _ character
return key + '_' + nuxtApp._id++
@manniL can you fix this as well please?
from nuxt.
Can this be closed then?
from nuxt.
Related Issues (20)
- Tailwindcss added at last is not applied HOT 5
- Disabling SSR prevents remaining CSS from loading HOT 3
- Error: Cannot find module punycode/ HOT 9
- Img @error not working HOT 2
- useHead undefined after initiating a regex (since monday) HOT 4
- keepalive not work HOT 1
- String vs object errors with `createError` and accessing server-thrown errors on client
- Tailwind css issue related to CSS specificity on dev server HOT 1
- keep alive caches are destroyed when visit keep alive excluded page HOT 2
- The package generated under the .output/server/node_modules file is a hyperlink. HOT 1
- 'text/html' is not a valid JavaScript MIME type. HOT 1
- This module cannot be imported in the Vue part of your app. [importing @nuxt/kit from app.vue] causing page to not work HOT 5
- If a component uses empty data in `useFetch`, then `clearError` will be invalidated HOT 2
- Cache control header missing in response headers (while using nitro.publicAssets) HOT 4
- [nuxt] [request error] [unhandled] [500] _fetch is not a function HOT 3
- feat: support passing options to `TypedRouterOptions` when using `experimental.typedPages` HOT 3
- Dynamic layouts HOT 3
- Previous route info HOT 2
- Imported CSS files not correctly injected in circumstances involving lazy-loaded components HOT 1
- Nuxt 3 Dev build time is very slow in WSL 2 Linux Ubuntu ~ ranging up to 30 seconds just to refresh changes HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nuxt.