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

Đang mở Phù hợp với người mới
#67 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
78/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
backend, devtools

Hướng nghiên cứu

Đọc packages/agent-react-devtools/src/component-tree.ts quanh dòng 329–334 và so sánh trường hợp SUSPENDERS của decoder với bố cục 5 + environmentCount được mô tả trong issue. Theo dõi cách mảng operations được cung cấp được tiêu thụ, sau đó chạy bản tái hiện Suspense với hai boundary và xác nhận rằng nó không còn thêm một nút Anonymous có id 0.

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

Mô tả

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.

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.