KyleJune / deno-tailwind-ui-react-example

An example of how you can use Tailwind UI and React with Deno
20 stars 5 forks source link

Improve live reload reliability #9

Open KyleJune opened 2 years ago

KyleJune commented 2 years ago

Sometimes the browser may refresh when the application isn't listening. Use server sent events to detect when server stops and disable triggering reloads until the server has restarted.

Add document unload listener to live-reload.js so that the same connection can be closed gracefully when leaving the current page. This will prevent it from causing error logs in the browser and on the server. Then add automatic browser reloads on server sent event error.

KyleJune commented 2 years ago

Deno doesn't support EventSource so server sent events wont work for detecting when the server is in the process of restarting. Use a hook or websockets instead for that. Use an unload event listener or one for oak.

https://deno.land/manual/runtime/program_lifecycle

Leave the browser using SSE for knowing when to restart.