-
Notifications
You must be signed in to change notification settings - Fork 13
Provide a page reload mechanism for the dev environement #105
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
Comments
Cool! We don't want to mess up the production configuration by doing this out-of-the-box. Right now, the framework is configured to silently reconnect to the websocket, and fall-back to HTTP if it isn't connected. How do other frameworks do this? What's the simplest way to add this functionality for development but not for production? (I'd like to avoid specifically naming anything "dev" or "prod" -- maybe there's some way to easily configure it for live-reload when running) |
Yeah I saw that, but pluging into that mechanism at dev-time felt a bit off, so I didn't try to explore that (but that was just a quick assumption on my part, nothing well thought out)
Quite a long time ago (a very long time ago), I worked on a rails app, and at the time the idea was new and necessitated a browser plugin: https://chromewebstore.google.com/detail/livereload/jnihajbhpnppcggbcgedagnkighmdlei You'd then install a file watcher process in your environment (and extra dependencies), that would instruct the plugin that the page should refresh. It worked well but that's antiquated now. I've played briefly with the Dream OCaml web library, you can install a separate package and change ou couple of lines in your code: https://github.com/tmattio/dream-livereload But the best "out of the box" dev experience I can remember was when I learned a bit of Elixir Phoenix/LiveView, and so I looked into it: When you install the framework and initiate your project setup, a dev environment + configuration get created by the scaffolding tool. One of these dependencies is this one: https://github.com/phoenixframework/phoenix_live_reload/ Which injects a new websocket (technically, in an iframe, right before the closing body tag). Which reloads the page like I did actually, here: https://github.com/phoenixframework/phoenix_live_reload/blob/e9160bde423f727036951aba92ddd6dbee674013/priv/static/phoenix_live_reload.js#L42 To me though, a dev-specific configuration is equivalent to an environnement variable. But maybe something could be done with an extra internal library via cabal configuration? Meaning, to prevent activating such a behavior in a production environment if it's a concern. What about the idea to just dispatch a custom event on reconnect? Then maybe document a simple js script to copy/paste into ones project would suffice? (the script would listen to an event "hyperbole:source-code-changed" or something like that) |
Is anything planned? I think it'd be nice to have the library provide a default mechanism to reload the page automatically.
I created a little script that does the trick for me
page-reload-2025-03-29_14.41.14.mp4
Personally, I don't care for anything fancy, since we can easily restore some kind of "state" via cookies or URL params.
Do you think such a script be integrated into the lib? I'm thinking it could be injected via setting an env var?
The text was updated successfully, but these errors were encountered: