[2.0 rc.14 / next] A synchronous `prepareRequest` hook makes every hydrated server-function read refetch in the browser
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 3/5
- Thời gian dự kiến
- Nửa ngày
- Mức phù hợp với người mới
- 55/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- javascript, typescript
- Lĩnh vực
- frontend
Hướng nghiên cứu
Start in packages/web/server-functions/src/client.ts, in createRequest, where config.prepareRequest is awaited even when it returns synchronously. Then read subFetch in packages/solid/src/client/hydration.ts to see how the fetch mock is swapped and restored. Done means a synchronous prepareRequest produces zero client requests after hydration for memo and store sources, and the existing client, server and hydration test suites still pass.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Summary
With any prepareRequest configured, even an identity hook init => init, a page whose data comes from server functions fetches that data twice: once during SSR, and again from the browser right after hydration, although the serialized value was adopted. Without the hook there is no client request.
Reproduces on 2.0.0-rc.14 and on next at 358159c6.
Reproduction
// client entry, before render
import { configureServerFunctionsClient } from "@solidjs/web/server-functions/client";
configureServerFunctionsClient({ prepareRequest: init => init });
// a page reading a "use server" function through a memo or derived store
const value = createMemo(() => readThing());
return <p>{value()}</p>;
Load the page directly (SSR, then hydrate) and watch the network:
prepareRequest |
SSR reads | Client requests after hydration |
|---|---|---|
| not configured | 1 | 0 |
init => init |
1 | 1 |
The DOM is adopted correctly in both cases; the extra request is wasted (and, for private reads, doubles server work on every page load).
Cause
Hydration runs a serialized source's compute once, synchronously, inside subFetch (packages/solid/src/client/hydration.ts), with window.fetch swapped for a never-settling mock, then restores it. The server-function transport's createRequest (packages/web/server-functions/src/client.ts) does:
if (config.prepareRequest) {
const prepared = await config.prepareRequest(init, { id, meta });
The await runs even when the hook returns synchronously, so send(base, init) happens a microtask later, after subFetch has restored the real fetch. The call goes to the network instead of the mock.
Fix
Await only when the hook returns a promise:
- const prepared = await config.prepareRequest(init, { id, meta });
+ let prepared = config.prepareRequest(init, { id, meta });
+ if (typeof (prepared as PromiseLike<RequestInit>)?.then === "function") prepared = await prepared;
A synchronous hook then sends inside the hydration window like the default transport. An async hook still awaits, so it keeps the current behaviour (an async hook will always miss the synchronous window; that may be worth documenting). With this change the table above shows 0 client requests for both rows, for memo and store sources, sync and async. @solidjs/web's client, server and hydration test suites pass unchanged. I can open a PR.
(submitted by Claude Opus 5.5 on behalf of rvlzzr)
- Ngôn ngữ chính
- TypeScript
- Star
- 36.1k
- Fork
- 1.1k
- Merge trung bình
- 11 giờ 32 phút
- Pull request đã merge (30 ngày)
- 356
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của solidjs/solid
-
[2.0 / next] Error formatting and async iterator protocol failures escape memo error handlingĐang mở
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 22/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 14/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 35/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 18/100
Maintainer thường phản hồi trong vòng 1 ngày
-
[2.0 / next] Outside latest reads of a derivation expose errors and values at different timesĐang mở
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 22/100
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của solidjs/solid
Issue tương tự
-
documentation good first issue
Độ khó 2/5 Nửa ngày Mức phù hợp với người mới 72/100
sujithputta02/Esapay#13 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
ehmpathy/rhachet-roles-bhuild#468 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Share dialog: the address book's contact count reads "1 contacts" (no singular form in any language)Có thể đã có người làm @chibenwa đã nhận hôm nay. Đang mởai-driven-qa bug claude Cosmetic
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
linagora/twake-contacts-frontend#271 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
factory-active task-identify-harness-labels-done task-identify-issue-type-done
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 70/100
vercel/ai#23435 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
Koenkk/zigbee2mqtt#33402 ·
Maintainer thường phản hồi trong vòng 1 ngày