feat(web): report request failures met before any render - #3763
Conversation
Add `reportRequestFailure(error, event)` to the server entry of
`@solidjs/web`, with a no-op in the client view, and `"request"` to
`ServerErrorSite.kind`. A framework's request handler that catches a
failure before any render or server function met it (a middleware
throw) reports it through the ambient server error hook as
`{ kind: "request", handling: "failed", event }`, once per error object,
or to `console.error` when no hook is registered, the same policy as a
render that fails before its shell.
Closes solidjs#3723.
🦋 Changeset detectedLatest commit: f7bbd58 The changes in this PR will be included in the next version bump. This PR includes changesets to release 12 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Merging this PR will not alter performance
Comparing Footnotes
|
Co-authored-by: Cursor <[email protected]> # Conflicts: # .github/workflows/size.yml
…ethrow A synchronous throw out of renderToString, or out of renderToStream's first pass (and so renderToFrameStream and serverComponentResponse), reached the caller without the server error hook hearing it. A request handler that caught it and called reportRequestFailure filed it as kind "request". The render now reports it as render/failed through its own onError or the ambient hook before rethrowing, so the handler's report of the same error is deduped by the once-per-error ledger. No console fallback on this road: the rethrow is the caller's. The "request" kind is documented as a failure that fails the request outside any render or server function the runtime reports. Co-authored-by: Claude via Cursor <[email protected]> Co-authored-by: Cursor <[email protected]>
Measured at 20,412 B against next @ 4738c6d's 20,377 (+35 B; +72 B minified): the catch in renderToString that reports a synchronous throw as render/failed before rethrowing. Accepted by the maintainer; ledger note in scripts/size/scenarios.js. Size-Exception: renderToString reports synchronous render throws as render/failed before rethrowing (+35 B), accepted by the maintainer. Co-authored-by: Claude via Cursor <[email protected]> Co-authored-by: Cursor <[email protected]>
|
…arve-step1 Co-authored-by: Cursor <[email protected]>
Summary
Closes #3723.
A failure that fails a request before any render or server function met it (a Start middleware throw, a
setuporrenderModemodule failing) had no public way to reach the server error hook. solidjs/solid-vite-plugin#383 reports it today throughreportServerErrorfromsolid-js/internal, labelledkind: "render"becauseServerErrorSite.kindhad nothing else, and repeatsfailRender'sconsole.errorfallback by reading the hook slot offglobalThis.reportRequestFailure(error, event)in the server entry of@solidjs/web, next toconfigureServerErrors: it reports{ kind: "request", handling: "failed", event }throughreportServerError, then callsconsole.error(error)only when no ambient hook is registered, the same policy asfailRender. The hook's return is ignored, as for everyhandling: "failed", and the once-per-error ledger applies, so a direct server-function failure already heard asserver-function/thrownisn't heard again when it escapes the middleware."request"added toServerErrorSite.kindinsolid-js, on both the server and the client declaration.reportRequestFailureinserver-mock.ts, asconfigureServerErrorshas, so the client entry exports it too.I exported it from the package root rather than
@solidjs/web/server, which the issue mentions: the package has no./serversubpath today, andconfigureServerErrorsalready lives in the root's server build.How did you test this change?
Five tests in
packages/web/test/server/server-error-hook.spec.tsx:request/failedcall carrying the event, its return is ignored, and nothing reachesconsole.error;server-function/thrownwithdirect: true, andreportRequestFailureadds no second call;console.error;They fail on
next, where the export doesn't exist.pnpm build, then:@solidjs/webclient@solidjs/webserver@solidjs/webhydrate@solidjs/webtest-typessolid-jsPublic API changes
New
reportRequestFailure(error: unknown, event: RequestEvent): voidfrom@solidjs/web(server entry; a no-op on the client).ServerErrorSite.kind(and soServerErrorContext.kind) gains"request", always withhandling: "failed"andeventset.Behavior change: the server error hook (the render's
onError, or the ambientconfigureServerErrorshook) now hears{ kind: "render", handling: "failed" }for a synchronous throw out ofrenderToStringor out ofrenderToStream's first pass (and sorenderToFrameStreamandserverComponentResponse), before the error is rethrown to the caller. Previously these reached the caller without the hook hearing them. A handler that catches the rethrow and callsreportRequestFailureadds nothing (once per error). With no hook, nothing is logged on this road; the rethrow is the caller's. Added by the maintainer on this branch.Maintainer changes
next(with chore(size): keep the size comparison green on fork PRs #3765) into this branch;.github/workflows/size.ymlnow matchesnext, replacing this PR's duplicate change.render/failedbefore rethrow, with tests (renderToString,renderToStream,renderToFrameStream, per-renderonError, no-hook case, and a genuine pre-render failure still reportingrequest)."request"documented as a failure that fails the request outside any render or server function the runtime reports.server: renderToStringfloor cap raised 20.38 → 20.42 KB (+35 B), ledger note inscripts/size/scenarios.js.Size-Exception: renderToString reports synchronous render throws as render/failed before rethrowing (+35 B), accepted by the maintainer.