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(nuxt): warn if inheritAttrs: false is set when using useId #25616

Merged
merged 2 commits into from
Feb 5, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions packages/nuxt/src/app/composables/id.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ export function useId (key?: string): string {
const instanceIndex = key + ':' + instance._nuxtIdIndex[key]++

if (import.meta.server) {
if (!import.meta.dev && instance.vnode.type && typeof instance.vnode.type === 'object' && 'inheritAttrs' in instance.vnode.type && instance.vnode.type.inheritAttrs === false) {
danielroe marked this conversation as resolved.
Show resolved Hide resolved
console.warn('[nuxt] `useId` is not compatible with components that have `inheritAttrs: false`.')
}
const ids = JSON.parse(instance.attrs[ATTR_KEY] as string | undefined || '{}')
ids[instanceIndex] = key + ':' + nuxtApp._id++
instance.attrs[ATTR_KEY] = JSON.stringify(ids)
Expand Down