From d60fa3b50739421c938ed15aaed78a74ab0e9258 Mon Sep 17 00:00:00 2001 From: Dev Agrawal Date: Tue, 24 Nov 2026 22:25:54 -0600 Subject: [PATCH] fix: keep the devtools' own reads of the app out of Health The graph and the tree read runtime node fields such as `_flags` and `_time`. The runtime lists a store's proxy beside plain signals, so those reads went through the proxy, and inside a strict-read scope of the app, such as an effect callback, each one was reported as STRICT_READ_UNTRACKED against the app. The registry walks, the change counters and the dev-hook listeners now run in `quietly`, which reads through Solid's `untrack` (it closes the strict-read window) and marks the read as the devtools'. Health drops anything the runtime reports while such a read runs. Co-Authored-By: Claude Opus 5.5 --- .changeset/quiet-devtools-reads.md | 5 ++ src/dev-toolbar/dev-hooks.ts | 15 +++- src/dev-toolbar/issues/tracker.ts | 3 + src/dev-toolbar/ownership/registry.ts | 4 ++ src/dev-toolbar/quiet.dev.test.ts | 78 +++++++++++++++++++++ src/dev-toolbar/quiet.ts | 30 ++++++++ src/dev-toolbar/reactivity/registry.test.ts | 1 + src/dev-toolbar/reactivity/registry.ts | 15 ++-- 8 files changed, 144 insertions(+), 7 deletions(-) create mode 100644 .changeset/quiet-devtools-reads.md create mode 100644 src/dev-toolbar/quiet.dev.test.ts create mode 100644 src/dev-toolbar/quiet.ts diff --git a/.changeset/quiet-devtools-reads.md b/.changeset/quiet-devtools-reads.md new file mode 100644 index 0000000..ba314d4 --- /dev/null +++ b/.changeset/quiet-devtools-reads.md @@ -0,0 +1,5 @@ +--- +'@solidjs/start-devtools': patch +--- + +The devtools' own reads of the app no longer fill the Health view with `STRICT_READ_UNTRACKED` warnings about `_flags`, `_time`, `_subs` and `_config`. The graph and the tree read node fields, and on a store those reads went through its proxy. Inside a strict-read scope of the app, such as an effect callback, the runtime reported each one as the app's. The devtools now read the app untracked, and Health leaves out anything the runtime reports while they do. diff --git a/src/dev-toolbar/dev-hooks.ts b/src/dev-toolbar/dev-hooks.ts index 9345e74..149e649 100644 --- a/src/dev-toolbar/dev-hooks.ts +++ b/src/dev-toolbar/dev-hooks.ts @@ -1,4 +1,5 @@ import { DEV } from 'solid-js'; +import { quietly } from './quiet.js'; /** The dev hooks of solid-js the toolbar uses. */ export interface DevHooksSlot { @@ -37,17 +38,25 @@ export function createDevHooksHub(slot: DevHooksSlot): DevHooksHub { onUpdate: slot.onUpdate, }; original = found; + // The hooks run inside the app, often in a component body, so the + // listeners read quietly: what they read is not the app's doing. slot.onOwner = (owner) => { found.onOwner?.(owner); - for (const listener of listeners) listener.onOwner?.(owner); + quietly(() => { + for (const listener of listeners) listener.onOwner?.(owner); + }); }; slot.onGraph = (value, owner) => { found.onGraph?.(value, owner); - for (const listener of listeners) listener.onGraph?.(value, owner); + quietly(() => { + for (const listener of listeners) listener.onGraph?.(value, owner); + }); }; slot.onUpdate = () => { found.onUpdate?.(); - for (const listener of listeners) listener.onUpdate?.(); + quietly(() => { + for (const listener of listeners) listener.onUpdate?.(); + }); }; } diff --git a/src/dev-toolbar/issues/tracker.ts b/src/dev-toolbar/issues/tracker.ts index 99eef82..5652ffc 100644 --- a/src/dev-toolbar/issues/tracker.ts +++ b/src/dev-toolbar/issues/tracker.ts @@ -1,4 +1,5 @@ import { OBSERVE } from 'solid-js'; +import { isQuiet } from '../quiet.js'; /** One finding of the runtime's diagnostics channel, as `OBSERVE.diagnostics` delivers it. */ export interface IssueEvent { @@ -118,6 +119,8 @@ export function captureIssues( if (!diagnostics) return () => {}; let pending: { event: IssueEvent; subject: object | undefined; at: number }[] = []; return diagnostics.subscribe((event, subject) => { + // The devtools' own reads of the app are not the app's findings. + if (isQuiet()) return; if (!pending.length) { queueMicrotask(() => { const batch = pending; diff --git a/src/dev-toolbar/ownership/registry.ts b/src/dev-toolbar/ownership/registry.ts index ddaa102..738882b 100644 --- a/src/dev-toolbar/ownership/registry.ts +++ b/src/dev-toolbar/ownership/registry.ts @@ -1,5 +1,6 @@ import { DEV } from 'solid-js'; import { listenToDevHooks } from '../dev-hooks.js'; +import { quietly } from '../quiet.js'; import { isSolidBuiltin } from './builtins.js'; import { buildOwnershipTree, EMPTY_TREE, type OwnershipTree, type RawNode } from './tree.js'; @@ -172,7 +173,10 @@ export interface SnapshotOptions { */ export function snapshotOwnershipTree(options?: SnapshotOptions): OwnershipTree { if (!isOwnershipAvailable()) return EMPTY_TREE; + return quietly(() => readTree(options)); +} +function readTree(options?: SnapshotOptions): OwnershipTree { const roots = new Set(); if (seedOwner) roots.add(rootOf(seedOwner)); for (const ref of tracked) { diff --git a/src/dev-toolbar/quiet.dev.test.ts b/src/dev-toolbar/quiet.dev.test.ts new file mode 100644 index 0000000..ceea8c9 --- /dev/null +++ b/src/dev-toolbar/quiet.dev.test.ts @@ -0,0 +1,78 @@ +import { + createEffect, + createRoot, + createSignal, + createStore, + flush, + OBSERVE, + untrack, +} from 'solid-js'; +import { afterEach, describe, expect, it } from 'vitest'; +import { captureIssues, type IssueEvent } from './issues/tracker.js'; +import { snapshotOwnershipTree, startOwnershipTracking } from './ownership/registry.js'; +import { quietly } from './quiet.js'; +import { snapshotReactivityGraph, startReactivityTracking } from './reactivity/registry.js'; + +// The label the runtime gives an untracked read it warns about, as in a component body. +const COMPONENT_BODY = 'a component body'; + +function strictReads(): string[] { + const names: string[] = []; + stops.push( + OBSERVE!.diagnostics.subscribe((event) => { + if (event.code === 'STRICT_READ_UNTRACKED') names.push(event.nodeName ?? ''); + }), + ); + return names; +} + +const stops: (() => void)[] = []; +afterEach(() => { + while (stops.length) stops.pop()!(); +}); + +describe('the devtools reading the app', () => { + it('raise no strict-read findings, even in an app effect callback', () => { + stops.push(startReactivityTracking(), startOwnershipTracking()); + const reads = strictReads(); + const [count, setCount] = createSignal(0); + createRoot((dispose) => { + stops.push(dispose); + untrack(() => { + // The runtime lists the store's proxy beside the plain signals. + const [state] = createStore({ items: [1, 2], label: 'x' }); + createEffect( + () => count(), + () => { + // An effect callback is a strict-read scope. Reading the node fields + // through the store's proxy here used to report `_flags`, `_time`... + snapshotReactivityGraph(); + snapshotOwnershipTree(); + void state; + }, + ); + }, COMPONENT_BODY); + }); + flush(); + setCount(1); + flush(); + expect(reads).toEqual([]); + }); + + it('leave what the runtime reports during a devtools read out of Health', async () => { + const [state] = createRoot(() => createStore({ label: 'x' })); + const captured: IssueEvent[] = []; + stops.push(captureIssues((added) => captured.push(...added.map((entry) => entry.event)))); + const reads = strictReads(); + + // A strict-read scope opened inside a devtools read still reports to the + // console, but it is not the app's finding. + quietly(() => untrack(() => state.label, COMPONENT_BODY)); + // The same read by the app is. + untrack(() => state.label, COMPONENT_BODY); + await Promise.resolve(); + + expect(reads).toEqual(['label', 'label']); + expect(captured.map((event) => event.nodeName)).toEqual(['label']); + }); +}); diff --git a/src/dev-toolbar/quiet.ts b/src/dev-toolbar/quiet.ts new file mode 100644 index 0000000..dacb4ff --- /dev/null +++ b/src/dev-toolbar/quiet.ts @@ -0,0 +1,30 @@ +import { untrack } from 'solid-js'; + +/** + * The devtools read the app's runtime nodes field by field, such as `_flags` + * and `_time`. A store hands out proxies, and the runtime lists them beside + * plain signals, so the same field reads go through the store's proxy. In a + * strict-read scope, such as an effect callback of the app, the runtime then + * reports `STRICT_READ_UNTRACKED` for every field, as if the app had read it. + * + * `untrack` is the runtime's own way to mark a deliberate one-time read: it + * closes the strict-read window. While it runs, the toolbar also leaves out + * whatever the runtime reports, so the Health view never counts findings the + * devtools caused. + */ +let depth = 0; + +/** Runs a devtools read of the app untracked, with its findings left out of Health. */ +export function quietly(read: () => T): T { + depth++; + try { + return untrack(read); + } finally { + depth--; + } +} + +/** Whether a devtools read is running now. */ +export function isQuiet(): boolean { + return depth > 0; +} diff --git a/src/dev-toolbar/reactivity/registry.test.ts b/src/dev-toolbar/reactivity/registry.test.ts index 145c82d..b254b24 100644 --- a/src/dev-toolbar/reactivity/registry.test.ts +++ b/src/dev-toolbar/reactivity/registry.test.ts @@ -19,6 +19,7 @@ vi.mock('solid-js', () => ({ get DEV() { return runtime.DEV; }, + untrack: (read: () => T): T => read(), })); describe('registry without the dev runtime', () => { diff --git a/src/dev-toolbar/reactivity/registry.ts b/src/dev-toolbar/reactivity/registry.ts index cc5f995..6b072c1 100644 --- a/src/dev-toolbar/reactivity/registry.ts +++ b/src/dev-toolbar/reactivity/registry.ts @@ -1,5 +1,6 @@ import { DEV } from 'solid-js'; import { listenToDevHooks } from '../dev-hooks.js'; +import { quietly } from '../quiet.js'; // Flag bits used by @solidjs/signals. They are internal to the runtime, so the // values are copied here and every read is defensive. @@ -186,10 +187,12 @@ export function startReactivityTracking(): () => void { */ function recordUpdates(): void { if (tracked.size > STATS_LIMIT) return; - for (const ref of tracked) { - const node = ref.deref(); - if (node) statsOf(node); - } + quietly(() => { + for (const ref of tracked) { + const node = ref.deref(); + if (node) statsOf(node); + } + }); } /** Drops one watcher. Stops listening once nothing watches any more. */ @@ -420,6 +423,10 @@ export interface SnapshotOptions { */ export function snapshotReactivityGraph(options?: SnapshotOptions): ReactiveGraph { if (!isReactivityAvailable()) return EMPTY_GRAPH; + return quietly(() => readGraph(options)); +} + +function readGraph(options?: SnapshotOptions): ReactiveGraph { const includeDisposed = options?.includeDisposed ?? false; const queue: RawNode[] = [];