Skip to content

Commit 48089a0

Browse files
authored
Merge branch 'next' into fix/delegated-event-restore-v2
2 parents ba30ae6 + b1b0667 commit 48089a0

38 files changed

Lines changed: 1183 additions & 123 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+
A streamed boundary that fails on the server can leave nested reads still pending. The server abandons those reads, and their records used to settle as `undefined`, which the client's fresh render of the failed fragment would then adopt as the server's answer. The server now unregisters abandoned records, so those reads compute on the client. The fresh render also spends an id on each element's hydration key, as the server did, so its reads line up with the server's records by id.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@solidjs/babel-plugin": patch
3+
---
4+
5+
Evaluated negative and non-finite numbers (`c={-1}`, `d={NaN}`) are static again. Since Babel 8 support, `evaluateAndInline` built them with `t.valueToNode`, which gives `-1` / `0 / 0` expressions rather than numeric literals, so they stopped being inlined into templates (SSR emitted `ssrAttribute("c", -1)` instead of `c="-1"`) and diverged from `@solidjs/compiler` (the parity probes' "exotic literal holes"). They are now NumericLiteral nodes again, built directly where @babel/types 8's builder would reject the value; both Babel majors print them as before.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@solidjs/compiler": patch
3+
---
4+
5+
The secondary passes (`transformDirectives`, the lazy and refresh passes, source names) accept a filename with any extension. They run on code that is already lowered to JavaScript, so the filename is metadata rather than a parser choice: a known extension still picks its dialect, and any other (`App.rx`, from another front end) is parsed as TSX instead of failing with "Unknown file extension". This matters for server functions, whose IDs hash the filename: a front end can now pass the module's real path, so the ID matches the one `moduleForFunctionId` computes for that module. The JSX transform itself is unchanged.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"solid-js": patch
3+
"@solidjs/web": patch
4+
---
5+
6+
A boundary whose server render failed is rendered fresh on the client while adopting the server's records. Inside that render, a `<Dynamic>` tag now creates its element instead of throwing a hydration mismatch, and a `<Portal>` mounts. Hydration also completes when the adopted error has no client boundary to catch it.
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+
A node that moves into a hole with no marker (a sole child, or the last child) no longer keeps the `$$SLOT` tag of the hole it came from. The markerless hole now retags it with its parent, so a later removal from that hole takes the node out of the DOM instead of skipping it as another slot's. Untagged nodes in markerless holes stay untagged, so lists like a `<For>` under `<tbody>` take the same path as before.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"solid-js": patch
3+
---
4+
5+
Hydration never asks again for what the server sent, even when a streamed boundary's fragment rejects with no outcome (no `<Errored>` on the server could draw the failure). The client still renders that fragment fresh, so its graph is created, but every read in it now claims its serialized record: reads the server resolved take their values, and a read whose record is an error throws that error to the nearest client boundary, or is an uncaught error when there is none. Only reads with no record, such as those cut off by a truncated stream, compute. Recovery comes from a real input change or a boundary's `reset()`, as for any hydrated failure.

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
VoidElements
1212
} from "../../../web/src/constants.js";
1313
import {
14+
numberLiteral,
1415
evaluateAndInline,
1516
getAttributeNamed,
1617
getTagName,
@@ -997,7 +998,7 @@ function transformAttributes(
997998
((type = typeof evaluated) === "string" || type === "number" || type === "boolean")
998999
) {
9991000
if (type === "number" && key.startsWith("prop:")) {
1000-
value = t.jsxExpressionContainer(t.valueToNode(evaluated) as babelTypes.Expression);
1001+
value = t.jsxExpressionContainer(numberLiteral(evaluated));
10011002
} else if (type === "boolean") {
10021003
value = t.jsxExpressionContainer(t.booleanLiteral(evaluated));
10031004
} else value = t.stringLiteral(String(evaluated));

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -759,6 +759,18 @@ const templateEscapes = new Map([
759759
["\u2029", "\\u2029"]
760760
]);
761761

762+
// A NumericLiteral for any evaluated number, so `-1` and `NaN` stay static
763+
// literals downstream. @babel/types 8's builder rejects negative and
764+
// non-finite values (`t.valueToNode` builds `-1` / `0 / 0` expressions
765+
// instead), so those are built as plain nodes; generators print them as
766+
// `-1` / `NaN` / `Infinity`, as Babel 7's builder did.
767+
export function numberLiteral(value: number): t.NumericLiteral {
768+
if (value >= 0 && Number.isFinite(value) && !Object.is(value, -0)) return t.numericLiteral(value);
769+
const node = { type: "NumericLiteral", value } as t.NumericLiteral;
770+
if (Object.is(value, -0)) node.extra = { raw: "-0", rawValue: -0 };
771+
return node;
772+
}
773+
762774
export function evaluateAndInline(
763775
value: EvaluateAndInlineNode | null | undefined,
764776
valueNode: NodePath<EvaluateAndInlineNode>
@@ -786,7 +798,7 @@ export function evaluateAndInline(
786798
if (typeof r.value === "string") {
787799
valueNode.replaceWith(t.stringLiteral(r.value));
788800
} else if (typeof r.value === "number") {
789-
valueNode.replaceWith(t.valueToNode(r.value));
801+
valueNode.replaceWith(numberLiteral(r.value));
790802
} else if (typeof r.value === "boolean") {
791803
valueNode.replaceWith(t.booleanLiteral(r.value));
792804
}

‎packages/babel-plugin/test/numeric-literals.spec.js‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,32 @@ describe("evaluated numeric literals", () => {
2626
}
2727
});
2828
});
29+
30+
describe("evaluated numeric attributes stay static", () => {
31+
const attrs = `const a = <div c={-1} d={0 / 0} e={-0} />;
32+
const b = <input prop:value={-1} />;`;
33+
const compile = generate =>
34+
babel.transformSync(attrs, {
35+
plugins: [[plugin, { generate, moduleName: "r-dom" }]],
36+
configFile: false,
37+
babelrc: false,
38+
filename: "numeric.jsx"
39+
}).code;
40+
41+
test("dom", () => {
42+
const code = compile("dom");
43+
expect(code).toContain("<div c=-1 d=NaN e=0>");
44+
expect(code).toContain("_el$2.value = -1;");
45+
});
46+
47+
test("ssr", () => {
48+
expect(compile("ssr")).toContain('c=\\"-1\\" d=\\"NaN\\" e=\\"0\\"');
49+
});
50+
51+
test("universal", () => {
52+
const code = compile("universal");
53+
expect(code).toContain("c: -1");
54+
expect(code).toContain("d: NaN");
55+
expect(code).toContain("e: -0");
56+
});
57+
});
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
const path = require("path");
2+
3+
const compilerDir = path.resolve(__dirname, "..");
4+
const { transformDirectives, transformLazy, transformRefresh } = require(compilerDir);
5+
6+
// Another front end (ReactiveScript's `.rx`, through a bundler's frontends hook)
7+
// lowers its own modules to Solid's output, then hands that ordinary
8+
// JavaScript to the secondary passes under the module's own filename — the
9+
// path server-function ids hash, as the bundler's manifest keys it.
10+
const ROOT = "/project";
11+
const FILENAME = `${ROOT}/src/routes/App.rx`;
12+
const generated = `
13+
export async function save(value) {
14+
"use server";
15+
return value;
16+
}
17+
`;
18+
19+
describe("secondary passes for another front end's modules", () => {
20+
it.each(["server", "client"])(
21+
"transforms the generated JavaScript under the original path in %s mode",
22+
mode => {
23+
const result = transformDirectives(generated, {
24+
filename: FILENAME,
25+
root: ROOT,
26+
mode,
27+
env: "production"
28+
});
29+
expect(result.valid).toBe(true);
30+
expect(result.functions).toHaveLength(1);
31+
expect(result.functions[0].name).toBe("save");
32+
}
33+
);
34+
35+
it("hashes the module's own path, not a borrowed extension", () => {
36+
const own = transformDirectives(generated, {
37+
filename: FILENAME,
38+
root: ROOT,
39+
mode: "server",
40+
env: "production"
41+
});
42+
const client = transformDirectives(generated, {
43+
filename: FILENAME,
44+
root: ROOT,
45+
mode: "client",
46+
env: "production"
47+
});
48+
const borrowed = transformDirectives(generated, {
49+
filename: `${FILENAME}.tsx`,
50+
root: ROOT,
51+
mode: "server",
52+
env: "production"
53+
});
54+
expect(client.functions[0].id).toBe(own.functions[0].id);
55+
expect(borrowed.functions[0].id).not.toBe(own.functions[0].id);
56+
});
57+
58+
it("runs the lazy and refresh passes under that filename", () => {
59+
const lazy = transformLazy(
60+
`import { lazy } from "solid-js";\nexport const Page = lazy(() => import("./Page.rx"));\n`,
61+
{ filename: FILENAME }
62+
);
63+
expect(lazy.code).toContain("lazy(");
64+
const refresh = transformRefresh(`export function App() { return null; }\n`, {
65+
filename: FILENAME,
66+
bundler: "vite",
67+
jsx: false
68+
});
69+
expect(typeof refresh.code).toBe("string");
70+
});
71+
});

0 commit comments

Comments
 (0)