Skip to content

Commit 73c288c

Browse files
committed
Merge remote-tracking branch 'origin/next' into fix/show-held-branch-verdict-reader-4010
2 parents 5bb069b + 25935fe commit 73c288c

24 files changed

Lines changed: 1409 additions & 544 deletions

File tree

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@solidjs/babel-plugin": patch
3+
"@solidjs/compiler": patch
4+
---
5+
6+
Non-hydratable client builds now remove the `value` attribute when a checkbox or radio input binds a nullish `value` or `defaultValue`, matching the runtime fix from #4009, so a checked box submits `"on"` instead of `""`. Both compilers route these bindings through `setProperty` when the input's static `type` is `checkbox` or `radio`, or when its `type` cannot be known at compile time (an expression, `prop:type`, `attr:type`). Text inputs, inputs without a `type`, and textareas still clear to `""` inline (#2957).
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
---
2+
"solid-js": patch
3+
---
4+
5+
`onHydrationEnd` is public API again, as `@experimental` (#4000), so end-to-end tests have a documented end-of-hydration signal instead of reading `_$HY` internals. It was already a runtime export of both entries; only its declarations change (it is no longer stripped as `@internal`), so it adds no runtime bytes. `sharedConfig` and `isHydrationInProgress` stay internal.
6+
7+
- `onHydrationEnd(callback)` (`solid-js`): runs `callback` once when the hydration phase ends — the root pass of `hydrate()` over and every streamed `<Loading>` boundary (and every hold an integration registers) resumed or cancelled. With no hydration in progress, and on the server, it runs in the next microtask.
8+
- Register it after calling `hydrate()`: registered before hydration starts (or after a `hydrate()` parked mid-parse, #3971), it runs in the next microtask and does not wait for hydration work started afterward.
9+
- It reports that the phase ended, not that hydration succeeded: a document root whose module preload fails ends the phase with the server markup kept and not interactive.
10+
- It is not page-wide completion with several hydration roots: a root deferred behind its module preload is not counted (GH5).
11+
- Intended for test tooling and markers, not for branching what the app renders.
12+
13+
This reverses the part of the earlier "Remove isHydrating/onHydrationEnd from public API" entry that covered `onHydrationEnd`, as #3718 did for `isHydrating`: hydration snapshots make timing transparent to code inside the app, not to a test reading the page from outside it.

‎documentation/server-components/frames-rulings.md‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,9 @@ Four corollaries, one per seam and one for the boundary the seams meet at:
132132
(`initBoundaryResume`), and there is no parallel accounting, no second
133133
"done", no SC consumer API. `onHydrationEnd` and `isHydrationInProgress()`
134134
mean the same thing with or without SC. Seam 3 (3.1, with 3.2 as its
135-
mechanism).
135+
mechanism). `onHydrationEnd` is the one public signal for it (`solid-js`,
136+
`@experimental`, #4000; `isHydrationInProgress` stays internal), so SC
137+
pages get the same channel, not one of their own.
136138
4. **A frame is one async value outward; its inner boundaries are the
137139
server's.** _"SCs participate in `<Loading>` until their first flush the
138140
same way, and can have their own internal loading states that the client

‎documentation/solid-2.0/12-ssr-http.md‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,34 @@ For hydration, the document needs the hydration script ahead of the app markup:
3030

3131
In a hand-built document the render output ends with the serialized hydration records (`_$HY.r`), written by a classic inline `<script>`. The client entry must execute after that script: make it a deferred `<script type="module">` (or a `defer` classic script), or place it after the render output — never `async`, which may run before the records have been parsed and hydrate against an empty document. `<HydrationScript />` documents handle the ordering themselves: the records script is spliced immediately after the bootstrap, so the entry may be `async` there.
3232

33+
### Observing the end of hydration: `onHydrationEnd` (experimental)
34+
35+
`onHydrationEnd(callback)` (`solid-js`, `@experimental`) runs `callback` once, when the hydration phase ends: the root pass of `hydrate()` is over and every streamed `<Loading>` boundary — and every hold an integration registers, such as server-component content waiting for its data — has resumed or been cancelled. When no hydration is in progress (before `hydrate()` starts, after the phase has ended, in a client-only render, on the server) it runs in the next microtask.
36+
37+
It exists for test tooling and markers: an end-to-end test that must wait until the client has taken over before it checks state the client writes, or must assert that it has not yet. It is not a way to branch what the app renders — read `isHydrating()` where a value must match the server and switch to the client-only value from `onSettled` (RFC 01).
38+
39+
```tsx
40+
import { onHydrationEnd } from "solid-js";
41+
import { hydrate } from "@solidjs/web";
42+
43+
hydrate(() => <App />, document);
44+
// after hydrate(): see below
45+
onHydrationEnd(() => {
46+
document.documentElement.dataset.hydrated = "";
47+
});
48+
```
49+
50+
```ts
51+
// Playwright
52+
await expect(page.locator("html[data-hydrated]")).toBeAttached();
53+
```
54+
55+
What the callback does and does not tell you:
56+
57+
- **Register it after calling `hydrate()`.** Registered before hydration starts, the callback runs in the next microtask and does not wait for hydration work started afterward. The same holds when `hydrate()` parks because the entry ran while the parser was still inside the server shell (an `async` entry, #3971): hydration starts at the shell-end marker, after `hydrate()` has returned.
58+
- **It reports that the phase ended, not that hydration succeeded.** When a document root's module preload fails, `hydrate()` abandons hydration and keeps the server markup, which is not interactive; the callback still runs. A non-document root whose preload fails runs it before falling back to a client render. Check the expected behavior (and the reported error) separately.
59+
- **It is not page-wide completion with several hydration roots.** A root whose render waits on its module preload is not counted, so another root finishing ends the phase before that root has claimed anything (GH5 in `documentation/server-components/frames-consistency-contract.md`).
60+
3361
### Consuming the stream: `pipe`, `pipeTo`, `readable`
3462

3563
`renderToStream` returns a result with three consumption surfaces — **exactly one may be used per render** (a second consumer throws with a directed message):

‎packages/babel-plugin/src/dom/element.ts‎

Lines changed: 50 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ type DOMSetAttrOptions = {
5757
tagName?: string;
5858
styleProperty?: boolean;
5959
classProperty?: boolean;
60+
checkableInput?: boolean;
6061
};
6162
type SpreadOptions = {
6263
elem: babelTypes.Expression;
@@ -354,7 +355,7 @@ export function setAttr(
354355
elem: babelTypes.Expression,
355356
name: string,
356357
value: babelTypes.Expression,
357-
{ dynamic, prevId, tagName, styleProperty, classProperty }: DOMSetAttrOptions = {}
358+
{ dynamic, prevId, tagName, styleProperty, classProperty, checkableInput }: DOMSetAttrOptions = {}
358359
): babelTypes.Expression {
359360
// pull out namespace
360361
const config = getConfig(path);
@@ -428,10 +429,17 @@ export function setAttr(
428429
// carries the select-value retry and input/textarea nullish special cases.
429430
// `<select value>` always goes through it: a microtask only sees options
430431
// inserted in the same turn, so options that arrive later never get
431-
// selected (#3928).
432+
// selected (#3928). So does a non-literal value/defaultValue on an input
433+
// that may be a checkbox or radio: a nullish value must remove the
434+
// attribute so the checked box submits its native "on" (#4009, #4017),
435+
// and setProperty already tests the live `type` for that.
432436
if (
433437
(config.hydratable && (isLocked || namespace !== "prop")) ||
434-
(name === "value" && tagName === "select")
438+
(name === "value" && tagName === "select") ||
439+
(checkableInput &&
440+
(name === "value" || name === "defaultValue") &&
441+
!t.isStringLiteral(value) &&
442+
!t.isNumericLiteral(value))
435443
) {
436444
return t.callExpression(registerImportMethod(path, "setProperty"), [
437445
elem,
@@ -451,7 +459,8 @@ export function setAttr(
451459
!t.isStringLiteral(value) &&
452460
!t.isNumericLiteral(value)
453461
) {
454-
// prevents undefined on input/textarea.value/defaultValue, fallback to empty string
462+
// prevents undefined on text input/textarea.value/defaultValue, fallback
463+
// to empty string (#2957)
455464
return t.assignmentExpression(
456465
"=",
457466
t.memberExpression(elem, t.identifier(name)),
@@ -492,6 +501,35 @@ function detectResolvableEventHandler(
492501
return t.isFunction(handler);
493502
}
494503

504+
/**
505+
* Whether an `<input>` may be a checkbox or radio, whose nullish
506+
* value/defaultValue removes the `value` attribute (restoring the native "on"
507+
* submission value) instead of clearing it to "" like a text field (#4017).
508+
* Only a plain `type` written as a string literal is resolved here; a missing
509+
* `type` is a text input. Anything else (an expression, `prop:type`,
510+
* `attr:type`, a spread) is unknown and treated as possibly checkable, which
511+
* stays correct because setProperty tests the live `type`. Mirrored by the
512+
* native compiler's `input_may_be_checkable` (dom/attrs.rs).
513+
*/
514+
function inputMayBeCheckable(node: babelTypes.JSXElement): boolean {
515+
let checkable = false;
516+
for (const attribute of node.openingElement.attributes) {
517+
if (t.isJSXSpreadAttribute(attribute)) return true;
518+
const name = attribute.name;
519+
if (t.isJSXNamespacedName(name)) {
520+
if (name.name.name === "type") return true;
521+
continue;
522+
}
523+
if (name.name !== "type") continue;
524+
let value: babelTypes.Node | null | undefined = attribute.value;
525+
if (t.isJSXExpressionContainer(value)) value = value.expression;
526+
if (value == null) checkable = false;
527+
else if (t.isStringLiteral(value)) checkable = /^(checkbox|radio)$/i.test(value.value);
528+
else return true;
529+
}
530+
return checkable;
531+
}
532+
495533
function transformAttributes(
496534
path: BabelPath<babelTypes.JSXElement>,
497535
results: DOMTransformResult
@@ -504,7 +542,8 @@ function transformAttributes(
504542
const tagName = getTagName(path.node),
505543
hasChildren = path.node.children.length > 0,
506544
hasSpread = attributes.some(attribute => t.isJSXSpreadAttribute(attribute.node)),
507-
config = getConfig(path);
545+
config = getConfig(path),
546+
checkableInput = tagName === "input" && inputMayBeCheckable(path.node);
508547
const refs: babelTypes.Statement[] = [];
509548

510549
// preprocess spreads
@@ -1182,6 +1221,7 @@ function transformAttributes(
11821221
key,
11831222
value: value.expression,
11841223
tagName,
1224+
checkableInput,
11851225
styleProperty: isStyleProperty,
11861226
classProperty: isClassProperty
11871227
});
@@ -1190,6 +1230,7 @@ function transformAttributes(
11901230
t.expressionStatement(
11911231
setAttr(attribute, elem, key, value.expression, {
11921232
tagName,
1233+
checkableInput,
11931234
styleProperty: isStyleProperty,
11941235
classProperty: isClassProperty
11951236
})
@@ -1238,7 +1279,10 @@ function transformAttributes(
12381279
) {
12391280
results.exprs.push(
12401281
t.expressionStatement(
1241-
setAttr(attribute, elem, key, staticValue as babelTypes.Expression, { tagName })
1282+
setAttr(attribute, elem, key, staticValue as babelTypes.Expression, {
1283+
tagName,
1284+
checkableInput
1285+
})
12421286
)
12431287
);
12441288
} else {

‎packages/babel-plugin/src/dom/template.ts‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,7 @@ function wrapDynamics(
258258
t.expressionStatement(
259259
setAttr(path, dynamics[0].elem, dynamics[0].key, newValue, {
260260
tagName: dynamics[0].tagName,
261+
checkableInput: dynamics[0].checkableInput,
261262
dynamic: true,
262263
prevId: prevValue,
263264
styleProperty: dynamics[0].styleProperty,
@@ -278,7 +279,9 @@ function wrapDynamics(
278279
const statements: t.ExpressionStatement[] = [];
279280
const properties: t.Identifier[] = [];
280281

281-
dynamics.forEach(({ elem, key, value, tagName, styleProperty, classProperty }, index) => {
282+
dynamics.forEach((binding, index) => {
283+
const { elem, key, tagName, styleProperty, classProperty, checkableInput } = binding;
284+
let value = binding.value;
282285
const propIdent = t.identifier(getNumberedId(index));
283286
const propMember = t.memberExpression(prevId, propIdent);
284287
const optionalPropMember = t.optionalMemberExpression(prevId, propIdent, false, true);
@@ -296,7 +299,8 @@ function wrapDynamics(
296299
setAttr(path, elem, key, propIdent, {
297300
tagName,
298301
dynamic: true,
299-
prevId: optionalPropMember
302+
prevId: optionalPropMember,
303+
checkableInput
300304
})
301305
)
302306
);
@@ -316,7 +320,8 @@ function wrapDynamics(
316320
tagName,
317321
dynamic: true,
318322
styleProperty,
319-
classProperty
323+
classProperty,
324+
checkableInput
320325
})
321326
)
322327
)

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ export interface DynamicBinding {
161161
tagName?: string;
162162
styleProperty?: boolean;
163163
classProperty?: boolean;
164+
checkableInput?: boolean;
164165
}
165166

166167
export interface SetAttrOptions {

‎packages/babel-plugin/test/__dom_fixtures__/attributeExpressions/code.js‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,3 +421,21 @@ const template97 = <div class={["todo", { active: isActive(), [props.name]: prop
421421
const template98 = <div class={["todo", { active: isActive() }, props.extra]} />;
422422

423423
const template99 = <div class={["todo", "item", { todo: false, active: isActive() }]} />;
424+
425+
// #4017: a nullish value/defaultValue on a checkbox or radio (or an input whose
426+
// type is not statically known) removes the attribute; text inputs clear to "".
427+
const template100 = <input type="checkbox" name="agree" value={value()} checked />;
428+
429+
const template101 = <input type="radio" name="choice" defaultValue={value()} />;
430+
431+
const template102 = <input type="text" value={value()} />;
432+
433+
const template103 = <input value={value()} />;
434+
435+
const template104 = <input type={kind()} value={value()} />;
436+
437+
const template105 = <input type="Checkbox" value={value} />;
438+
439+
const template106 = <input type="checkbox" value={value()} defaultValue={other()} />;
440+
441+
const template107 = <input type="email" value={value()} defaultValue={other()} />;

‎packages/babel-plugin/test/__dom_fixtures__/attributeExpressions/output.js‎

Lines changed: 81 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,13 @@ var _tmpl$ = /*#__PURE__*/ _$template(`<div><h1><a href=/>Welcome`),
7474
),
7575
_tmpl$50 = /*#__PURE__*/ _$template(`<video src=test.mp4 muted>`),
7676
_tmpl$51 = /*#__PURE__*/ _$template(`<div class=todo>`),
77-
_tmpl$52 = /*#__PURE__*/ _$template(`<div class="todo item">`);
77+
_tmpl$52 = /*#__PURE__*/ _$template(`<div class="todo item">`),
78+
_tmpl$53 = /*#__PURE__*/ _$template(`<input type=checkbox name=agree checked>`),
79+
_tmpl$54 = /*#__PURE__*/ _$template(`<input type=radio name=choice>`),
80+
_tmpl$55 = /*#__PURE__*/ _$template(`<input type=text>`),
81+
_tmpl$56 = /*#__PURE__*/ _$template(`<input>`),
82+
_tmpl$57 = /*#__PURE__*/ _$template(`<input type=Checkbox>`),
83+
_tmpl$58 = /*#__PURE__*/ _$template(`<input type=email>`);
7884
import * as styles from "./styles.module.css";
7985
import { binding } from "somewhere";
8086
function refFn() {}
@@ -844,4 +850,78 @@ _$effect(
844850
}
845851
);
846852
const template99 = _el$123;
853+
854+
// #4017: a nullish value/defaultValue on a checkbox or radio (or an input whose
855+
// type is not statically known) removes the attribute; text inputs clear to "".
856+
var _el$124 = _tmpl$53();
857+
_$effect(
858+
() => value(),
859+
_v$ => {
860+
_$setProperty(_el$124, "value", _v$);
861+
}
862+
);
863+
const template100 = _el$124;
864+
var _el$125 = _tmpl$54();
865+
_$effect(
866+
() => value(),
867+
_v$ => {
868+
_$setProperty(_el$125, "defaultValue", _v$);
869+
}
870+
);
871+
const template101 = _el$125;
872+
var _el$126 = _tmpl$55();
873+
_$effect(
874+
() => value(),
875+
_v$ => {
876+
_el$126.value = _v$ ?? "";
877+
}
878+
);
879+
const template102 = _el$126;
880+
var _el$127 = _tmpl$56();
881+
_$effect(
882+
() => value(),
883+
_v$ => {
884+
_el$127.value = _v$ ?? "";
885+
}
886+
);
887+
const template103 = _el$127;
888+
var _el$128 = _tmpl$56();
889+
_$effect(
890+
() => ({
891+
e: kind(),
892+
t: value()
893+
}),
894+
({ e, t }, _p$) => {
895+
e !== _p$?.e && _$setAttribute(_el$128, "type", e);
896+
_$setProperty(_el$128, "value", t);
897+
}
898+
);
899+
const template104 = _el$128;
900+
var _el$129 = _tmpl$57();
901+
_$setProperty(_el$129, "value", value);
902+
const template105 = _el$129;
903+
var _el$130 = _tmpl$9();
904+
_$effect(
905+
() => ({
906+
e: value(),
907+
t: other()
908+
}),
909+
({ e, t }, _p$) => {
910+
_$setProperty(_el$130, "value", e);
911+
t !== _p$?.t && _$setProperty(_el$130, "defaultValue", t);
912+
}
913+
);
914+
const template106 = _el$130;
915+
var _el$131 = _tmpl$58();
916+
_$effect(
917+
() => ({
918+
e: value(),
919+
t: other()
920+
}),
921+
({ e, t }, _p$) => {
922+
_el$131.value = e ?? "";
923+
t !== _p$?.t && (_el$131.defaultValue = t ?? "");
924+
}
925+
);
926+
const template107 = _el$131;
847927
_$delegateEvents(["click", "input"]);

0 commit comments

Comments
 (0)