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

Proxy request.signal through in vite dev #9976

Merged
merged 4 commits into from
Sep 13, 2024

Conversation

brophdawg11
Copy link
Contributor

@brophdawg11 brophdawg11 commented Sep 11, 2024

Found this wasn't working right while testing #9975. Aligned with how we do it in the express adapter.

Closes #9438

Copy link

changeset-bot bot commented Sep 11, 2024

🦋 Changeset detected

Latest commit: 0689ce9

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 16 packages
Name Type
@remix-run/dev Patch
create-remix Patch
remix Patch
@remix-run/architect Patch
@remix-run/cloudflare Patch
@remix-run/cloudflare-pages Patch
@remix-run/cloudflare-workers Patch
@remix-run/css-bundle Patch
@remix-run/deno Patch
@remix-run/eslint-config Patch
@remix-run/express Patch
@remix-run/node Patch
@remix-run/react Patch
@remix-run/serve Patch
@remix-run/server-runtime Patch
@remix-run/testing Patch

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

@brophdawg11 brophdawg11 linked an issue Sep 12, 2024 that may be closed by this pull request
@brophdawg11 brophdawg11 merged commit a49b4c6 into dev Sep 13, 2024
9 checks passed
@brophdawg11 brophdawg11 deleted the brophdawg11/proxy-vite-signal branch September 13, 2024 14:54
@github-actions github-actions bot added the awaiting release This issue has been fixed and will be released soon label Sep 13, 2024
Copy link
Contributor

🤖 Hello there,

We just published version 2.12.1-pre.0 which includes this pull request. If you'd like to take it for a test run please try it out and let us know what you think!

Thanks!

Copy link
Contributor

🤖 Hello there,

We just published version 2.12.1 which includes this pull request. If you'd like to take it for a test run please try it out and let us know what you think!

Thanks!

@jvaill
Copy link

jvaill commented Sep 23, 2024

It's working better now! But I'm still having issues with the signal not being aborted sometimes.

Referencing this: sergiodxa/remix-utils#317 (comment)

@Eiley2
Copy link

Eiley2 commented Sep 25, 2024

Is there a workaround for this? Maybe check every once is a while if a connection is closed to abort that connection? I'm having the same issue with node and the updated version of remix in production too.

routes/sse.time.ts

import { LoaderFunctionArgs } from "@remix-run/node"
import { eventStream } from "remix-utils/sse/server"

export async function loader({ request }: LoaderFunctionArgs) {
  return eventStream(request.signal, function setup(send) {
    const timer = setInterval(() => {
      console.log(new Date().toLocaleTimeString())
      send({ event: "time", data: new Date().toLocaleTimeString() })
    }, 1000)

    return function clear() {
      console.log("SSE connection closed")
      clearInterval(timer)
    }
  })
}

and this is my route:

routes/time.tsx

import { useEventSource } from "remix-utils/sse/react"

export default Route(){
  let time = useEventSource("/sse/time", { event: "time" })
  if (!time) {
    time = new Date().toLocaleTimeString()
  }

return <p>{time}</p>

@jvaill
Copy link

jvaill commented Sep 25, 2024

It seems like the signal is working correctly until a new undici Request() is constructed. At that point, undici creates an underlying signal. That ends up getting passed to the remix handler.

Here's where Request() is created in remix.

Here's an issue I opened on the undici repo.

@jvaill
Copy link

jvaill commented Sep 26, 2024

Possible fix: #10030

@mkromann
Copy link

I am running into the same issue, and cannot get any EventSource to close with request.signal. Is there a workaround for how to handle this?

Right now it is a huge block for developing with SSE. We have to restart the whole app constantly.

acusti added a commit to acusti/superflare that referenced this pull request Nov 11, 2024
v2.12.1 includes remix-run/remix#9976, which changed the API contract of the fromNodeRequest util that we will depend on in superflareDevProxyVitePlugin
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.

request.signal is never fired in dev server
5 participants