fix: flash bug on tag (#12332)

* fix flash bug on tag

* fix lint

---------

Co-authored-by: Alex <alex.tran1502@gmail.com>
This commit is contained in:
Min Idzelis
2024-09-05 07:29:07 -07:00
committed by GitHub
parent 27e283e724
commit d7d3b8dfec
7 changed files with 79 additions and 54 deletions

View File

@@ -10,10 +10,10 @@ type TrackedProperties = {
left?: string;
};
type OnIntersectCallback = (entryOrElement: IntersectionObserverEntry | HTMLElement) => unknown;
type OnSeperateCallback = (element: HTMLElement) => unknown;
type OnSeparateCallback = (element: HTMLElement) => unknown;
type IntersectionObserverActionProperties = {
key?: string;
onSeparate?: OnSeperateCallback;
onSeparate?: OnSeparateCallback;
onIntersect?: OnIntersectCallback;
root?: Element | Document | null;
@@ -22,8 +22,6 @@ type IntersectionObserverActionProperties = {
right?: string;
bottom?: string;
left?: string;
disabled?: boolean;
};
type TaskKey = HTMLElement | string;
@@ -92,11 +90,7 @@ function _intersectionObserver(
element: HTMLElement,
properties: IntersectionObserverActionProperties,
) {
if (properties.disabled) {
properties.onIntersect?.(element);
} else {
configure(key, element, properties);
}
configure(key, element, properties);
return {
update(properties: IntersectionObserverActionProperties) {
const config = elementToConfig.get(key);
@@ -106,20 +100,14 @@ function _intersectionObserver(
if (isEquivalent(config, properties)) {
return;
}
configure(key, element, properties);
},
destroy: () => {
if (properties.disabled) {
properties.onSeparate?.(element);
} else {
const config = elementToConfig.get(key);
const { observer, onSeparate } = config || {};
observer?.unobserve(element);
elementToConfig.delete(key);
if (onSeparate) {
onSeparate?.(element);
}
}
const config = elementToConfig.get(key);
const { observer } = config || {};
observer?.unobserve(element);
elementToConfig.delete(key);
},
};
}
@@ -148,5 +136,5 @@ export function intersectionObserver(
},
};
}
return _intersectionObserver(element, element, properties);
return _intersectionObserver(properties.key || element, element, properties);
}