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

未关闭 适合新手
#66 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
86/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
react, typescript
领域
devtools

调研方向

从 packages/agent-react-devtools/src/devtools-bridge.ts 中约第 331–334 行的 handleInspectedElement 开始,阅读 extractHooksArray 如何访问已脱水的值。使用提供的 React 19 示例复现,并检查 inspectElement 响应中的 props 和 state。完成标准是:get component 显示底层的 prop 和 state 值,同时 hooks 仍能正确显示。

由索引模型根据 Issue 内容生成。

描述

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,
主要语言
TypeScript
星标
251
派生
13
PR 合并指标
30 天内没有已合并 PR

环境准备

这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

callstackincubator/agent-react-devtools 的其他 Issue

查看 callstackincubator/agent-react-devtools 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。