[2.0 rc.20 / next] A value that fails to serialize stays pending on the client while the render reports completion

Đã đóng
#4,647 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

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ó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
35/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
backend

Hướng nghiên cứu

Start with the default serializer's onError in packages/web/src/server.ts (around L2532), where a serialization failure is only reported. Run the included repro.mjs to see completedAll: true with the key left pending. Done means either the render fails like a rejection, or the key is settled as a rejection that <Errored> can catch, and onCompleteAll no longer fires while a key is unsettled. The choice between those two behaviours is a design decision for maintainers, so confirm it before writing code.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

In #4242, the value that fails to serialize was noted as still not resolving, as a separate problem. This is that problem on its own, since I couldn't find an issue for it.

When the default serializer cannot serialize a resolved async value, the error reaches the error hook with handling: "serialize", the render completes and onCompleteAll runs. The hydration payload declares the promise for that key but never settles it, so the client waits for it forever: nothing hydrates past it, and there is no rejection for an <Errored> to catch.

A rejected async value in the same spot fails the render instead: the promise form resolves with no HTML and onCompleteAll is not called. So the server reports a broken document as a successful one only in the serialization case.

Versions

solid-js and @solidjs/web 2.0.0-rc.20 from npm, and next at ab29345. Node 26.13.0.

Reproduction

Save as repro.mjs in a project with solid-js and @solidjs/web 2.0.0-rc.20, then run node repro.mjs:

import { renderToStream, ssr, escape } from "@solidjs/web";
import { createMemo } from "solid-js";

class Unserializable {}

function App() {
  const value = createMemo(() => Promise.resolve(new Unserializable()));
  return ssr(["<main>", "</main>"], () => escape(String(value() instanceof Unserializable)));
}

let completedAll = false;
const errors = [];
const html = await renderToStream(App, {
  onCompleteAll: () => (completedAll = true),
  onError: error => errors.push(error?.constructor?.name)
});
console.log(html);
console.log({ completedAll, errors });
Observed
<main>true</main><script>(self.$R=self.$R||{})[""]=[];_$HY.r["0"]=$R[0]=($R[1]=($R[2]=() => {
	const resolver = {
		p: 0,
		s: 0,
		f: 0
	};
	resolver.p = new Promise((resolve, reject) => {
		resolver.s = resolve;
		resolver.f = reject;
	});
	return resolver;
})()).p;</script>
{ completedAll: true, errors: [ 'SerovalUnsupportedTypeError' ] }

$R[1] is never settled. With a serializable value, the payload ends with the call that resolves it (($R[3]=(resolver, data) => {...})($R[1],"loaded")). With Promise.reject(new Error("...")) instead, the output is an empty document and { completedAll: false, errors: [ 'Error' ] }.

Expected

A value that cannot be serialized is handled like a failure of that value: either the render fails the same way it does for a rejection, or the key reaches the client as a rejection that the nearest <Errored> can handle. In both cases onCompleteAll should not report the document as complete while one of its keys can never settle.

Cause

The default serializer's onError only reports the failure (packages/web/src/server.ts, L2532 on next). Nothing fails the render or writes a settle call for the key, and the render then completes through the normal path.

Ngôn ngữ chính
TypeScript
Star
36.2k
Fork
1.1k
Merge trung bình
9 giờ 56 phút
Pull request đã merge (30 ngày)
487

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. 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.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của solidjs/solid

Tất cả issue của solidjs/solid

Issue tương tự

Thêm issue về TypeScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.