Skip to content

Commit db51811

Browse files
Apply Coderabbit's fix for duplicate crumb keys
1 parent 763b7d5 commit db51811

2 files changed

Lines changed: 22 additions & 2 deletions

File tree

‎components/breadcrumbs.jsx‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,10 @@ export default function Breadcrumbs() {
6262
return (
6363
<nav className="breadcrumbs" aria-label="Breadcrumb">
6464
<ol>
65-
{crumbs.map(crumb => (
66-
<li key={crumb.label}>
65+
{/* Key by position: crumbs are strictly ordered and labels may
66+
repeat when username === repository (e.g. refactorfirst/…). */}
67+
{crumbs.map((crumb, index) => (
68+
<li key={index}>
6769
{crumb.current ? (
6870
<span aria-current="page">{crumb.label}</span>
6971
) : crumb.href ? (

‎tests/integration/breadcrumbs.test.jsx‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,24 @@ describe('Breadcrumbs', () => {
155155
expect(items.at(-1).querySelector('[aria-current="page"]')).toBeTruthy();
156156
});
157157

158+
test('duplicate crumb labels (user == repository) do not produce duplicate keys', () => {
159+
const { spyOn } = require('bun:test');
160+
const consoleError = spyOn(console, 'error');
161+
try {
162+
const { container } = renderBreadcrumbs('/refactorfirst/refactorfirst/master');
163+
const items = crumbs(container);
164+
expect(items.length).toBe(4);
165+
expect(items.map(item => item.textContent))
166+
.toEqual(['Home', 'refactorfirst', 'refactorfirst', 'master']);
167+
const keyWarnings = consoleError.mock.calls
168+
.flat()
169+
.filter(arg => String(arg).includes('same key'));
170+
expect(keyWarnings).toEqual([]);
171+
} finally {
172+
consoleError.mockRestore();
173+
}
174+
});
175+
158176
test('exposes an ordered list inside a labelled navigation landmark', () => {
159177
const { container } = renderBreadcrumbs('/alice/some-repo/master');
160178
const nav = container.querySelector('nav[aria-label="Breadcrumb"]');

0 commit comments

Comments
 (0)