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

已关闭
#4,548 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
35/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
活跃
领域
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
平均合并
10 小时 39 分钟
30 天内合并 PR
500

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

solidjs/solid 的其他 Issue

查看 solidjs/solid 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。