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

Implement websockets based on-demand-entries ping #4508

Merged
merged 6 commits into from
Dec 14, 2018

Conversation

ijjk
Copy link
Member

@ijjk ijjk commented May 31, 2018

Fixes #4495

Here's my approach for replacing the XHR on-demand-entries pinger #1364 #4495. I'm not sure if this is the way everyone wants to accomplish this since I saw mention of using a separate server and port for the dynamic entries websocket, but thought this would be a fairly clean solution since it doesn't need that.

With this method the only change when using a custom server is you have to listen for the upgrade event and pass it to next.getRequestHandler(). Example:

const server = app.listen(port)
const handleRequest = next.getRequestHandler()

if(dev) {
  server.on('upgrade', handleRequest)
}

@ijjk
Copy link
Member Author

ijjk commented Jun 3, 2018

Hey @rauchg I was wondering if I could get your feedback on this. Sorry to bother if you're the wrong person to ask, I thought I'd ask you since you prioritized the issue.

@timneutkens
Copy link
Member

I'll review this soon, I'm currently implementing a new server.

@ijjk
Copy link
Member Author

ijjk commented Jun 3, 2018

Okay cool, thanks for the reply!

@willopez
Copy link

@timneutkens can this be revisited?

@Enalmada
Copy link
Contributor

Having to put a little code in custom server seems worth it. Are there any other disadvantages of this solution over the current one?

@icharge
Copy link

icharge commented Nov 21, 2018

I'm waiting for this

@Enalmada
Copy link
Contributor

Would it make reviewers more comfortable if this was configurable and people could opt-in to websocket based pinger? I would happily beta test this feature if there is some hesitation about making it the default right away.

@ijjk ijjk force-pushed the dynamic-entries-websocket branch from 20347e2 to b0d6afe Compare November 26, 2018 04:39
@ijjk
Copy link
Member Author

ijjk commented Nov 26, 2018

Hey @Enalmada I updated my dynamic-entries-websocket branch with the new next structure so if you want to give it a try it should be good to go.

@Enalmada
Copy link
Contributor

Enalmada commented Nov 27, 2018

@ijjk Thanks for taking the time to do this pull request. It seems to work great! Developers like me that spend lots of time with the chrome console open will be so happy when this is merged. It is a superior developer experience and has tests and everything.

@timneutkens
Copy link
Member

Is there an alternative to doing this:

if(dev) {
  server.on('upgrade', handleRequest)
}

I assume we could open a socket server on a different (random) port in development?

This is the only part that makes me hesitate to merge this PR, as it'll break pretty much every implementation of Next.js that is currently out there, and it's easy to forget adding this.

@ijjk
Copy link
Member Author

ijjk commented Dec 11, 2018

Yeah, that makes sense, it does seem better to avoid that. I updated my branch to create a WebSocket server on a random port for the dynamic-entries pinging in development.

@timneutkens
Copy link
Member

💯 Going to have a look 👍

so that the port can be passed with DefinePlugin
Copy link
Member

@timneutkens timneutkens left a comment

Choose a reason for hiding this comment

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

Let's put this on canary after my changes to render.js 💯

@timneutkens timneutkens mentioned this pull request Dec 12, 2018
@timneutkens timneutkens changed the title Replace XHR based on-demand-entries pinger with websocket based Implement websockets based on-demand-entries ping Dec 14, 2018
@timneutkens timneutkens merged commit af07611 into vercel:canary Dec 14, 2018
@ghost
Copy link

ghost commented Dec 30, 2018

Is there a way to manually set the port? I have to manually map ports so this has corrupted my Dev experience. I did try setting process.env.NEXT_WS_PORT on both client and server.

@ijjk
Copy link
Member Author

ijjk commented Dec 30, 2018

@glenarama currently you can't manually set the port for the on-demand-entries WebSocket. I just sent over a pull request adding a --websocket or -w argument similar to how the -p argument works to fix that.

@ghost
Copy link

ghost commented Dec 30, 2018

Great, thanks!

@ijjk ijjk deleted the dynamic-entries-websocket branch February 17, 2019 05:43
@lock lock bot locked as resolved and limited conversation to collaborators Feb 17, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Replace on-demand-retries XHR ping with websocket
5 participants