SUSPENDERS operation is decoded with the wrong length, adding a phantom node

未關閉 適合新手
#67 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

還沒有人認領這個 Issue。

評估

難度
2/5
預估耗時
1-3 小時
新手友好度
78/100
Issue 類型
缺陷
描述清晰度
描述清楚
活躍度
活躍
技術堆疊
react, typescript
領域
backend, devtools

研究方向

閱讀 packages/agent-react-devtools/src/component-tree.ts 第329–334行附近的內容,並將 decoder 的 SUSPENDERS 分支與 issue 中描述的 5 + environmentCount 佈局進行比較。追蹤提供的 operations array 如何被處理,接著執行包含兩個 boundary 的 Suspense 重現案例,並確認它不再新增 id 為 0 的 Anonymous 節點。

由索引模型根據 Issue 內容生成。

描述

Summary

The operations decoder skips 2 + numChanges * 4 values for SUSPENSE_TREE_OPERATION_SUSPENDERS (12). Current backends write 5 + environmentCount values per change. When one commit changes suspenders on two or more Suspense boundaries, the leftover values are parsed as opcodes, and a phantom Anonymous node with id 0 gets added to the tree.

Environment

Repro

const pending = new Promise(() => {});
function Loader({ p }) { use(p); return <i>done</i>; }
function App() {
  const [on, setOn] = useState(false);
  useEffect(() => { setTimeout(() => setOn(true), 3000); }, []);
  return (
    <div>
      <Suspense fallback={<b>A...</b>}>{on ? <Loader p={pending} /> : <i>a</i>}</Suspense>
      <Suspense fallback={<b>B...</b>}>{on ? <Loader p={pending} /> : <i>b</i>}</Suspense>
    </div>
  );
}

After both boundaries suspend in the same commit:

$ agent-react-devtools count
5 components (?:2 susp:2 fn:1)
$ agent-react-devtools find Anonymous
@c?(id:0) [?] Anonymous

The operations message for that commit (captured from the backend websocket):

[1,1,0, 10,1,2,3,4, 12,2, 3,1,0,1,0, 4,1,0,1,0]

Each change is id, hasUniqueSuspenders, endTime, isSuspended, envCount, ...envIds. The decoder skips 10 values after the opcode and lands on 1,0, which it reads as TREE_OPERATION_ADD for id 0.

Cause

component-tree.ts L329-L334. The encoder is in react-devtools-shared renderer.js (flushPendingEvents); its own printOperationsArray reads the same 5 + N layout.

Fix

case SUSPENSE_TREE_OPERATION_SUSPENDERS: {
  this.extendedAddFormat = true;
  const numChanges = operations[i + 1];
  i += 2;
  for (let c = 0; c < numChanges; c++) {
    i += 4;                  // id, hasUniqueSuspenders, endTime, isSuspended
    i += 1 + operations[i];  // envCount + env string IDs
  }
  break;
}

With this change the same repro reports 4 components (susp:2 ?:1 fn:1) and no Anonymous node.

主要語言
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 摘要。