Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug report: Single fetch: Throwing a response stub with a 4xx status causes a turbo-stream error #9454

Closed
wants to merge 1 commit into from

Conversation

haines
Copy link
Contributor

@haines haines commented May 17, 2024

Throwing a response stub with a 4xx status causes an error, because turbo-stream attempts to serialize the response stub and fails when it hits the headers value, which is not serializable due to having a prototype of Headers.

Running the test included test case produces the following logs:

Error: Cannot encode object with prototype
    at Object.stringify (~/remix/node_modules/.pnpm/turbo-stream@2.0.0/node_modules/turbo-stream/dist/flatten.js:116:27)
    at Object.flatten (~/remix/node_modules/.pnpm/turbo-stream@2.0.0/node_modules/turbo-stream/dist/flatten.js:22:15)
    at ~/remix/node_modules/.pnpm/turbo-stream@2.0.0/node_modules/turbo-stream/dist/flatten.js:30:59
    at Array.map (<anonymous>)
    at partsForObj (~/remix/node_modules/.pnpm/turbo-stream@2.0.0/node_modules/turbo-stream/dist/flatten.js:30:10)
    at Object.stringify (~/remix/node_modules/.pnpm/turbo-stream@2.0.0/node_modules/turbo-stream/dist/flatten.js:113:38)
    at Object.flatten (~/remix/node_modules/.pnpm/turbo-stream@2.0.0/node_modules/turbo-stream/dist/flatten.js:22:15)
    at ~/remix/node_modules/.pnpm/turbo-stream@2.0.0/node_modules/turbo-stream/dist/flatten.js:30:59
    at Array.map (<anonymous>)
    at partsForObj (~/remix/node_modules/.pnpm/turbo-stream@2.0.0/node_modules/turbo-stream/dist/flatten.js:30:10)
    at Object.stringify (~/remix/node_modules/.pnpm/turbo-stream@2.0.0/node_modules/turbo-stream/dist/flatten.js:113:38)
    at Object.flatten (~/remix/node_modules/.pnpm/turbo-stream@2.0.0/node_modules/turbo-stream/dist/flatten.js:22:15)
    at ~/remix/node_modules/.pnpm/turbo-stream@2.0.0/node_modules/turbo-stream/dist/flatten.js:30:59
    at Array.map (<anonymous>)
    at partsForObj (~/remix/node_modules/.pnpm/turbo-stream@2.0.0/node_modules/turbo-stream/dist/flatten.js:30:10)
    at Object.stringify (~/remix/node_modules/.pnpm/turbo-stream@2.0.0/node_modules/turbo-stream/dist/flatten.js:113:38)
    at Object.flatten (~/remix/node_modules/.pnpm/turbo-stream@2.0.0/node_modules/turbo-stream/dist/flatten.js:22:15)
    at Object.start (~/remix/node_modules/.pnpm/turbo-stream@2.0.0/node_modules/turbo-stream/dist/turbo-stream.js:123:45)
    at setupReadableStreamDefaultController (node:internal/webstreams/readablestream:2342:23)
    at setupReadableStreamDefaultControllerFromSource (node:internal/webstreams/readablestream:2375:3)
    at new ReadableStream (node:internal/webstreams/readablestream:286:7)
    at Object.encode (~/remix/node_modules/.pnpm/turbo-stream@2.0.0/node_modules/turbo-stream/dist/turbo-stream.js:121:22)
    at Object.encodeViaTurboStream (~/remix/build/node_modules/@remix-run/server-runtime/dist/single-fetch.js:395:22)
    at handleDocumentRequest (~/remix/build/node_modules/@remix-run/server-runtime/dist/server.js:288:40)
    at requestHandler (~/remix/build/node_modules/@remix-run/server-runtime/dist/server.js:142:18)
    at file://~/remix/integration/bug-report-test.ts:140:18

Copy link

changeset-bot bot commented May 17, 2024

⚠️ No Changeset found

Latest commit: 4c0c6cc

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@haines haines changed the title Bug report: throwing a response stub with a 4xx status causes a turbo-stream error Bug report: Single fetch: Throwing a response stub with a 4xx status causes a turbo-stream error May 17, 2024
@brophdawg11 brophdawg11 self-assigned this May 20, 2024
@brophdawg11
Copy link
Contributor

Thank you for the bug report! This should be handled by #9501

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants