Skip to content

Commit

Permalink
fix: try unobserving elements on cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
mary-ext committed Dec 13, 2023
1 parent 866999e commit de311ac
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions app/com/components/VirtualContainer.tsx
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -97,12 +97,11 @@ export const VirtualContainer = (props: VirtualContainerProps) => {
}
};

const measure = (node: HTMLElement) => scrollObserver.observe(node);
const shouldHide = () => !intersecting() && cachedHeight() !== undefined;

return (
<article
ref={measure}
ref={startMeasure}
class={props.class}
style={{ height: shouldHide() ? `${height ?? cachedHeight()}px` : undefined }}
prop:$onintersect={handleIntersect}
Expand All @@ -115,3 +114,11 @@ export const VirtualContainer = (props: VirtualContainerProps) => {
</article>
);
};

const startMeasure = (node: HTMLElement) => {
scrollObserver.observe(node);

onCleanup(() => {
scrollObserver.unobserve(node);
});
};

0 comments on commit de311ac

Please sign in to comment.