fix(components): deduplicate plugin handler registration

This commit is contained in:
saberzero1
2026-04-24 23:56:53 +02:00
parent 4ffe041f13
commit 710db1f161

View File

@@ -90,7 +90,12 @@ class ComponentRegistry {
try {
let instance: QuartzComponent
if (typeof r.component === "function") {
instance = this.instantiate(r.component as QuartzComponentConstructor, undefined)
// Check if this constructor was already instantiated (with any options).
// Re-instantiating with `undefined` when options were provided would create
// a duplicate instance with separate afterDOMLoaded scripts.
const existing = this.findCachedInstance(r.component as QuartzComponentConstructor)
instance =
existing ?? this.instantiate(r.component as QuartzComponentConstructor, undefined)
} else {
instance = r.component as QuartzComponent
}
@@ -103,6 +108,17 @@ class ComponentRegistry {
}
return results
}
private findCachedInstance(
constructor: QuartzComponentConstructor<any>,
): QuartzComponent | undefined {
const ctorId = (constructor as unknown as { __cacheId?: string }).__cacheId
if (!ctorId) return undefined
for (const [key, instance] of this.instanceCache) {
if (key.startsWith(`${ctorId}:`)) return instance
}
return undefined
}
}
export const componentRegistry = new ComponentRegistry()