From de311ac446c7e0592ee77bccdfaeccda797bd96a Mon Sep 17 00:00:00 2001 From: Mary Date: Wed, 13 Dec 2023 07:41:24 +0700 Subject: [PATCH] fix: try unobserving elements on cleanup --- app/com/components/VirtualContainer.tsx | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/app/com/components/VirtualContainer.tsx b/app/com/components/VirtualContainer.tsx index 37f59b6b..0635bbf9 100644 --- a/app/com/components/VirtualContainer.tsx +++ b/app/com/components/VirtualContainer.tsx @@ -1,4 +1,4 @@ -import { type JSX, createSignal } from 'solid-js'; +import { type JSX, createSignal, onCleanup } from 'solid-js'; import { scheduleIdleTask } from '~/utils/idle.ts'; import { getRectFromEntry, scrollObserver } from '~/utils/intersection-observer.ts'; @@ -97,12 +97,11 @@ export const VirtualContainer = (props: VirtualContainerProps) => { } }; - const measure = (node: HTMLElement) => scrollObserver.observe(node); const shouldHide = () => !intersecting() && cachedHeight() !== undefined; return (
{
); }; + +const startMeasure = (node: HTMLElement) => { + scrollObserver.observe(node); + + onCleanup(() => { + scrollObserver.unobserve(node); + }); +};