diff --git a/packages/component/src/providers/CustomElements/private/useUpdater.tsx b/packages/component/src/providers/CustomElements/private/useUpdater.tsx index d8c9ac30bc..c5e530b705 100644 --- a/packages/component/src/providers/CustomElements/private/useUpdater.tsx +++ b/packages/component/src/providers/CustomElements/private/useUpdater.tsx @@ -40,10 +40,12 @@ export function createElementRegistryWithUpdater void>(); + disposeCallback.current = useMemo(() => { disposeCallback.current?.(); updateCallbacks.add(updateCallback); + const localUpdaters = new Set([...elements].map(element => new ElementUpdater(element, updateCallback))); updaters = updaters.union(localUpdaters); @@ -62,8 +64,10 @@ export function createElementRegistryWithUpdater updater.element === element)); + disposeUpdaters.forEach(updater => updater.dispose()); updaters = updaters.difference(disposeUpdaters); + elements.delete(element); } @@ -71,9 +75,11 @@ export function createElementRegistryWithUpdater new ElementUpdater(element, updateCallback))) ); + elements.add(element); }