Synthetic events drop non-enumerable fields (clipboardData/dataTransfer from Testing Library are undefined)
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 78/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- javascript, react, typescript
Hướng nghiên cứu
Bắt đầu tại src/dom/synthetic-event.ts, ở createSyntheticEvent, và đọc cách hàm này sao chép các trường từ sự kiện gốc. Dùng ví dụ Vitest và Testing Library trong issue để tái hiện các giá trị còn thiếu của clipboardData hoặc dataTransfer. Hoàn tất khi các handler nhận được những giá trị đó trong các bài kiểm thử và hành vi hiện có của sự kiện tổng hợp vẫn hoạt động.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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.
- Ngôn ngữ chính
- TypeScript
- Star
- 408
- Fork
- 13
- Merge trung bình
- 1 giờ 44 phút
- Pull request đã merge (30 ngày)
- 21
Chuẩn bị môi trường
Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của TanStack/redact
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 85/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 90/100
TanStack/redact#67 · 1 reaction ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 82/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Bug: jsx runtime doesn't apply defaultProps (breaks Recharts 2: "Could not find xAxis by id")Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
TanStack/redact#58 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của TanStack/redact
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
marmelab/react-admin#11431 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
db-ux-design-system/core-web#8655 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
Maintainer thường phản hồi trong vòng 1 ngày
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
stripe/react-stripe-js#728 ·
-
[Upload Grade C dataset] the pop-up changes it's size while uploading the document => Jumping effectĐang mởbug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 66/100
epam/statgpt-admin-frontend#305 ·
Maintainer thường phản hồi trong vòng 1 ngày