get component shows props and state as the dehydrated {data, cleaned, unserializable} wrapper

Đang mở Phù hợp với người mới
#66 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

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
86/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ệ
react, typescript
Lĩnh vực
devtools

Hướng nghiên cứu

Bắt đầu tại packages/agent-react-devtools/src/devtools-bridge.ts, ở handleInspectedElement khoảng dòng 331–334, và đọc cách extractHooksArray truy cập các giá trị đã khử nước. Tái hiện bằng ví dụ React 19 được cung cấp và kiểm tra phản hồi inspectElement để xem props và state. Hoàn tất khi get component hiển thị các giá trị prop và state bên dưới trong khi hooks vẫn hiển thị chính xác.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

Summary

get component prints props and class state as the raw dehydrated wrapper { data, cleaned, unserializable } instead of the values. Hooks are fine.

Environment

Repro

Any React 19 app connected through react-devtools-core:

function Greeting({ name, count, user, tags }) {
  const [n] = React.useState(42);
  return <p>{name}</p>;
}
class Counter extends React.Component {
  state = { clicks: 5, label: 'hi' };
  render() { return <span>{this.state.clicks}</span>; }
}
<>
  <Greeting name="Ada" count={3} user={{ id: 7, role: 'admin' }} tags={['a', 'b']} />
  <Counter step={2} />
</>
$ agent-react-devtools get component @c3
@c3 [fn] Greeting
props:
  data: {"name":"Ada","count":3,"user":{"id":7,"role":"admin"},"t...
  cleaned: []
  unserializable: []
hooks:
  State: 42
$ agent-react-devtools get component @c4
@c4 [cls] Counter
props:
  data: {"step":2}
  cleaned: []
  unserializable: []
state:
  data: {"clicks":5,"label":"hi"}
  cleaned: []
  unserializable: []

Expected

props:
  name: "Ada"
  count: 3
  user: {"id":7,"role":"admin"}
  tags: ["a","b"]

Cause

The backend's inspectElement response passes props, state, hooks (and context) through cleanForBridge, which returns { data, cleaned, unserializable }. handleInspectedElement in devtools-bridge.ts calls cleanDehydrated(data.value.props) / cleanDehydrated(data.value.state) on the wrapper itself. Hooks work because extractHooksArray reads .data.

Reading .data first fixes it. With this local change the output above becomes the expected one:

props: cleanDehydrated(data.value.props?.data ?? data.value.props),
state: data.value.state ? cleanDehydrated(data.value.state?.data ?? data.value.state) : null,
Ngôn ngữ chính
TypeScript
Star
251
Fork
13
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

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

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. 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.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của callstackincubator/agent-react-devtools

Tất cả issue của callstackincubator/agent-react-devtools

Issue tương tự

Thêm issue về TypeScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.