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 摘要。