Skip to content

Commit 2777488

Browse files
committed
🐛(frontend) fix duplicate document entries in grid
The tests e2e were failing sometimes because the documents list was containing duplicates. This was happening when multiple users were modifying the documents list (creation, update, ...). We now deduplicate documents by their ID before displaying them.
1 parent a11258f commit 2777488

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,15 @@ and this project adheres to
66

77
## [Unreleased]
88

9+
## Fixed
10+
11+
- 🐛(frontend) fix duplicate document entries in grid #1479
12+
913
## [3.8.2] - 2025-10-17
1014

1115
### Fixed
1216

13-
🐛(service-worker) fix sw registration and page reload logic #1500
17+
- 🐛(service-worker) fix sw registration and page reload logic #1500
1418

1519
## [3.8.1] - 2025-10-17
1620

src/frontend/apps/impress/src/features/docs/docs-grid/components/DocsGrid.tsx

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { Button } from '@openfun/cunningham-react';
2+
import { useMemo } from 'react';
23
import { useTranslation } from 'react-i18next';
34
import { InView } from 'react-intersection-observer';
45
import { css } from 'styled-components';
@@ -36,7 +37,19 @@ export const DocsGrid = ({
3637
hasNextPage,
3738
} = useDocsQuery(target);
3839

39-
const docs = data?.pages.flatMap((page) => page.results) ?? [];
40+
const docs = useMemo(() => {
41+
const allDocs = data?.pages.flatMap((page) => page.results) ?? [];
42+
// Deduplicate documents by ID to prevent the same doc appearing multiple times
43+
// This can happen when a multiple users are impacting the docs list (creation, update, ...)
44+
const seenIds = new Set<string>();
45+
return allDocs.filter((doc) => {
46+
if (seenIds.has(doc.id)) {
47+
return false;
48+
}
49+
seenIds.add(doc.id);
50+
return true;
51+
});
52+
}, [data?.pages]);
4053

4154
const loading = isFetching || isLoading;
4255
const hasDocs = data?.pages.some((page) => page.results.length > 0);

0 commit comments

Comments
 (0)