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

Chiusa
#4,548 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
35/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
javascript, typescript
Ambito
devtools

Direzione di ricerca

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.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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.

Lingua principale
TypeScript
Stelle
36.2k
Fork
1.1k
Merge medio
10h 39m
PR unite (30g)
500

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di solidjs/solid

Tutte le issue di solidjs/solid

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.