Skip to content

perf/a11y: 슬라이드 인덱스 검색 개선 및 중복 ARIA 제거#327

Merged
AndyH0ng merged 2 commits intodevelopfrom
copilot/optimize-slide-search
Mar 2, 2026
Merged

perf/a11y: 슬라이드 인덱스 검색 개선 및 중복 ARIA 제거#327
AndyH0ng merged 2 commits intodevelopfrom
copilot/optimize-slide-search

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 2, 2026

Two independent issues in SlidePage.tsx: redundant double array scan to resolve the current slide, and a mobile container incorrectly duplicating the desktop tabpanel ARIA role/ID.

Performance: single findIndex instead of find + findIndex

// Before — two O(n) passes
const currentSlide = slides?.find((s) => s.slideId === routeSlideId) ?? slides?.[0];
const currentIndex = currentSlide
  ? (slides?.findIndex((s) => s.slideId === currentSlide.slideId) ?? -1)
  : -1;

// After — one pass, index-based access
const currentIndexFromRoute = slides?.findIndex((s) => s.slideId === routeSlideId) ?? -1;
const effectiveIndex =
  slides && slides.length > 0
    ? currentIndexFromRoute >= 0 ? currentIndexFromRoute : 0
    : -1;
const currentSlide = effectiveIndex >= 0 && slides ? slides[effectiveIndex] : undefined;
const currentIndex = effectiveIndex;

Accessibility: remove duplicate tabpanel on mobile

The mobile <div> had role="tabpanel" / id="tabpanel-slide-mobile" / aria-labelledby="tab-slide" — mirroring the desktop panel that's always in the DOM. Since only one is visible at a time via CSS, this created two elements claiming the same tab's content. The mobile div's ARIA tabpanel attributes are removed; the desktop panel retains them.

Original prompt
Please apply the following diffs and create a pull request.
Once the PR is ready, give it a title based on the messages of the fixes being applied.

[{"message":"The code performs two separate array searches: one with `find` to get the slide, and another with `findIndex` to get its position. This results in two O(n) operations. Consider using a single `findIndex` operation and then accessing the slide by index, which would reduce the search to O(n).","fixFiles":[{"filePath":"src/pages/SlidePage.tsx","diff":"diff --git a/src/pages/SlidePage.tsx b/src/pages/SlidePage.tsx\n--- a/src/pages/SlidePage.tsx\n+++ b/src/pages/SlidePage.tsx\n@@ -22,10 +22,15 @@\n     pollingIntervalMs: 15000,\n   });\n \n-  const currentSlide = slides?.find((s) => s.slideId === routeSlideId) ?? slides?.[0];\n-  const currentIndex = currentSlide\n-    ? (slides?.findIndex((s) => s.slideId === currentSlide.slideId) ?? -1)\n-    : -1;\n+  const currentIndexFromRoute = slides?.findIndex((s) => s.slideId === routeSlideId) ?? -1;\n+  const effectiveIndex =\n+    slides && slides.length > 0\n+      ? currentIndexFromRoute >= 0\n+        ? currentIndexFromRoute\n+        : 0\n+      : -1;\n+  const currentSlide = effectiveIndex >= 0 && slides ? slides[effectiveIndex] : undefined;\n+  const currentIndex = effectiveIndex;\n   const hasPrev = currentIndex > 0;\n   const hasNext = !!slides && currentIndex >= 0 && currentIndex < slides.length - 1;\n \n"}]},{"message":"Both tabpanels share the same `aria-labelledby` value 'tab-slide', but have different ids ('tabpanel-slide' and 'tabpanel-slide-mobile'). Since only one tabpanel is visible at a time depending on screen size, consider using a consistent approach where the visible tabpanel has the proper ARIA relationship, or ensure the controlling tab element references both tabpanels appropriately.","fixFiles":[{"filePath":"src/pages/SlidePage.tsx","diff":"diff --git a/src/pages/SlidePage.tsx b/src/pages/SlidePage.tsx\n--- a/src/pages/SlidePage.tsx\n+++ b/src/pages/SlidePage.tsx\n@@ -132,12 +132,7 @@\n         </main>\n       </div>\n \n-      <div\n-        role=\"tabpanel\"\n-        id=\"tabpanel-slide-mobile\"\n-        aria-labelledby=\"tab-slide\"\n-        className=\"flex min-[1024px]:hidden h-full flex-col px-4 py-4\"\n-      >\n+      <div className=\"flex min-[1024px]:hidden h-full flex-col px-4 py-4\">\n         <div className=\"flex items-center justify-between pb-3\">\n           <button\n             type=\"button\"\n"}]}]

💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Co-authored-by: AndyH0ng <60703412+AndyH0ng@users.noreply.github.com>
Copilot AI changed the title [WIP] Optimize slide search algorithm for better performance perf/a11y: single-pass slide index lookup and remove duplicate tabpanel ARIA on mobile Mar 2, 2026
@github-actions github-actions bot added the page 페이지 관련 변경 label Mar 2, 2026
@AndyH0ng AndyH0ng marked this pull request as ready for review March 2, 2026 04:46
@AndyH0ng AndyH0ng merged commit eb7d447 into develop Mar 2, 2026
8 checks passed
@AndyH0ng AndyH0ng deleted the copilot/optimize-slide-search branch March 2, 2026 04:47
@AndyH0ng AndyH0ng changed the title perf/a11y: single-pass slide index lookup and remove duplicate tabpanel ARIA on mobile perf/a11y: 슬라이드 인덱스 검색 개선 및 중복 ARIA 제거 Mar 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

page 페이지 관련 변경

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants