Skip to content

fix: fall back to structured-clone for RPC error envelopes#336

Closed
baseballyama wants to merge 1 commit into
vitejs:mainfrom
baseballyama:fix/335
Closed

fix: fall back to structured-clone for RPC error envelopes#336
baseballyama wants to merge 1 commit into
vitejs:mainfrom
baseballyama:fix/335

Conversation

@baseballyama
Copy link
Copy Markdown

Description

jsonSerializable: true declares the result shape of an RPC function, but the WS transport applied strictJsonStringify to every outgoing message routed to such a method — including the error envelope ({ t: 's', i, e }) emitted when the handler throws. Because Error instances aren't JSON-serializable, this crashed the serializer with DF0020 and masked the original DTK0011 entirely, taking the dev server down with it (reproducible on StackBlitz / WebContainer).

Skip the strict-JSON path for error envelopes on both ws-server and ws-client transports so thrown values round-trip via structured-clone, and the underlying failure surfaces on the caller instead.

Linked Issues

close: #335

Additional context

N/A

Copilot AI review requested due to automatic review settings May 11, 2026 10:39
@netlify
Copy link
Copy Markdown

netlify Bot commented May 11, 2026

Deploy Preview for devfra ready!

Name Link
🔨 Latest commit 071bf31
🔍 Latest deploy log https://app.netlify.com/projects/devfra/deploys/6a01b78900816d00083a245e
😎 Deploy Preview https://deploy-preview-336--devfra.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a WS transport bug in devframe’s RPC layer where jsonSerializable: true methods could crash the serializer when the handler throws, because the error envelope was being strict-JSON encoded (masking the original RPC error and potentially taking the dev server down).

Changes:

  • Skip strict-JSON serialization for RPC error envelopes on both WS server and WS client transports (fall back to structured-clone).
  • Add a regression test ensuring a thrown Error from a jsonSerializable: true RPC results in a rejection rather than a serialization crash.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
devframe/packages/devframe/src/rpc/transports/ws-server.ts Adjusts WS server-side message serialization to avoid strict-JSON for error envelopes.
devframe/packages/devframe/src/rpc/transports/ws-client.ts Mirrors the same error-envelope serialization behavior on the WS client channel.
devframe/packages/devframe/src/rpc/transports/ws.test.ts Adds a regression test for thrown errors in jsonSerializable: true RPCs over WS.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread devframe/packages/devframe/src/rpc/transports/ws-client.ts Outdated
Comment thread devframe/packages/devframe/src/rpc/transports/ws-server.ts Outdated
Comment thread devframe/packages/devframe/src/rpc/transports/ws.test.ts Outdated
@antfu
Copy link
Copy Markdown
Member

antfu commented May 12, 2026

Thanks for the PR! I am sorry I just did a big refactor to move devframe out of the repo, you can resend the PR to https://github.com/devframes/devframe instead? Thanks

@baseballyama
Copy link
Copy Markdown
Author

I opened devframes/devframe#8 instead.

@baseballyama baseballyama deleted the fix/335 branch May 12, 2026 12:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: vite:anonymous:auth fails on StackBlitz: DF0020 masks DTK0011 (Error in jsonSerializable: true response)

3 participants