Synthetic events drop non-enumerable fields (clipboardData/dataTransfer from Testing Library are undefined)
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
- 难度
- 2/5
- 预计耗时
- 1-3 小时
- 新手友好度
- 78/100
- Issue 类型
- 缺陷
- 描述清晰度
- 描述清楚
- 活跃度
- 活跃
- 技术栈
- javascript, react, typescript
调研方向
从 src/dom/synthetic-event.ts 中的 createSyntheticEvent 开始,查看它如何从原生事件复制字段。使用 issue 中的 Vitest 和 Testing Library 示例,重现缺失的 clipboardData 或 dataTransfer 值。当处理程序在测试中收到这些值,且现有的合成事件行为仍然正常时,即表示完成。
由索引模型根据 Issue 内容生成。
描述
Version: @tanstack/redact 0.2.2
createSyntheticEvent (src/dom/synthetic-event.ts) copies the native event's fields with for (const key in native). That only sees enumerable properties. Own properties defined with Object.defineProperty (non-enumerable by default) are dropped, so the handler gets undefined where React hands over the value.
In real browsers this is fine for native events: WebIDL attributes such as ClipboardEvent.clipboardData and DragEvent.dataTransfer are enumerable accessors on the prototype (checked in Chromium). It breaks for:
- Testing Library / jsdom:
fireEvent.paste(el, { clipboardData })andfireEvent.drop(el, { dataTransfer })assign those fields withObject.defineProperty, because jsdom has noClipboardEvent/DragEventdata. Paste and drop tests that pass under React fail under Redact. - Any library or app code that dispatches a plain
Eventand attaches data the same way.
Repro (Vitest + jsdom + Testing Library)
import { render, fireEvent } from "@testing-library/react";
it("handlers see non-enumerable event fields", () => {
let pasted: unknown;
const { getByRole } = render(
<textarea onPaste={(e) => { pasted = e.clipboardData?.getData("text/plain"); }} />,
);
fireEvent.paste(getByRole("textbox"), { clipboardData: { getData: () => "hello" } });
let dropped: unknown;
const { container } = render(<div onDrop={(e) => { dropped = e.dataTransfer?.getData("text"); }} />);
const ev = new Event("drop", { bubbles: true });
Object.defineProperty(ev, "dataTransfer", { value: { getData: () => "dropped" } });
container.firstChild!.dispatchEvent(ev);
expect(pasted).toBe("hello");
expect(dropped).toBe("dropped");
});
pasted |
dropped |
|
|---|---|---|
| React 19 | "hello" |
"dropped" |
| Redact 0.2.2 | undefined |
undefined |
Suggestion
Also copy own non-enumerable properties (Object.getOwnPropertyNames(native)), or read fields lazily from nativeEvent (a getter or Proxy fallback) the way React's per-interface getters read nativeEvent.clipboardData / dataTransfer directly.
Found while running a TanStack Start app's component tests (chat composer paste and image drop) under Redact.
- 主要语言
- TypeScript
- 星标
- 408
- 派生
- 13
- 平均合并
- 1 小时 47 分钟
- 30 天内合并 PR
- 22
环境准备
这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
TanStack/redact 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 85/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 88/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 90/100
TanStack/redact#67 · 1 个 reaction ·
维护者通常 1 天内回复
-
难度 1/5 1 小时以内 新手友好度 82/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 1 天内回复
相似的 Issue
-
Replace discontinued crypto-js in the theme可能已有人在做 @aelmanaa 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 85/100
PaloAltoNetworks/docusaurus-openapi-docs#1689 ·
维护者通常 2 天内回复
-
难度 2/5 1-3 小时 新手友好度 70/100
solana-foundation/solana-web3.js#4015 · 1 条评论 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 85/100
维护者通常 1 天内回复
-
documentation
难度 1/5 1-3 小时 新手友好度 90/100
ivopogace/opencode-courier#422 ·
维护者通常 1 天内回复
-
bug
难度 2/5 1-3 小时 新手友好度 68/100
chapel-lang/chapel-vscode#158 ·
维护者通常 1 天内回复