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

SSE | WebSockets for auto-reload (future: HMR) #4

Closed
3 tasks done
thedodd opened this issue Aug 23, 2020 · 14 comments
Closed
3 tasks done

SSE | WebSockets for auto-reload (future: HMR) #4

thedodd opened this issue Aug 23, 2020 · 14 comments
Labels
cli Trunk CLI application enhancement New feature or request

Comments

@thedodd
Copy link
Member

thedodd commented Aug 23, 2020

  • open the URL in the browser, only do once per invocation of the CLI.
  • use WebSocket to communicate with browser app to trigger reloads.
  • use WebSocket to do WASM HMR (this will probably be a beast, may not even be browser supported quite yet, we'll see). We can look into HMR in the future as WASM module linking stabilizes.
@thedodd thedodd added the core label Aug 23, 2020
@thedodd thedodd changed the title Finish watch mode & watch functionality in serve SSE | WebSockets for reload (future: HMR) Aug 25, 2020
thedodd added a commit that referenced this issue Aug 25, 2020
@thedodd thedodd added cli Trunk CLI application enhancement New feature or request and removed core labels Sep 8, 2020
@jeroenvervaeke
Copy link

I started implementing hot reload for trunk.

I got everything finished (backend wise) but I'm blocked by an open issue with tide, SSE simply doesn't seem to work.
Sending a SSE back to the client simply doesn't work. Source

This might be another argument for #81 to switch away to another web server.

@thedodd
Copy link
Member Author

thedodd commented Mar 4, 2021

So, now that we’ve got a solid WebSocket impl about to land, we can start building a proper hot reloading mechanism.

A rough design:

  • Configure Trunk to listen for hot reload WS connections on a specific endpoint.
  • When running in serve mode, inject a canned script which will connect to the WS endpoint and listen for reload messages.
  • When a reload message is received, it will load the new module specified in the message, or simply reload the entire page.
  • The server will emit reload events over the socket whenever a build completes successfully.

@Boscop
Copy link

Boscop commented May 17, 2021

Any idea which bundler for Rust Wasm frontends supports livereload?
I tried using trunk serve with tauri dev and trunk rebuilds but my tauri app doesn't reload :/
What can I do to get auto-reloading working? :)

@ranile
Copy link
Contributor

ranile commented May 17, 2021

What can I do to get auto-reloading working? :)

Right now, use trunk watch to build and serve the dist directory with a server that supports live reloading. Trunk can't do it for now,

@Boscop
Copy link

Boscop commented May 18, 2021

@hamza1311 Can you recommend a server that supports live reloading that can serve any dist from the CLI?
I know browser-sync, but is there another one, maybe one that supports the livereload protocol? :)

@ranile
Copy link
Contributor

ranile commented May 18, 2021

@Boscop, take a look at httpwatcher

@Boscop
Copy link

Boscop commented May 18, 2021

@hamza1311 Thanks, but it seems there's no way to proxy my own websocket communication (between backend and frontend) through a different port (like browsersync allows)?

@ranile
Copy link
Contributor

ranile commented May 18, 2021

@hamza1311 Thanks, but it seems there's no way to proxy my own websocket communication (between backend and frontend) through a different port (like browsersync allows)?

Unfortunately, I'm not aware of any servers that would do this. If you're willing to do that, I think adding live reloading would be a great addition to trunk

@alecandido
Copy link

@Boscop, take a look at httpwatcher

Some time ago I was working at another project of mine for managing slides creation (essentially with reveal.js), and I wanted live reloading. It's not perfect, but it is working, and I took it exactly from httpwatcher, isolating the websocket from everything else:

I'm sorry not to be so expert in websockets + rust, but I'm pretty sure there should be no obstacle in repeating the same.

@thedodd thedodd changed the title SSE | WebSockets for reload (future: HMR) SSE | WebSockets for auto-reload (future: HMR) May 24, 2021
@thedodd
Copy link
Member Author

thedodd commented May 24, 2021

Hey folks. Lots of good discussion here. We now have WebSockets support in the Trunk dev server, and we should be clear to begin implementing a mechanism for auto-reload / live-reload. There are a few options for us to consider, however considering the discussion over in #141 I am strongly tempted to say that we should attempt to knock out these two issues as part of the same objective.

@thedodd
Copy link
Member Author

thedodd commented Jul 28, 2021

#191 is an implementation of this feature (not the HMR part though).

@thedodd
Copy link
Member Author

thedodd commented Aug 20, 2021

Support for this has landed as part of #191

@thedodd thedodd closed this as completed Aug 20, 2021
@hackers267
Copy link

Does trunk support the HMR(Hot Module Replacement). If supported, how to enable it?

@ctron
Copy link
Collaborator

ctron commented Oct 11, 2024

I am not sure this is applicable here. Seems purely like a webpack thing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cli Trunk CLI application enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

7 participants