fix(kit): don't mutate existing component entry when overriding (#25786)

This commit is contained in:
Daniel Roe 2024-02-14 11:48:25 +00:00 committed by GitHub
parent 936ad91b0a
commit 363bb57b63
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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
@ -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)
}