Skip to content

Commit 4368bf2

Browse files
authored
Merge pull request #121 from UW-Macrostrat/infinite-scroll-fix
Infinite scroll fix
2 parents 9ecf536 + 932cdbb commit 4368bf2

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
@@ -147,7 +147,7 @@ function InfiniteScrollView<T>(props: InfiniteScrollProps<T>) {
147147
route,
148148
params,
149149
opts,
150-
placeholder,
150+
placeholder = (p: APIPlaceholderProps) => h(Spinner),
151151
className,
152152
itemComponent = JSONView,
153153
loadingPlaceholder = LoadingPlaceholder,
@@ -160,7 +160,15 @@ function InfiniteScrollView<T>(props: InfiniteScrollProps<T>) {
160160
delay,
161161
} = props;
162162
const { get } = useAPIActions();
163-
const { getCount, getNextParams, getItems, hasMore } = props;
163+
const {
164+
getCount = () => null,
165+
getNextParams = (response, params) => {
166+
const lastPage = params.page ?? 0;
167+
return { ...params, page: lastPage + 1 };
168+
},
169+
getItems = (d) => d,
170+
hasMore = (d) => true,
171+
} = props;
164172

165173
const initialState: ScrollState<T> = {
166174
items: initialItems,
@@ -179,13 +187,6 @@ function InfiniteScrollView<T>(props: InfiniteScrollProps<T>) {
179187

180188
const loadingRef = useRef(false);
181189

182-
const mountedRef = useRef(true);
183-
useEffect(() => {
184-
return () => {
185-
mountedRef.current = false;
186-
};
187-
}, []);
188-
189190
const loadPage = useCallback(
190191
async (action: LoadPage<T>) => {
191192
if (loadingRef.current) return; // Prevent concurrent loads
@@ -195,7 +196,6 @@ function InfiniteScrollView<T>(props: InfiniteScrollProps<T>) {
195196

196197
try {
197198
const res = await get(route, action.params, opts);
198-
if (!mountedRef.current) return;
199199

200200
const itemVals = getItems(res);
201201
const nextParams = getNextParams(res, action.params);
@@ -215,7 +215,7 @@ function InfiniteScrollView<T>(props: InfiniteScrollProps<T>) {
215215
},
216216
});
217217
} catch (error) {
218-
if (!mountedRef.current) return;
218+
console.error("Error loading page:", error);
219219
action.dispatch({
220220
type: "update-state",
221221
spec: { error: { $set: error }, isLoadingPage: { $set: null } },
@@ -298,21 +298,4 @@ function InfiniteScrollView<T>(props: InfiniteScrollProps<T>) {
298298
);
299299
}
300300

301-
InfiniteScrollView.defaultProps = {
302-
hasMore() {
303-
return true;
304-
},
305-
getItems(d) {
306-
return d;
307-
},
308-
getCount() {
309-
return null;
310-
},
311-
getNextParams(response, params) {
312-
const lastPage = params.page ?? 0;
313-
return { ...params, page: lastPage + 1 };
314-
},
315-
placeholder: (p: APIPlaceholderProps) => h(Spinner),
316-
};
317-
318301
export { InfiniteScrollView };

0 commit comments

Comments
 (0)