Skip to content

Commit 4b0f423

Browse files
committed
Keep track of loaded urls and make sure to not load them again
1 parent 31d08f4 commit 4b0f423

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

.idea/workspace.xml

+1-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/util/usePreLoader.ts

+8-1
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,17 @@ const cacheContent = async (contents: Story[]) => {
3333
export const usePreLoader = (contents: Story[], cursor: number, preloadCount: number) => {
3434
const urlsLoaded = useRef([] as string[]).current;
3535

36+
// Pushes urls to urlsLoaded
37+
const markUrlsLoaded = (contents: Story[]) => urlsLoaded.push(...contents.map((content) => content.url))
38+
3639
useEffect(() => {
3740
const start = cursor + 1;
3841
const end = cursor + preloadCount + 1;
39-
const toPreload = contents.slice(start, end);
42+
43+
const toPreload = contents.slice(start, end)
44+
.filter((content) => !urlsLoaded.includes(content.url)); // Only preload urls that haven't been loaded yet
45+
46+
markUrlsLoaded(toPreload)
4047

4148
cacheContent(toPreload)
4249
}, [cursor, preloadCount, contents])

0 commit comments

Comments
 (0)