Skip to content

Commit

Permalink
fix(kit): don't mutate existing component entry when overriding (#25786)
Browse files Browse the repository at this point in the history
  • Loading branch information
danielroe committed Feb 14, 2024
1 parent 936ad91 commit 363bb57
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions packages/kit/src/components.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,9 @@ export async function addComponent (opts: AddComponentOptions) {
}

nuxt.hook('components:extend', (components: Component[]) => {
const existingComponent = components.find(c => (c.pascalName === component.pascalName || c.kebabName === component.kebabName) && c.mode === component.mode)
if (existingComponent) {
const existingComponentIndex = components.findIndex(c => (c.pascalName === component.pascalName || c.kebabName === component.kebabName) && c.mode === component.mode)
if (existingComponentIndex !== -1) {
const existingComponent = components[existingComponentIndex]
const existingPriority = existingComponent.priority ?? 0
const newPriority = component.priority ?? 0

Expand All @@ -65,7 +66,7 @@ export async function addComponent (opts: AddComponentOptions) {
const name = existingComponent.pascalName || existingComponent.kebabName
logger.warn(`Overriding ${name} component. You can specify a \`priority\` option when calling \`addComponent\` to avoid this warning.`)
}
Object.assign(existingComponent, component)
components.splice(existingComponentIndex, 1, component)
} else {
components.push(component)
}
Expand Down

0 comments on commit 363bb57

Please sign in to comment.