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

オープン 初心者向け
#67 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
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がどのように消費されるかを追い、次に2つの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. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

callstackincubator/agent-react-devtools のほかの issue

callstackincubator/agent-react-devtools の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。