Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

try to fix resize observer issue in windows (#33395)

Jordi Enric641207119374
diff --git a/apps/studio/components/ui/AIAssistantPanel/hooks.ts b/apps/studio/components/ui/AIAssistantPanel/hooks.ts
index 6de3b700fa7..507c0708e55 100644
--- a/apps/studio/components/ui/AIAssistantPanel/hooks.ts
+++ b/apps/studio/components/ui/AIAssistantPanel/hooks.ts
@@ -30,17 +30,21 @@ export function useAutoScroll({ enabled = true }: UseAutoScrollProps = {}) {
useEffect(() => {
if (!container || !enabled) return
+ let timeoutId: NodeJS.Timeout
+
const resizeObserver = new ResizeObserver(() => {
- // Prevent duplicate scroll events from phantom height changes
- if (
- lastScrollHeightRef.current !== undefined &&
- container.scrollHeight !== lastScrollHeightRef.current
- ) {
- lastScrollHeightRef.current = container.scrollHeight
- if (isStickyRef.current) {
- scrollToEnd()
+ clearTimeout(timeoutId)
+ timeoutId = setTimeout(() => {
+ if (
+ lastScrollHeightRef.current !== undefined &&
+ container.scrollHeight !== lastScrollHeightRef.current
+ ) {
+ lastScrollHeightRef.current = container.scrollHeight
+ if (isStickyRef.current) {
+ scrollToEnd()
+ }
}
- }
+ }, 100)
})
const handleScroll = () => {
@@ -59,6 +63,7 @@ export function useAutoScroll({ enabled = true }: UseAutoScrollProps = {}) {
container.addEventListener('scroll', handleScroll)
return () => {
+ clearTimeout(timeoutId)
resizeObserver.disconnect()
container.removeEventListener('scroll', handleScroll)
}