Skip to content

Commit 442ba41

Browse files
committed
Merge branch 'main' into postgrest-scroll
2 parents 4cf88d2 + 4368bf2 commit 442ba41

File tree

3 files changed

+16
-29
lines changed

3 files changed

+16
-29
lines changed

packages/ui-components/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## [4.3.2] - 2025-07-03
4+
5+
- Fixed infinite loading issue on mount
6+
37
## [4.3.1] - 2025-07-02
48

59
- Updated infinite scorlling to take `delay` as input param (default 100ms)

packages/ui-components/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@macrostrat/ui-components",
3-
"version": "4.3.1",
3+
"version": "4.3.2",
44
"description": "UI components for React and Blueprint.js",
55
"main": "dist/cjs/index.js",
66
"module": "dist/esm/index.js",

packages/ui-components/src/infinite-scroll.ts

Lines changed: 11 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ function InfiniteScrollView<T>(props: InfiniteScrollProps<T>) {
174174
route,
175175
params,
176176
opts,
177-
placeholder,
177+
placeholder = (p: APIPlaceholderProps) => h(Spinner),
178178
className,
179179
itemComponent = JSONView,
180180
loadingPlaceholder = LoadingPlaceholder,
@@ -187,7 +187,15 @@ function InfiniteScrollView<T>(props: InfiniteScrollProps<T>) {
187187
delay,
188188
} = props;
189189
const { get } = useAPIActions();
190-
const { getCount, getNextParams, getItems, hasMore } = props;
190+
const {
191+
getCount = () => null,
192+
getNextParams = (response, params) => {
193+
const lastPage = params.page ?? 0;
194+
return { ...params, page: lastPage + 1 };
195+
},
196+
getItems = (d) => d,
197+
hasMore = (d) => true,
198+
} = props;
191199

192200
const initialState: ScrollState<T> = {
193201
items: initialItems,
@@ -206,13 +214,6 @@ function InfiniteScrollView<T>(props: InfiniteScrollProps<T>) {
206214

207215
const loadingRef = useRef(false);
208216

209-
const mountedRef = useRef(true);
210-
useEffect(() => {
211-
return () => {
212-
mountedRef.current = false;
213-
};
214-
}, []);
215-
216217
const loadPage = useCallback(
217218
async (action: LoadPage<T>) => {
218219
if (loadingRef.current) return; // Prevent concurrent loads
@@ -222,7 +223,6 @@ function InfiniteScrollView<T>(props: InfiniteScrollProps<T>) {
222223

223224
try {
224225
const res = await get(route, action.params, opts);
225-
if (!mountedRef.current) return;
226226

227227
const itemVals = getItems(res);
228228
const nextParams = getNextParams(res, action.params);
@@ -242,7 +242,7 @@ function InfiniteScrollView<T>(props: InfiniteScrollProps<T>) {
242242
},
243243
});
244244
} catch (error) {
245-
if (!mountedRef.current) return;
245+
console.error("Error loading page:", error);
246246
action.dispatch({
247247
type: "update-state",
248248
spec: { error: { $set: error }, isLoadingPage: { $set: null } },
@@ -325,21 +325,4 @@ function InfiniteScrollView<T>(props: InfiniteScrollProps<T>) {
325325
);
326326
}
327327

328-
InfiniteScrollView.defaultProps = {
329-
hasMore() {
330-
return true;
331-
},
332-
getItems(d) {
333-
return d;
334-
},
335-
getCount() {
336-
return null;
337-
},
338-
getNextParams(response, params) {
339-
const lastPage = params.page ?? 0;
340-
return { ...params, page: lastPage + 1 };
341-
},
342-
placeholder: (p: APIPlaceholderProps) => h(Spinner),
343-
};
344-
345328
export { InfiniteScrollView };

0 commit comments

Comments
 (0)