From 710db1f16107e5f2123493accd8e5976afec2397 Mon Sep 17 00:00:00 2001 From: saberzero1 Date: Fri, 24 Apr 2026 23:56:53 +0200 Subject: [PATCH] fix(components): deduplicate plugin handler registration --- quartz/components/registry.ts | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/quartz/components/registry.ts b/quartz/components/registry.ts index 2b55b9f..444cd49 100644 --- a/quartz/components/registry.ts +++ b/quartz/components/registry.ts @@ -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, + ): 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()