[2.0 RC20] Development attribution can trigger context errors by evaluating lazy children getters

クローズ
#4,548 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

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

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
35/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
活発
技術スタック
javascript, typescript
領域
devtools

調査の方向性

The comparator is shallowEquivalent in packages/signals/src/core/attribution.ts, which reads property values directly and so invokes getters on both previous and next output; it is shared by UNSTABLE_MEMO_OUTPUT and UNSTABLE_LIST_IDENTITY. Start by running the minimal repro with node --conditions=development repro.mjs and confirm it prints 2 when attribution is enabled. Done when the repro prints 0 and the comparator no longer evaluates lazy getters.

索引モデルが issue の本文から書いたものです。

説明

What happened?

While porting a base ui to Solid 2, I encountered context errors in development previews for simple components. Their component tests were passing, which initially made this look like a problem with the preview setup or our Solid adaptations.

After reducing the failing case, I found that attribution’s output comparison was evaluating a lazy children getter that the application had not read. When that getter constructs JSX or reads context, the diagnostic can run it outside the expected owner and cause a context error.

I originally encountered this on RC13 and confirmed that the underlying behavior still reproduces with the unpatched RC20 package. The reproduction below requires neither our component library nor JSX.

Minimal reproduction

Install @solidjs/[email protected], save this as repro.mjs, and run node --conditions=development repro.mjs:

import {
  createEffect,
  createMemo,
  createRoot,
  createSignal,
  flush
} from "@solidjs/signals";
import { attribution } from "@solidjs/signals/attribution";

let reads = 0;
let update;

attribution.enable({ log: false });

const dispose = createRoot(dispose => {
  const [version, setVersion] = createSignal(0);
  update = () => setVersion(v => v + 1);

  const record = createMemo(() => {
    version();
    return {
      get children() {
        reads++;
        return "child";
      }
    };
  });

  createEffect(record, () => {});
  return dispose;
});

try {
  flush();
  update();
  flush();
  console.log(reads);
} finally {
  attribution.disable();
  dispose();
}
Expected behavior

reads remains 0: neither the application nor the effect reads children. Enabling development diagnostics should not introduce execution of that lazy getter.

Actual behavior

The example prints 2. Without attribution enabled, it prints 0.

The counting getter demonstrates the unexpected execution without throwing. In the original component previews, the getter performs context-dependent work, so that extra execution can interrupt rendering with an ownership or missing-context error.

Investigation

shallowEquivalent in packages/signals/src/core/attribution.ts compares property values directly. This invokes getters on both the previous and next output. Array-index getters are affected too.

The comparator is shared by UNSTABLE_MEMO_OUTPUT and UNSTABLE_LIST_IDENTITY.

主要言語
TypeScript
スター
36.2k
フォーク
1.1k
平均マージ
11時間 5分
マージ済み PR(30日)
475

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

solidjs/solid のほかの issue

solidjs/solid の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

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

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