Skip to content

Commit da84bd9

Browse files
ryansolidClaude via Cursorcursoragent
authored
fix(solid): hydration trace's fake Promise provides withResolvers and try (#3727)
During hydration adoption, subFetch runs the compute once under a never-settling fake `Promise` to record its dependencies. The fake had no `withResolvers` or `try`, so a traced compute calling either threw out of hydration instead of adopting the server value. - `withResolvers` returns a never-settling fake with no-op `resolve`/`reject`. - `try` returns a never-settling fake without invoking its callback, matching the fake constructor, which ignores its executor. Every other standard static and prototype method was already present. Size-Exception accepted by the maintainer: the two frozen page caps rise to fit (+67 B minified; brotli +99 B / +96 B): - page: base server components: 45.95 -> 46.04 KB - page: live server components: 50.12 -> 50.17 KB Co-authored-by: Claude via Cursor <[email protected]> Co-authored-by: Cursor <[email protected]>
1 parent 3dcc269 commit da84bd9

5 files changed

Lines changed: 71 additions & 3 deletions

File tree

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+
Fix hydration adoption throwing when a traced compute calls `Promise.withResolvers()` or `Promise.try()`. The trace run swaps the global `Promise` for a never-settling mock that lacked these two statics, so the call threw out of hydration instead of adopting the server value. The mock now provides both: `withResolvers` returns a never-settling mock with no-op `resolve`/`reject`, and `try` returns a never-settling mock without invoking its callback (matching how the mock's constructor ignores its executor).

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -407,9 +407,14 @@ const MockPromise = /* @__PURE__ */ (() => {
407407
return new MockPromise();
408408
}
409409
}
410-
for (const k of ["all", "allSettled", "any", "race", "reject", "resolve"] as const) {
410+
for (const k of ["all", "allSettled", "any", "race", "reject", "resolve", "try"] as const) {
411411
(MockPromise as any)[k] = () => new MockPromise();
412412
}
413+
(MockPromise as any).withResolvers = () => ({
414+
promise: new MockPromise(),
415+
resolve() {},
416+
reject() {}
417+
});
413418
return MockPromise;
414419
})();
415420

‎packages/solid/test/client-hydration.spec.ts‎

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4761,3 +4761,46 @@ describe("Promise-of-AsyncIterable Hydration — createMemo", () => {
47614761
expect(result()).toBe(2);
47624762
});
47634763
});
4764+
4765+
describe("adoption trace — Promise statics", () => {
4766+
afterEach(() => {
4767+
stopHydration();
4768+
});
4769+
4770+
test("a compute calling Promise.withResolvers adopts the server value", () => {
4771+
startHydration({ t0: { s: 1, v: "server" } });
4772+
4773+
let result: any;
4774+
createRoot(
4775+
() => {
4776+
result = createMemo(() => {
4777+
const { promise, resolve, reject } = (Promise as any).withResolvers();
4778+
resolve("client");
4779+
reject(new Error("client"));
4780+
return promise;
4781+
})();
4782+
},
4783+
{ id: "t" }
4784+
);
4785+
flush();
4786+
4787+
expect(result).toBe("server");
4788+
});
4789+
4790+
test("a compute calling Promise.try adopts the server value without running the callback", () => {
4791+
startHydration({ t0: { s: 1, v: "server" } });
4792+
4793+
const callback = vi.fn(() => "client");
4794+
let result: any;
4795+
createRoot(
4796+
() => {
4797+
result = createMemo(() => (Promise as any).try(callback))();
4798+
},
4799+
{ id: "t" }
4800+
);
4801+
flush();
4802+
4803+
expect(result).toBe("server");
4804+
expect(callback).not.toHaveBeenCalled();
4805+
});
4806+
});

‎scripts/size/floor-caps.json‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
"signals: core floor (createSignal/Memo/Effect/Root/flush)": "9.51 KB",
33
"app: render + one signal (the simple-app floor)": "12.05 KB",
44
"app: hydrating (no stores) with Show/For/Loading/Errored/lazy": "19.69 KB",
5-
"page: base server components (hydrating + dynamic + frames + sf reference)": "45.95 KB",
6-
"page: live server components (base + live/GET + action + isPending/latest)": "50.12 KB",
5+
"page: base server components (hydrating + dynamic + frames + sf reference)": "46.04 KB",
6+
"page: live server components (base + live/GET + action + isPending/latest)": "50.17 KB",
77
"server: floor (getRequestEvent + isServer)": "1.34 KB",
88
"server: renderToString (the server-render floor)": "20.36 KB"
99
}

‎scripts/size/scenarios.js‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3012,6 +3012,16 @@ module.exports = [
30123012
// measured at 45,943 B against `next` @ bf87f27de's 45,904 (+39 B; +105 B
30133013
// minified). Same latch change as the `+ every store` note. Accepted by
30143014
// the maintainer. The cap is frozen again at 45.95 KB.
3015+
// Size-Exception (fake Promise statics, 2026-09-30): 45.95 -> 46.04 KB,
3016+
// measured at 46,036 B against `next` @ cce43eb44's 45,937 (+99 B; 86 B
3017+
// over the cap; +67 B minified). The hydration trace's fake `Promise`
3018+
// gains `withResolvers` and `try`, so a traced compute calling them
3019+
// adopts the server value instead of throwing out of hydration. About
3020+
// 60 B of the minified cost is the property names. None of ~90
3021+
// equivalent encodings fit the two hydrating and two page caps at once
3022+
// (brotli layout moved each by up to ±100 B); this is the smallest
3023+
// minified form. Accepted by the maintainer. The cap is frozen again at
3024+
// 46.04 KB.
30153025
limit: floorCaps["page: base server components (hydrating + dynamic + frames + sf reference)"],
30163026
alias: pageAlias
30173027
},
@@ -3078,6 +3088,11 @@ module.exports = [
30783088
// measured at 50,115 B against `next` @ bf87f27de's 50,085 (+30 B; +105 B
30793089
// minified). Same latch change as the base page's note. Accepted by the
30803090
// maintainer. The cap is frozen again at 50.12 KB.
3091+
// Size-Exception (fake Promise statics, 2026-09-30): 50.12 -> 50.17 KB,
3092+
// measured at 50,166 B against `next` @ cce43eb44's 50,070 (+96 B; 46 B
3093+
// over the cap; +67 B minified). Same fake-`Promise` change as the base
3094+
// page's note. Accepted by the maintainer. The cap is frozen again at
3095+
// 50.17 KB.
30813096
limit: floorCaps["page: live server components (base + live/GET + action + isPending/latest)"],
30823097
alias: pageAlias
30833098
},

0 commit comments

Comments
 (0)