Code Monkey home page Code Monkey logo

Comments (13)

danielroe avatar danielroe commented on June 4, 2024 5

We need the ability to v-bind attrs to the root element as useId needs to access them when it hydrates.

from nuxt.

manchenkoff avatar manchenkoff commented on June 4, 2024 2

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.

manniL avatar manniL commented on June 4, 2024 2

@gregdev00 no, see #26315

from nuxt.

gregdev00 avatar gregdev00 commented on June 4, 2024 1

I believe it's because of how the useId composable was implemented, it had different separators. It is fixed in this commit.

from nuxt.

codeflorist avatar codeflorist commented on June 4, 2024 1

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.

github-actions avatar github-actions commented on June 4, 2024

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.

daniluk4000 avatar daniluk4000 commented on June 4, 2024

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.

gangsthub avatar gangsthub commented on June 4, 2024

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.

TheDutchCoder avatar TheDutchCoder commented on June 4, 2024

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.

danielroe avatar danielroe commented on June 4, 2024

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.

jd1378 avatar jd1378 commented on June 4, 2024

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.

gregdev00 avatar gregdev00 commented on June 4, 2024

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.

madebyfabian avatar madebyfabian commented on June 4, 2024

Can this be closed then?

from nuxt.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.