Two sibling .map() lists with the same keys leave orphaned DOM nodes that pile up on refill (React keeps key scopes per array)
維護者通常 1 天內回覆
還沒有人認領這個 Issue。
評估
- 難度
- 4/5
- 預估耗時
- 3-5 天
- 新手友好度
- 58/100
- Issue 類型
- 缺陷
- 描述清晰度
- 描述清楚
- 活躍度
- 活躍
- 技術堆疊
- react, typescript
研究方向
Start by reading the child reconciliation code and the related issue #149, which the report identifies as likely sharing the same key-space problem. Run the supplied Vitest and Testing Library repro against React and Redact, then trace how sibling .map() arrays are represented during removal and refill. Done means both lists empty to [0, 0] and refill to [2, 2], with a regression test covering the case.
由索引模型根據 Issue 內容生成。
描述
Version: @tanstack/redact 0.3.1. Baseline: react / react-dom 19.3.1.
When two .map() lists in the same parent use the same keys, emptying them leaves one list's DOM nodes in the document. Redact never removes them, and they pile up: each refill adds a full new set next to the stale nodes. React keeps each array's keys separate, so its output follows the props.
Sharing keys between sibling lists is valid React and easy to hit. For example, a map overlay might render one marker per item and then one label per group, where a single-item group's key is that item's key.
Repro (Vitest + happy-dom + Testing Library)
import { render } from '@testing-library/react';
import { expect, test } from 'vitest';
function Two({ ids }) {
return (
<div>
{ids.map((id) => <span key={id} className="a" />)}
{ids.map((id) => <span key={id} className="b" />)}
</div>
);
}
test('two sibling lists with the same keys empty and refill like React', () => {
const view = render(<Two ids={['x', 'y']} />);
const counts = () => [
document.querySelectorAll('.a').length,
document.querySelectorAll('.b').length,
];
view.rerender(<Two ids={[]} />);
expect(counts()).toEqual([0, 0]); // React: [0, 0]. Redact: [2, 0]
view.rerender(<Two ids={['x', 'y']} />);
expect(counts()).toEqual([2, 2]); // React: [2, 2]. Redact: [4, 2]
});
React 19.3.1 passes. Redact 0.3.1 fails: after emptying, the first list's two nodes are still in the DOM ([2, 0]), and after refilling there are four ([4, 2]). In a larger case (30 items, then a grouped list with some single-item groups), the nodes whose keys collided were the ones left behind.
Related
This is likely the shared key space that #149 mentions as a side effect of flattening nested arrays into the parent's child list. The candidate fix described there, which gives each nested array its own slot and key scope, may cover it. This repro could be added as a regression case for orphaned nodes, which #149's own repro does not show.
- 主要語言
- TypeScript
- 星號
- 640
- 分支
- 32
- 平均合併
- 1 小時 15 分鐘
- 30 天內合併 PR
- 7
環境準備
這個專案沒有提供開發容器、Dockerfile 或貢獻指南,環境需要你自己搭建:先看它的 README,通用步驟見我們的新手貢獻指南。
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
TanStack/redact 的其他 Issue
-
難度 2/5 1-3 小時 新手友好度 70/100
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 82/100
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 84/100
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 85/100
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 78/100
維護者通常 1 天內回覆
相似的 Issue
-
bug data-types
難度 2/5 1-3 小時 新手友好度 88/100
ClickHouse/clickhouse-js#1293 ·
維護者通常 1 天內回覆
-
area: middleware enhancement good first issue
難度 2/5 1-3 小時 新手友好度 68/100
-
agent/quality testing
難度 1/5 1 小時以內 新手友好度 95/100
維護者通常 1 天內回覆
-
GitHub registry install via `gh` credentials rewrites `\u0000`–`\u001f` escapes in source files to `^@`–`^_`可能已有人在做 關聯的 PR 仍在進行中或已合併。 未關閉
難度 2/5 1-3 小時 新手友好度 92/100
維護者通常 2 天內回覆
-
難度 2/5 1-3 小時 新手友好度 78/100
juspay/agent-distro#203 ·
維護者通常 1 天內回覆