Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 36 additions & 8 deletions components/brain/notifications/Notifications.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -199,16 +199,12 @@ export default function Notifications({ activeDrop, setActiveDrop }: Notificatio
return;
}

if (typeof ResizeObserver === "undefined") {
return;
}

const observationTarget =
(scrollElement.firstElementChild as HTMLElement | null) ?? scrollElement;

let rafId: number | null = null;

const observer = new ResizeObserver(() => {
const scheduleStickToBottom = () => {
if (!hasInitializedScrollRef.current || !isPinnedToBottomRef.current) {
return;
}
Expand All @@ -226,15 +222,47 @@ export default function Notifications({ activeDrop, setActiveDrop }: Notificatio
container.scrollTop = container.scrollHeight;
rafId = null;
});
});
};

observer.observe(observationTarget);
if (typeof ResizeObserver !== "undefined") {
const resizeObserver = new ResizeObserver(() => {
scheduleStickToBottom();
});

resizeObserver.observe(observationTarget);

return () => {
if (rafId !== null) {
cancelAnimationFrame(rafId);
}
resizeObserver.disconnect();
};
}

if (typeof MutationObserver !== "undefined") {
const mutationObserver = new MutationObserver(() => {
scheduleStickToBottom();
});

mutationObserver.observe(observationTarget, {
attributes: true,
childList: true,
subtree: true,
characterData: true,
});

return () => {
if (rafId !== null) {
cancelAnimationFrame(rafId);
}
mutationObserver.disconnect();
};
}

return () => {
if (rafId !== null) {
cancelAnimationFrame(rafId);
}
observer.disconnect();
};
}, [items, showLoader, showNoItems]);

Expand Down