Skip to content

Commit 8a2f269

Browse files
committed
fix: retry scrolls to ensure unmounted sizes are not estimated
1 parent e9e9410 commit 8a2f269

1 file changed

Lines changed: 19 additions & 6 deletions

File tree

  • Website/components/datamodelview

Website/components/datamodelview/List.tsx

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -159,9 +159,7 @@ export const List = ({ setCurrentIndex }: IListProps) => {
159159
return;
160160
}
161161

162-
rowVirtualizer.scrollToIndex(sectionIndex, {
163-
align: 'start'
164-
});
162+
smartScrollToIndex(sectionIndex);
165163

166164
}, [flatItems]);
167165

@@ -175,9 +173,7 @@ export const List = ({ setCurrentIndex }: IListProps) => {
175173
return;
176174
}
177175

178-
rowVirtualizer.scrollToIndex(groupIndex, {
179-
align: 'start'
180-
});
176+
smartScrollToIndex(groupIndex);
181177
}, [flatItems]);
182178

183179
const restoreSection = useCallback(() => {
@@ -202,6 +198,23 @@ export const List = ({ setCurrentIndex }: IListProps) => {
202198
}
203199
}, [rowVirtualizer]);
204200

201+
const smartScrollToIndex = useCallback((index: number) => {
202+
rowVirtualizer.scrollToIndex(index, { align: 'start' });
203+
204+
const tryFix = () => {
205+
const mounted = rowVirtualizer.getVirtualItems().some(v => v.index === index);
206+
if (!mounted) {
207+
requestAnimationFrame(tryFix);
208+
return;
209+
}
210+
211+
requestAnimationFrame(() => {
212+
rowVirtualizer.scrollToIndex(index, { align: 'start' });
213+
});
214+
};
215+
requestAnimationFrame(tryFix);
216+
}, [rowVirtualizer]);
217+
205218
return (
206219
<>
207220
<Box className={`absolute w-full h-full flex items-center justify-center z-[100] transition-opacity duration-300 ${loadingSection ? 'opacity-100' : 'opacity-0 pointer-events-none'}`}>

0 commit comments

Comments
 (0)