From 2777488d24d81df28d34380d4e28227ba91e9756 Mon Sep 17 00:00:00 2001 From: Anthony LC Date: Mon, 13 Oct 2025 16:03:37 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B(frontend)=20fix=20duplicate=20docu?= =?UTF-8?q?ment=20entries=20in=20grid?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- CHANGELOG.md | 6 +++++- .../docs/docs-grid/components/DocsGrid.tsx | 15 ++++++++++++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 96e8ec18..f2cc21f8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,11 +6,15 @@ and this project adheres to ## [Unreleased] +## Fixed + +- 🐛(frontend) fix duplicate document entries in grid #1479 + ## [3.8.2] - 2025-10-17 ### Fixed -🐛(service-worker) fix sw registration and page reload logic #1500 +- 🐛(service-worker) fix sw registration and page reload logic #1500 ## [3.8.1] - 2025-10-17 diff --git a/src/frontend/apps/impress/src/features/docs/docs-grid/components/DocsGrid.tsx b/src/frontend/apps/impress/src/features/docs/docs-grid/components/DocsGrid.tsx index 3705e98c..51df82b4 100644 --- a/src/frontend/apps/impress/src/features/docs/docs-grid/components/DocsGrid.tsx +++ b/src/frontend/apps/impress/src/features/docs/docs-grid/components/DocsGrid.tsx @@ -1,4 +1,5 @@ import { Button } from '@openfun/cunningham-react'; +import { useMemo } from 'react'; import { useTranslation } from 'react-i18next'; import { InView } from 'react-intersection-observer'; import { css } from 'styled-components'; @@ -36,7 +37,19 @@ export const DocsGrid = ({ hasNextPage, } = useDocsQuery(target); - const docs = data?.pages.flatMap((page) => page.results) ?? []; + const docs = useMemo(() => { + const allDocs = data?.pages.flatMap((page) => page.results) ?? []; + // Deduplicate documents by ID to prevent the same doc appearing multiple times + // This can happen when a multiple users are impacting the docs list (creation, update, ...) + const seenIds = new Set(); + return allDocs.filter((doc) => { + if (seenIds.has(doc.id)) { + return false; + } + seenIds.add(doc.id); + return true; + }); + }, [data?.pages]); const loading = isFetching || isLoading; const hasDocs = data?.pages.some((page) => page.results.length > 0);