Skip to content

Commit

Permalink
fix(nuxt): warn if inheritAttrs: false when using useId (#25616)
Browse files Browse the repository at this point in the history
  • Loading branch information
danielroe committed Feb 5, 2024
1 parent b78e1cb commit 8705aed
Showing 1 changed file with 3 additions and 0 deletions.
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 @@ -29,6 +29,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) {
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

0 comments on commit 8705aed

Please sign in to comment.