Skip to content

Commit f519d15

Browse files
ryansolidClaude via Cursorcursoragent
committed
refactor(solid,signals): boundary records use the core's ownerPath; Reveal onReveal plumbing folds out of prod
- `@solidjs/signals` exports `ownerPath`; the server boundary record uses it instead of a verbatim copy (`ownerLabels`) in solid-js's server observe module. - The Reveal group's `onReveal` hook registration and dispatch are gated on `IS_OBSERVE` so the prod artifact carries neither; a second tier pin in server-boundary-records.spec asserts `onReveal` is absent from server.js and present in server.observe.js / server.dev.js. - Merged origin/next. Co-authored-by: Claude via Cursor <[email protected]> Co-authored-by: Cursor <[email protected]>
1 parent 1910eca commit f519d15

7 files changed

Lines changed: 28 additions & 24 deletions

File tree

‎.changeset/server-boundary-records.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ Server boundary records on `OBSERVE.server.records` (observe/dev tiers)
99
- New `"boundary"` record: one per `<Loading>` boundary that waited during a server render, delivered when it settles — `{ id, at, durationMs, heldMs, passes, outcome: "settled" | "fallback" | "client" | "error", streamed, revealGroup?, ownerPath? }`, with the thrown error beside it. `id` pairs it with `SSR_RENDER_ERROR_CONTAINED`; `passes` counts render passes (a sequential chain reads as `3+`); under a `<Reveal>` group the record waits for the group's swap so `heldMs` measures how long finished content was held for its siblings. No clock is read without a listener, and the emitter folds out of prod.
1010
- The server records channel is `OBSERVE.server.records.subscribe(type, listener)` — the server twin of `OBSERVE.attribution.subscribe(type, …)`. `OBSERVE.server.invocations` (unreleased) is renamed onto it: `subscribe("invocation", …)`. The `InvocationChannel` type is gone; `ServerRecords` is the channel's interface.
1111
- Types now layer one augmenter per interface: `@solidjs/signals` declares `ServerObserve` empty; `solid-js` augments it with `records: ServerRecords` and `trace: ServerTrace`, declaring both; `@solidjs/web` augments those two through `"solid-js"`. `TraceSlot` in `@solidjs/web` is now an alias of `solid-js`'s `ServerTrace`. (Two augmentations of one re-exported interface through different module aliases merge order-dependently in TypeScript — one set was silently lost.)
12+
- `@solidjs/signals` exports `ownerPath(subject)` — the root-first component-label walk its diagnostics already make — so a record's `ownerPath` and the finding it pairs with come from the one walk.

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ export type {
7676
export {
7777
DEV,
7878
OBSERVE,
79+
ownerPath,
7980
type AttributionSlot,
8081
type Dev,
8182
type Observe,

‎packages/signals/src/index.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ export {
2828
clearSnapshots,
2929
enforceLoadingBoundary,
3030
enableExternalSource,
31-
resetErrorHalt
31+
resetErrorHalt,
32+
ownerPath
3233
} from "./core/index.js";
3334
import { DEV as _DEV, OBSERVE as _OBSERVE, type Dev, type Observe } from "./core/index.js";
3435
/**

‎packages/solid/src/server/flow.ts‎

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {
1313
RevealGroupContext
1414
} from "./signals.js";
1515
import { createLoadingBoundary } from "./hydration.js";
16-
import { IS_DEV, devCheck } from "./diagnostics.js";
16+
import { IS_DEV, IS_OBSERVE, devCheck } from "./diagnostics.js";
1717
import { sharedConfig } from "./shared.js";
1818
import type { Accessor, RevealOrder } from "./signals.js";
1919
import type { Element as SolidElement } from "../types.js";
@@ -429,16 +429,16 @@ export function Reveal(props: RevealProps): SolidElement {
429429
}
430430

431431
// Observe tier: a leaf's `onReveal` (see `ServerRevealGroup.register`),
432-
// fired as its swap is issued. Kept off the prod shape — the map exists
433-
// only when a boundary registered one, which only the observe/dev
434-
// boundary does.
432+
// fired as its swap is issued. Only the observe/dev boundary registers
433+
// one, so the plumbing is gated on the tier constant and folds out of the
434+
// prod artifact entirely (the spec pins it), not merely left unallocated.
435435
let revealHooks: Map<string, () => void> | undefined;
436436

437437
// Every leaf swap this group issues goes through here, so the boundary
438438
// behind each key learns the moment it was revealed.
439439
function revealLeaves(leafKeys: string[]) {
440440
ctx.revealFragments?.(leafKeys);
441-
if (revealHooks === undefined) return;
441+
if (!IS_OBSERVE || revealHooks === undefined) return;
442442
for (const key of leafKeys) {
443443
const hook = revealHooks.get(key);
444444
if (hook !== undefined) {
@@ -526,7 +526,9 @@ export function Reveal(props: RevealProps): SolidElement {
526526
keys.push(key);
527527
const isComposite = !!options?.onActivate;
528528
if (isComposite) composites.set(key, options!.onActivate!);
529-
else if (options?.onReveal) (revealHooks ||= new Map()).set(key, options.onReveal);
529+
else if (IS_OBSERVE) {
530+
if (options?.onReveal) (revealHooks ||= new Map()).set(key, options.onReveal);
531+
}
530532
const selfCollapse = order === "sequential" && collapsed && keys.length > 1;
531533
const collapseFallback = collapsedByParent || selfCollapse;
532534
// Track leaf keys that render collapsed so we can emit revealFallbacks

‎packages/solid/src/server/hydration.ts‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ import {
1111
runWithBoundaryErrorContext,
1212
RevealGroupContext
1313
} from "./signals.js";
14+
import { ownerPath } from "@solidjs/signals";
1415
import { sharedConfig, NoHydrateContext } from "./shared.js";
1516
import { IS_OBSERVE, emitFinding, errorText } from "./diagnostics.js";
1617
import {
1718
deliverRecord,
18-
ownerLabels,
1919
recordListeners,
2020
type BoundaryEvent,
2121
type BoundaryLive
@@ -128,7 +128,10 @@ function ssrLoadingBoundary(
128128
streamed
129129
};
130130
if (revealGroup) event.revealGroup = revealGroup.id;
131-
const path = ownerLabels(o);
131+
// The core's walk (`_parent` + `_name`), the same one its diagnostics
132+
// make over these owners, so the record and the finding it may pair with
133+
// locate to the same `<App> › <Page>`.
134+
const path = ownerPath(o);
132135
if (path) event.ownerPath = path;
133136
const live: BoundaryLive = {};
134137
if (outcome === "error") live.error = error;

‎packages/solid/src/server/observe.ts‎

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -99,21 +99,6 @@ export function deliverRecord(listeners: Set<Function>, record: unknown, live: u
9999
}
100100
}
101101

102-
/**
103-
* Root-first component labels enclosing `owner` — the `ownerPath` a record
104-
* carries, the same walk (`_parent` + `_name`) the core's diagnostics make
105-
* over these owners, so a boundary record and the finding it may pair with
106-
* locate to the same `<App> › <Page>`.
107-
*/
108-
export function ownerLabels(owner: { _parent: any; _name?: string } | null): string[] | undefined {
109-
const path: string[] = [];
110-
for (let o = owner; o !== null; o = o._parent) {
111-
const name = o._name;
112-
if (typeof name === "string" && name.length) path.push(name);
113-
}
114-
return path.length ? path.reverse() : undefined;
115-
}
116-
117102
/**
118103
* One `<Loading>` boundary that WAITED during a server render — discovered
119104
* with pending async, then settled — delivered on

‎packages/web/test/server/server-boundary-records.spec.tsx‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -466,4 +466,15 @@ describe("tiers, in the built artifacts", () => {
466466
expect(read("server.observe.js")).toContain(marker);
467467
expect(read("server.dev.js")).toContain(marker);
468468
});
469+
470+
test("the Reveal group's onReveal plumbing folds out of prod with it", () => {
471+
const read = (name: string) =>
472+
readFileSync(resolve(import.meta.dirname, "../../../solid/dist", name), "utf8");
473+
// The hook is registered under this option name and read back from the
474+
// group's map; prod has no boundary that registers one, so the tier
475+
// gate takes both out of the artifact.
476+
expect(read("server.js")).not.toContain("onReveal");
477+
expect(read("server.observe.js")).toContain("onReveal");
478+
expect(read("server.dev.js")).toContain("onReveal");
479+
});
469480
});

0 commit comments

Comments
 (0)