Skip to content

Commit eb50c94

Browse files
committed
Merge remote-tracking branch 'origin/next' into fix/fresh-boundary-child-held-u1
2 parents 61c4436 + 8a5b3e3 commit eb50c94

32 files changed

Lines changed: 511 additions & 44 deletions
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@solidjs/web": patch
3+
---
4+
5+
fix(frames): a link inside nested slot regions is claimed once per adoption instead of once per enclosing region, and a streaming document whose server components mint no tier writes an empty `sc:tiers` record so the client skips its per-element slot-marker scan
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@solidjs/signals": patch
3+
---
4+
5+
Attribution: `createProjection` records the owner in scope as `createStore` does, so a projection's property nodes carry an owner path (#4035). The `GRAPH_GROWTH` message and its skill section now name a cache that never evicts as a source of the same growth.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@solidjs/web": patch
3+
---
4+
5+
Bind each server-component site to its own frame when the server minted the sites in a different order than the client mounts them (#4042). Document adoption took sites of one server function by ordinal (`id`, `id~2`, …), so a site behind async setup, rendered after its neighbours on the server but mounted first on the client, adopted a neighbour's element, and its first update landed in the wrong frame. A document frame for a call with arguments now carries the call's argument hash (`data-fa`), and a mount takes the unclaimed site showing its own arguments, falling back to the first unclaimed site when none does. Argless calls render byte-identical markup.

‎documentation/solid-2.0/08-dev-diagnostics.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,7 @@ Related: `WIDE_SCOPE_DEPS` (below) fires at a lower threshold, but only while th
428428

429429
#### `GRAPH_GROWTH`
430430

431-
**Message:** "the live graph grew on 3 consecutive visits to `/orders`, and so did the part that outlived each navigation there: computations 880 → 883 → 886 (of 900 → 903 → 906); edges 880 → 883 → 886 (of 900 → 903 → 906) (2 roots), across visits to `/orders`, `/`. Each visit left something behind that the next did not reclaim — the shape says an effect or memo created with no owner (a module-level or callback `createEffect`) that only its sources keep alive. Dispose what a visit creates (`onCleanup`, or return the disposer from `onSettled`) and own it under the route's component so leaving the route tears it down."
431+
**Message:** "the live graph grew on 3 consecutive visits to `/orders`, and so did the part that outlived each navigation there: computations 880 → 883 → 886 (of 900 → 903 → 906); edges 880 → 883 → 886 (of 900 → 903 → 906) (2 roots), across visits to `/orders`, `/`. Each visit left something behind that the next did not reclaim — the shape says an effect or memo created with no owner (a module-level or callback `createEffect`) that only its sources keep alive. Dispose what a visit creates (`onCleanup`, or return the disposer from `onSettled`) and own it under the route's component so leaving the route tears it down. A cache that never evicts grows alike."
432432

433433
Attribution-engine only; the leak class a heap snapshot finds, as a finding. At every navigation's settle (`withOrigin({ kind: "navigation" })`) the engine measures the live graph with a **walk**, never a per-node counter: the owner tree from the registered top-level roots (`owners`: roots, component owners, owned computations), then everything reachable from it through the reactive graph — each computation's dependency links (`edges`) and the `signals` and computations they reach, and each reached node's subscriber list, which is how a computation **no owner holds** (a `createEffect` with no owner, kept alive only by the sources it reads) is found and counted in `computations`. It emits a `graph` record (`GraphEvent`: the `GraphSize` fields plus `at`, `route`, `navigation`) for an `OBSERVE.records.subscribe("graph", …)` listener, and keeps the size at each settle of the same route. A count taken at an arrival also holds everything that visit just created, so a page whose correctly owned content is bigger on each visit (`/rows/1`, `/rows/3`, `/rows/5`) climbs too, although leaving it disposes everything. So the engine also counts what **outlived** each navigation: while the check is on, a non-initial navigation walks the graph once more as it opens, adding every node it meets to a `WeakSet`, and its settle's walk counts the nodes from that set still alive (an edge counts when both its ends are), then drops the set. A visit's own content is not among them; a root, an ownerless effect or a retained signal an earlier visit left behind is, whatever the content does. When any series — `owners`, `computations`, `signals`, `edges` — has climbed on `graphGrowth.visits` consecutive visits (default 3) to `ratio` or more of the first (default 1.25), both in the totals and in what outlived each navigation, the route reports, and _which_ series climbed names the leak: `owners` is an undisposed root or a Portal per visit; `computations` with `owners` flat is an ownerless effect; `edges` alone is a subscription per visit to something long-lived. The count is the whole graph's, so a leak shows at every route's settle: the first route to complete its climb reports and `data.routes` names the others seen; the verdict then resets. `data`: `route`, `grew` (the series that climbed), `history` (the `GraphSize` at each settle, oldest first), `survived` (the `GraphSize` of what outlived each of those navigations — alive when it opened and still alive at its settle — beside `history`), `roots`, `routes`, `interaction`. No subject.
434434

‎packages/signals/src/core/attribution.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3293,7 +3293,7 @@ function trackGraph(state: NavState): void {
32933293
`(${size.roots} roots)${routes.length > 1 ? `, across visits to ${routes.join(", ")}` : ""}. Each ` +
32943294
`visit left something behind that the next did not reclaim — the shape says ${shape}. Dispose ` +
32953295
`what a visit creates (onCleanup, or return the disposer from onSettled) and own it under the ` +
3296-
`route's component so leaving the route tears it down.`;
3296+
`route's component so leaving the route tears it down. A cache that never evicts grows alike.`;
32973297
const data: Record<string, unknown> = {
32983298
route,
32993299
grew,

‎packages/signals/src/store/projection.ts‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
* (uninitialized / pending / errored) and the reader's height, by the
1717
* rules a memo's read follows. No per-leaf back-pointer, nothing in core.
1818
*/
19+
import { attrHooks } from "../core/attribution-hooks.js";
1920
import { CONFIG_AUTO_DISPOSE, STATUS_PENDING, STATUS_UNINITIALIZED } from "../core/constants.js";
2021
import { computed } from "../core/core.js";
2122
import { NotReadyError } from "../core/error.js";
@@ -33,7 +34,7 @@ import type { Computed, Signal } from "../core/types.js";
3334
import type { Refreshable } from "../core/index.js";
3435
import { reconcileState } from "./reconcile.js";
3536
import { nameStore, runDirect, storeSetter, wrap } from "./store.js";
36-
import { setLookup, type StoreFamily, type StoreTarget } from "./target.js";
37+
import { setLookup, storeOwners, type StoreFamily, type StoreTarget } from "./target.js";
3738
import {
3839
$TARGET,
3940
isWrappable,
@@ -326,6 +327,10 @@ function createProjectionInternal<T extends object = {}>(
326327
}
327328
let nodeOptions: { name?: string; loadingValue?: void } | undefined;
328329
if (options?.seedLoadingValue) nodeOptions = { loadingValue: undefined };
330+
if (__OBSERVE__ && attrHooks !== null)
331+
// As createStore: the owner in scope stamps the projection's property
332+
// nodes, so attribution places them under it (#4035).
333+
storeOwners!.set((store as any)[$TARGET] as StoreTarget, getOwner());
329334
if (__OBSERVE__ && options?.name) {
330335
nodeOptions = { ...nodeOptions, name: options.name };
331336
nameStore(store, options.name);
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/**
2+
* solidjs/solid#4035 — `createStore` records the owner in scope so its
3+
* property nodes carry an owner path; `createProjection` did not, so a
4+
* projection's nodes had none: attribution could not place them under the
5+
* component that made them, and the graph walk could not tell whose they
6+
* were. A projection now records it as a store does.
7+
*/
8+
import { afterEach, describe, expect, it } from "vitest";
9+
import { attribution } from "../src/attribution.js";
10+
import {
11+
createMemo,
12+
createProjection,
13+
createRoot,
14+
createStore,
15+
flush,
16+
getOwner
17+
} from "../src/index.js";
18+
import { ownerPath } from "../src/core/dev.js";
19+
20+
afterEach(() => {
21+
attribution.disable();
22+
flush();
23+
});
24+
25+
const nameOwner = (name: string) => ((getOwner() as any)._name = name);
26+
27+
/** The property node `read` subscribes to, found through its reader's deps. */
28+
function propertyNode(read: () => unknown): any {
29+
let reader: any;
30+
createMemo(() => {
31+
reader = getOwner();
32+
return read();
33+
})();
34+
return reader._deps._dep;
35+
}
36+
37+
describe("a projection's property nodes carry the owner it was created under (#4035)", () => {
38+
it("as a store's do", () => {
39+
attribution.enable({ log: false });
40+
let storeNode: any;
41+
let projectionNode: any;
42+
const dispose = createRoot(dispose => {
43+
nameOwner("<Cache>");
44+
const [store] = createStore({ value: 1 });
45+
const projection = createProjection<{ value: number }>(
46+
draft => {
47+
draft.value = 2;
48+
},
49+
{ value: 0 }
50+
);
51+
storeNode = propertyNode(() => store.value);
52+
projectionNode = propertyNode(() => projection.value);
53+
return dispose;
54+
});
55+
flush();
56+
expect(ownerPath(storeNode)).toEqual(["<Cache>"]);
57+
expect(ownerPath(projectionNode)).toEqual(["<Cache>"]);
58+
dispose();
59+
});
60+
});

‎packages/solid/skills/reactivity-diagnostics/SKILL.md‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,10 @@ culprit is on one of them. Look for, in order:
319319
pair it with `onCleanup`.
320320
- A `Portal`, a panel or a modal mounted on each visit into a long-lived
321321
root, never removed when the route leaves.
322+
- A cache (entities kept by key, each under its own root) that only ever
323+
adds. Its entries outlive every navigation, so to the walk it is the same
324+
growth as a leak, and it is: memory that never comes back. Bound it or
325+
evict entries no visit still reads; an evicting cache stays quiet.
322326

323327
Do NOT reach for `dispose()` on the app root or a periodic sweep; the fix is
324328
ownership — create the thing under the owner whose lifetime it should share.

‎packages/web/frames/src/client.ts‎

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1093,15 +1093,25 @@ function indexBoundaries(root: ParentNode) {
10931093
if (key && isBoundaryId(key) && !boundaryIndex!.has(key)) boundaryIndex!.set(key, el);
10941094
});
10951095
}
1096-
function findBoundaryElement(id: string): Element | undefined {
1096+
function findBoundaryElement(id: string, address?: string): Element | undefined {
10971097
if (!boundaryIndex) {
10981098
boundaryIndex = new Map();
10991099
if (typeof document !== "undefined" && document.body) indexBoundaries(document.body);
11001100
}
11011101
// Later sites of one factory (#3889) are `<id>~n`, probed in mint order.
1102+
// Mint order is the server's, not the client's mount order: a site behind
1103+
// async setup mints after its neighbours on the server but mounts first
1104+
// here (#4042). So a mount that knows its call takes the unclaimed site
1105+
// showing its arguments (`data-fa`), and the first unclaimed site when
1106+
// none does.
1107+
const args = address && address.slice(id.length + 1);
1108+
let first: Element | undefined, el: Element | undefined;
11021109
for (let n = 0; ; n++) {
11031110
const key = n ? id + "~" + (n + 1) : id;
1104-
if (!claimedBoundaries.has(key)) return boundaryIndex.get(key);
1111+
if (claimedBoundaries.has(key)) continue;
1112+
if (!(el = boundaryIndex.get(key)) || !args || (el as HTMLElement).dataset.fa == args)
1113+
return el || first;
1114+
first = first || el;
11051115
}
11061116
}
11071117

@@ -1246,7 +1256,8 @@ function documentBoundary(
12461256
// client entry's installServerComponents() call — re-attempt here, where
12471257
// hydration is necessarily live (idempotent via the $sc flag).
12481258
installRevealHook();
1249-
const el = findBoundaryElement(id);
1259+
const address = binding && contentAddress(binding());
1260+
const el = findBoundaryElement(id, address);
12501261
if (el) return adoptBoundary(host, id, el, props, binding);
12511262
// Not in the page (yet). While the page can still deliver it (the document is
12521263
// streaming, or a deferred fragment is still holding its markup — see
@@ -1276,7 +1287,7 @@ function documentBoundary(
12761287
() =>
12771288
live &&
12781289
runWithOwner(owner, () => {
1279-
const node = findBoundaryElement(id);
1290+
const node = findBoundaryElement(id, address);
12801291
// No element after all (the page ran out of reveals, or another
12811292
// mount took it): mount fresh, exactly as an unwaited miss would.
12821293
return node

‎packages/web/frames/src/frame-client.ts‎

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -482,22 +482,40 @@ function claimHandlers() {
482482
return handlers !== undefined && handlers.length !== 0 ? handlers : undefined;
483483
}
484484

485-
/** Fire every handler on one element unconditionally. */
486-
function claimNode(handlers, el) {
485+
/**
486+
* Fire every handler on one element. `adopter`, on the adoption path only,
487+
* is the frame adopting it: an element a live frame's adoption sweep already
488+
* claimed is skipped (see `adoptedBy`).
489+
*/
490+
function claimNode(handlers, el, adopter?: object) {
491+
if (adopter) {
492+
const by = adoptedBy.get(el);
493+
if (by && liveFrames.has(by)) return;
494+
adoptedBy.set(el, adopter);
495+
}
487496
for (let i = 0; i < handlers.length; i++) handlers[i](el);
488497
}
489498

490499
const claimedAttr = name => name === "href" || name === "action";
491500

492501
/** Sweep `root` (element or fragment) and its claimable interior. */
493-
function claimTree(handlers, root) {
502+
function claimTree(handlers, root, adopter?: object) {
494503
const isElement = root.nodeType === ELEMENT_NODE;
495504
if (!isElement && root.nodeType !== 11 /* DOCUMENT_FRAGMENT_NODE */) return;
496-
if (isElement && root.matches(CLAIMED_ELEMENTS)) claimNode(handlers, root);
505+
if (isElement && root.matches(CLAIMED_ELEMENTS)) claimNode(handlers, root, adopter);
497506
const found = root.querySelectorAll(CLAIMED_ELEMENTS);
498-
for (let i = 0; i < found.length; i++) claimNode(handlers, found[i]);
507+
for (let i = 0; i < found.length; i++) claimNode(handlers, found[i], adopter);
499508
}
500509

510+
// Which frame's adoption sweep claimed an element. A region's interior is
511+
// inside its enclosing frame's range, so the enclosing frame's sweep already
512+
// claimed it, and the frame bound over the region would claim it again (at
513+
// depth N, N+1 times). While the claiming frame lives, its claim stands;
514+
// once it is disposed, a later adoption claims again. Changes to an element
515+
// reach consumers through the morph, directly or as new fragments, which
516+
// never pass an adopter.
517+
const adoptedBy = new WeakMap<Element, object>();
518+
501519
/** Fragment placeholder start: `<template id="pl-KEY">` (content = fallback). */
502520
const placeholderId = name => `pl-${name}`;
503521

@@ -1277,10 +1295,10 @@ class FrameImpl {
12771295
// recheck, which must fire on `href`/`action` REMOVAL too (the element no
12781296
// longer matches the sweep selector), mirroring compiled setAttribute.
12791297
// Stable identity so it threads into the morph without allocation.
1280-
#claimTree = (node, direct) => {
1298+
#claimTree = (node, direct?, adopter?) => {
12811299
const handlers = claimHandlers();
12821300
if (!handlers) return;
1283-
this.#scoped(() => (direct ? claimNode(handlers, node) : claimTree(handlers, node)));
1301+
this.#scoped(() => (direct ? claimNode(handlers, node) : claimTree(handlers, node, adopter)));
12841302
};
12851303

12861304
/** Run `fn` under the creator's `ownerScope` (when provided). */
@@ -2236,7 +2254,7 @@ class FrameImpl {
22362254

22372255
/** Sweep-claim the frame's existing content (the adoption path). */
22382256
#claimContent() {
2239-
for (let n = this.#element.firstChild; n; n = n.nextSibling) this.#claimTree(n);
2257+
for (let n = this.#element.firstChild; n; n = n.nextSibling) this.#claimTree(n, false, this);
22402258
}
22412259

22422260
/**

0 commit comments

Comments
 (0)