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

eventStream triggers warnings in Remix with single fetch #400

Open
kentcdodds opened this issue Oct 16, 2024 · 4 comments
Open

eventStream triggers warnings in Remix with single fetch #400

kentcdodds opened this issue Oct 16, 2024 · 4 comments

Comments

@kentcdodds
Copy link
Contributor

kentcdodds commented Oct 16, 2024

Describe the bug

When Single Fetch is enabled, eventStream causes Remix to output an error:

⚠️ REMIX FUTURE CHANGE: Resource routes will no longer be able to return raw JavaScript objects in v3 when Single Fetch becomes the default. You can prepare for this change at your convenience by wrapping the data returned from your loader function in the routes/test route with json(). For instructions on making this change see https://remix.run/docs/en/v2.9.2/guides/single-fetch#resource-routes

Your Example Website or App

https://github.com/epicweb-dev/epicshop

Steps to Reproduce the Bug or Issue

  1. Create a Remix app with single fetch enabled
  2. Create a resource route that returns an event stream
  3. Notice the error

Expected behavior

I expect no warnings

Screenshots or Videos

image

Platform

  • OS: macOS
  • Browser: Chrome
  • Version: 7.7.0

Additional context

It's possible this is an error in Remix's detection of returned responses.

@sergiodxa
Copy link
Owner

eventStream returns a Response object, so maybe they consider it a raw object?

@kentcdodds
Copy link
Contributor Author

Here's how they detect whether something is a response: https://github.com/remix-run/remix/blob/aabc7f84514c1c0e0ba8e33c48c7fba422cf8084/packages/remix-server-runtime/responses.ts#L107C1-L116C1

export function isResponse(value: any): value is Response {
  return (
    value != null &&
    typeof value.status === "number" &&
    typeof value.statusText === "string" &&
    typeof value.headers === "object" &&
    typeof value.body !== "undefined"
  );
}

Perhaps one of those things is unset in the eventStream?

@sergiodxa
Copy link
Owner

sergiodxa commented Oct 16, 2024

It has a headers object and body, but I never set a status and statusText, if that solves the issue it could be a quick change here, it can be just status 200 and statusText set to OK

@kentcdodds
Copy link
Contributor Author

doesn't new Response default the status to 200 and statusText to OK?

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

No branches or pull requests

2 participants