Skip to content

Commit a36b9f6

Browse files
feat(compiler,babel-plugin,solid): componentNames for SSR output; ssrScope swaps the id-bearing owner
The SSR generate honours `componentNames` the way `dom` does. Under the option both compilers keep the `createComponent` call they otherwise inline to `Comp(props)` and pass the source tag text — `_$createComponent(Comp, props, "Comp")` — so the server runtime's observe/dev `createComponent` (a transparent, labelled owner around the body, #3433) labels every compiled component and a server finding's `ownerPath` reads `<App> › <Page>` like the client's. Without the option SSR still inlines: prod output is byte-identical. Universal and dynamic stay unlabelled. `@solidjs/vite-plugin` already passes the option for its dev and observe postures for every generate, so app server builds pick this up with no config change. Oxc's `jsx_tag_name` is now a shared, closure-based helper so the SSR lowering reuses it (`this.Row` through the `_self$` pre-pass, member tags). The `ssrInert` fixture becomes `ssr`, widened to the DOM fixture's shapes; the Oxc suite pins that SSR without the option imports no `createComponent`. Compiling the web server suite with the option (vite.config.server.mjs — the dev posture) surfaced a latent `ssrScope` bug: the virtual hole scope swapped the CURRENT owner's `id`/`_childCount`, but content inside a hole resolves ids by walking up past transparent owners, so with one in between the reserved slot was invisible and the hole's content took fresh ids from the enclosing counter (`_hk=3` where the client expects `_hk=10`). Reachable in prod today through `runInServerComponentScope` (transparent), ubiquitous once every component body runs under a labelled owner. The scope now swaps the nearest id-bearing owner (solid/test/server/ssr-scope.spec.ts covers a plain transparent owner, the server-component scope, the labelled component owner, and nesting). server-diagnostics.spec.tsx drops its `mount()` workaround for plain JSX; boundaries are compiled components too, so a boundary's finding now locates as `<App> › <Errored>` / `<App> › <Loading>` — as on the client. Server, hydrate and client suites pass under the native compiler and JSX_COMPILER=babel. Co-authored-by: Cursor <[email protected]>
1 parent c452850 commit a36b9f6

23 files changed

Lines changed: 458 additions & 92 deletions

File tree

‎.changeset/ssr-component-names.md‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
"@solidjs/babel-plugin": patch
3+
"@solidjs/compiler": patch
4+
"solid-js": patch
5+
---
6+
7+
`componentNames` now applies to SSR output. Under the option both compilers keep the `createComponent` call they otherwise inline to `Comp(props)` and pass the source tag name — `createComponent(Comp, props, "Comp")` — so the server runtime's observe/dev `createComponent` labels the owner and a server finding's `ownerPath` reads `<App> › <Page>` like the client's. Without the option (prod builds) SSR output is unchanged. `@solidjs/vite-plugin` already passes the option for its dev and observe postures, so app server builds pick this up with no config change.
8+
9+
Fixes `ssrScope` under transparent owners: the virtual hole scope swapped the current owner's id counter, but content inside a hole resolves ids by walking past transparent owners, so with one in between (the server-component scope owner; now the labelled component owner) the hole's content took ids from the enclosing counter and disagreed with the client. The scope now swaps the nearest id-bearing owner.

‎documentation/plans/server-dev-build-plan.md‎

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -196,13 +196,31 @@ Decision: **reuse `@solidjs/signals`'s channel, do not fork it.**
196196
> `packages/web/test/frames-marker-corruption.spec.tsx`. Docs: RFC 08
197197
> "Server rendering" + quick reference; the reactivity-diagnostics skill.
198198
>
199-
> Known gap, deliberately out of this PR: the SSR compiler inlines component
200-
> calls (`Comp({})`) instead of `createComponent`, so compiled JSX does not
201-
> get the label — `ownerPath` is populated for `createComponent` callers
202-
> (the runtime's own flow components, `Dynamic`, tests) and empty for a
203-
> plain compiled `<Comp/>` tree. The fix is the compiler emitting
204-
> `createComponent` under the `componentNames` option for SSR output as it
205-
> does for the client; tracked separately.
199+
> Known gap at the time, closed in the follow-up (2026-09-14): the SSR
200+
> compiler inlined component calls (`Comp({})`) instead of `createComponent`,
201+
> so compiled JSX did not get the label — `ownerPath` was populated for
202+
> `createComponent` callers (the runtime's own flow components, `Dynamic`,
203+
> tests) and empty for a plain compiled `<Comp/>` tree. Both compilers now
204+
> honour `componentNames` for the `ssr` generate the way they do for `dom`:
205+
> the output keeps `createComponent(Comp, props, "Comp")` (the label has
206+
> nowhere else to go; the prod server `createComponent` is that same
207+
> `Comp(props)` call plus one frame), and without the option SSR still
208+
> inlines. The vite plugin already passes `componentNames` for its dev and
209+
> observe postures, so an app's server build labels every compiled component
210+
> in exactly the builds whose runtime reads the argument; prod output is
211+
> byte-identical to before. Boundaries are compiled components too, so a
212+
> server finding raised by a boundary reads `<App> › <Errored>` — as on the
213+
> client. Landing this surfaced a latent `ssrScope` bug: the virtual hole
214+
> scope swapped the CURRENT owner's `id`/`_childCount`, but content inside
215+
> the hole resolves ids by walking up past transparent owners — so with a
216+
> transparent owner in between (the server-component scope owner in every
217+
> tier; now the labelled `<Name>` owner under every component body) the
218+
> reserved slot was invisible and the hole's content took fresh ids from the
219+
> enclosing counter (`_hk=3` where the client expects `_hk=10`). The scope
220+
> now swaps the nearest id-bearing owner
221+
> (`packages/solid/test/server/ssr-scope.spec.ts`). The web server suite
222+
> compiles with `componentNames` (`vite.config.server.mjs`), so its
223+
> hydration-id and diagnostics specs run against the labelled shape.
206224
207225
- The server facade imports `DEV` (and the `emitDiagnostic` /
208226
`DiagnosticEvent` types) from `@solidjs/signals`, every use behind

‎packages/babel-plugin/README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ Development output. With `hydratable`, emits the hydration walk validation helpe
132132
- Type: `boolean`
133133
- Default: `false`
134134

135-
DOM output only. Emit the tag as written in source as a third `createComponent` argument — `<Home />` compiles to `createComponent(Home, props, "Home")`, `<Ui.Button />` to `"Ui.Button"` — so the dev and observe runtimes label each component's owner (`<Home>` in diagnostic `ownerPath`s and attribution chains) even after a minifier renames the function or a `lazy()`/HMR wrapper hides it. The production runtime ignores the argument; SSR and universal output are unaffected. `@solidjs/vite-plugin` turns this on for its dev and `observe` postures.
135+
Emit the tag as written in source as a third `createComponent` argument — `<Home />` compiles to `createComponent(Home, props, "Home")`, `<Ui.Button />` to `"Ui.Button"` — so the dev and observe runtimes label each component's owner (`<Home>` in diagnostic `ownerPath`s and attribution chains) even after a minifier renames the function or a `lazy()`/HMR wrapper hides it. Applies to DOM and SSR output; for SSR the compiler keeps the `createComponent` call it otherwise inlines to `Comp(props)`, so the server runtime labels the owner the same way (prod SSR output, without the option, is unchanged). Universal and dynamic output are unaffected. The production runtimes ignore the argument. `@solidjs/vite-plugin` turns this on for its dev and `observe` postures.
136136

137137
### delegateEvents
138138

‎packages/babel-plugin/src/config.ts‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@ export interface PluginConfig {
1818
dev: boolean;
1919
/** Emit the source tag name as a third `createComponent` argument
2020
* (`createComponent(Home, props, "Home")`) so dev/observe runtimes can
21-
* label owners after minification renames the function. DOM output only;
22-
* the production runtime ignores the argument. */
21+
* label owners after minification renames the function. DOM and SSR
22+
* output (SSR keeps the `createComponent` call it would otherwise inline
23+
* to `Comp(props)`); not universal or dynamic. The production runtimes
24+
* ignore the argument. */
2325
componentNames: boolean;
2426
delegateEvents: boolean;
2527
delegatedEvents: string[];

‎packages/babel-plugin/src/shared/component.ts‎

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -347,18 +347,27 @@ export default function transformComponent(
347347
const componentArgs = [tagId, props[0]];
348348
// `componentNames` carries the source tag name into the call so the
349349
// dev/observe runtimes can label the owner after minification renames the
350-
// function. DOM output only: SSR inlines the call below and the universal
351-
// renderer's `createComponent` is user code with a two-argument contract.
352-
if (config.componentNames && config.generate === "dom") {
350+
// function — on the client (`createComponent` in solid-js's client entry)
351+
// and on the server (its server entry's, which runs the body under a
352+
// transparent `<Name>` owner in observe/dev so a server finding's
353+
// `ownerPath` reads like the client's). Not for the universal renderer,
354+
// whose `createComponent` is user code with a two-argument contract, nor
355+
// the dynamic renderer's subtrees.
356+
const labelled =
357+
config.componentNames && (config.generate === "dom" || config.generate === "ssr");
358+
if (labelled) {
353359
componentArgs.push(t.stringLiteral(tagName));
354360
}
355-
// SSR's `createComponent` is literally `Comp(props || {})`. Since the
361+
// SSR's prod `createComponent` is literally `Comp(props || {})`. Since the
356362
// compiler always emits a real `props[0]` object expression above (see the
357363
// `props.push(t.objectExpression(runningObject))` line), the `|| {}` fallback
358364
// never fires in compiled output. Inline to a direct `Comp(props)` call to
359365
// drop one function-call frame per component invocation. (DOM/dev modes
360366
// keep the wrapper since it does real work — `untrack`, dev metadata.)
361-
if (config.generate === "ssr") {
367+
// With `componentNames` the wrapper IS the work — the label has nowhere
368+
// else to go — so SSR output keeps the call; the vite-plugin turns the
369+
// option on for dev and observe builds only, so prod output stays inlined.
370+
if (config.generate === "ssr" && !labelled) {
362371
exprs.push(t.callExpression(tagId, [props[0]]));
363372
} else {
364373
exprs.push(t.callExpression(registerImportMethod(path, "createComponent"), componentArgs));
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { Child, Ui, Row } from "./components";
2+
3+
const Component = () => <Child name="John" />;
4+
5+
const template = (
6+
<div>
7+
<Child name="Jane" {...props}>
8+
<span>{name()}</span>
9+
</Child>
10+
<Ui.Button variant="primary" />
11+
<Ui.Layout.Grid cols={2}>text</Ui.Layout.Grid>
12+
<For each={list()}>{item => <Row item={item} />}</For>
13+
<Show when={visible()}>
14+
<Child />
15+
</Show>
16+
<this.Row />
17+
<Comp>{() => <Child />}</Comp>
18+
</div>
19+
);
20+
21+
class Container {
22+
render() {
23+
return <this.Row />;
24+
}
25+
}

packages/babel-plugin/test/__dom_component_names_fixtures__/ssrInert/options.json renamed to packages/babel-plugin/test/__dom_component_names_fixtures__/ssr/options.json

File renamed without changes.
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
import { Show as _$Show } from "r-dom";
2+
import { For as _$For } from "r-dom";
3+
import { mergeProps as _$mergeProps } from "r-dom";
4+
import { ssr as _$ssr } from "r-dom";
5+
import { escape as _$escape } from "r-dom";
6+
import { createComponent as _$createComponent } from "r-dom";
7+
var _v$;
8+
var _tmpl$ = ["<span>", "</span>"],
9+
_tmpl$2 = ["<div>", "", "", "", "", "", "", "</div>"];
10+
import { Child, Ui, Row } from "./components";
11+
const Component = () =>
12+
_$createComponent(
13+
Child,
14+
{
15+
name: "John"
16+
},
17+
"Child"
18+
);
19+
var _v$2 = _$escape(
20+
_$createComponent(
21+
Child,
22+
_$mergeProps(
23+
{
24+
name: "Jane"
25+
},
26+
props,
27+
{
28+
get children() {
29+
return ((_v$ = () => _$escape(name())), _$ssr(_tmpl$, _v$));
30+
}
31+
}
32+
),
33+
"Child"
34+
)
35+
),
36+
_v$3 = _$escape(
37+
_$createComponent(
38+
Ui.Button,
39+
{
40+
variant: "primary"
41+
},
42+
"Ui.Button"
43+
)
44+
),
45+
_v$4 = _$escape(
46+
_$createComponent(
47+
Ui.Layout.Grid,
48+
{
49+
cols: 2,
50+
children: "text"
51+
},
52+
"Ui.Layout.Grid"
53+
)
54+
),
55+
_v$5 = _$escape(
56+
_$createComponent(
57+
_$For,
58+
{
59+
get each() {
60+
return list();
61+
},
62+
children: item =>
63+
_$createComponent(
64+
Row,
65+
{
66+
item: item
67+
},
68+
"Row"
69+
)
70+
},
71+
"For"
72+
)
73+
),
74+
_v$6 = _$escape(
75+
_$createComponent(
76+
_$Show,
77+
{
78+
get when() {
79+
return visible();
80+
},
81+
get children() {
82+
return _$createComponent(Child, {}, "Child");
83+
}
84+
},
85+
"Show"
86+
)
87+
),
88+
_v$7 = _$escape(_$createComponent(_self$.Row, {}, "this.Row")),
89+
_v$8 = _$escape(
90+
_$createComponent(
91+
Comp,
92+
{
93+
children: () => _$createComponent(Child, {}, "Child")
94+
},
95+
"Comp"
96+
)
97+
);
98+
const template = (() => {
99+
const _self$ = this;
100+
return _$ssr(_tmpl$2, _v$2, _v$3, _v$4, _v$5, _v$6, _v$7, _v$8);
101+
})();
102+
class Container {
103+
render() {
104+
return _$createComponent(this.Row, {}, "this.Row");
105+
}
106+
}

‎packages/babel-plugin/test/__dom_component_names_fixtures__/ssrInert/code.js‎

Lines changed: 0 additions & 8 deletions
This file was deleted.

‎packages/babel-plugin/test/__dom_component_names_fixtures__/ssrInert/output.js‎

Lines changed: 0 additions & 15 deletions
This file was deleted.

0 commit comments

Comments
 (0)