fix pagination failing if data is loaded too slow into dom
All checks were successful
delpoy / build-and-deploy (push) Successful in 49s
All checks were successful
delpoy / build-and-deploy (push) Successful in 49s
This commit is contained in:
parent
97f10da146
commit
c89cbdd389
@ -7,10 +7,19 @@
|
||||
|
||||
let intersectionObserver: IntersectionObserver;
|
||||
|
||||
let intersectionElement;
|
||||
function getIntersectionElement() {
|
||||
intersectionElement =
|
||||
bodyElem.rows.item(bodyElem.rows.length - 15) || bodyElem.lastElementChild;
|
||||
let intersectionElement: HTMLElement;
|
||||
async function getIntersectionElement(): Promise<HTMLElement> {
|
||||
if (!bodyElem.lastElementChild) {
|
||||
await new Promise<void>((resolve) => {
|
||||
new MutationObserver((_, observer) => {
|
||||
if (!bodyElem.lastElementChild) return;
|
||||
observer.disconnect();
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
return bodyElem.rows.item(bodyElem.rows.length - 15)! || bodyElem.lastElementChild!;
|
||||
}
|
||||
|
||||
onMount(async () => {
|
||||
@ -20,7 +29,7 @@
|
||||
intersectionObserver = new IntersectionObserver(
|
||||
async (entries, observer) => {
|
||||
if (entries.filter((e) => e.isIntersecting).length === 0 || !entries) return;
|
||||
observer.unobserve(intersectionElement!);
|
||||
observer.unobserve(intersectionElement);
|
||||
|
||||
const rows = bodyElem.rows.length;
|
||||
|
||||
@ -28,22 +37,19 @@
|
||||
await tick();
|
||||
|
||||
if (rows === bodyElem.rows.length) return;
|
||||
getIntersectionElement();
|
||||
observer.observe(intersectionElement!);
|
||||
observer.observe((intersectionElement = await getIntersectionElement()));
|
||||
},
|
||||
{ threshold: 0.25 }
|
||||
);
|
||||
|
||||
new MutationObserver((entries) => {
|
||||
new MutationObserver(async (entries) => {
|
||||
if (entries.filter((e) => e.removedNodes.length > 0).length === 0 || !entries) return;
|
||||
|
||||
intersectionObserver.unobserve(intersectionElement!);
|
||||
getIntersectionElement();
|
||||
intersectionObserver.observe(intersectionElement!);
|
||||
intersectionObserver.unobserve(intersectionElement);
|
||||
intersectionObserver.observe((intersectionElement = await getIntersectionElement()));
|
||||
}).observe(bodyElem, { childList: true });
|
||||
|
||||
getIntersectionElement();
|
||||
intersectionObserver.observe(intersectionElement!);
|
||||
intersectionObserver.observe((intersectionElement = await getIntersectionElement()));
|
||||
});
|
||||
</script>
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user