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

In dev mode, refresh the page when the server starts #234

Open
TimJentzsch opened this issue Jan 18, 2025 · 4 comments
Open

In dev mode, refresh the page when the server starts #234

TimJentzsch opened this issue Jan 18, 2025 · 4 comments
Labels
A-Run Related to the bevy run command A-Web Building or running Bevy apps targeting the browser C-Feature Make something new possible D-Modest A "normal" level of difficulty; suitable for simple features or challenging fixes S-Needs-Design This issue requires design work to think about how it would best be accomplished

Comments

@TimJentzsch
Copy link
Collaborator

This is the first step towards supporting some sort of watch feature (even if it is through external tools like bacon).
It might also aid with #189.

For this first iteration, if a browser window is already open with the app, it should refresh if we use bevy run web again and the new server booted up. That way, we ensure that we show the latest state and the user could just leave the browser open on the second screen and doesn't have to refresh manually to see the changes.

Implementation-wise, we could probably use websockets to send the refresh event from server to client.

trunk supports this feature since v0.14, so we can probably implement it in a similar way.

@TimJentzsch TimJentzsch added A-Run Related to the bevy run command A-Web Building or running Bevy apps targeting the browser C-Feature Make something new possible D-Modest A "normal" level of difficulty; suitable for simple features or challenging fixes S-Needs-Design This issue requires design work to think about how it would best be accomplished labels Jan 18, 2025
@BD103
Copy link
Member

BD103 commented Jan 21, 2025

Checkout trunk-rs/trunk#191 for the initial auto-reload feature in trunk, as well as trunk-rs/trunk#227 and trunk-rs/trunk#231

@TimJentzsch
Copy link
Collaborator Author

One thing we will need to decide on is whether we want to add a dependency to a HTML parser like trunk does to do this "properly" or if we can fake it with search/replace functionality (e.g. for <body>).

So basically a trade off between correctness and binary size + compile time.

Of course it might be possible that we want to inject more scripts in the future (asset hot reloading comes to mind)

@BD103
Copy link
Member

BD103 commented Jan 21, 2025

What reason would you need an HTML parser for this? My gut reaction is to avoid adding one, but maybe there's something I'm missing.

@TimJentzsch
Copy link
Collaborator Author

TimJentzsch commented Jan 21, 2025

Because the user can also provide their own index.html.
We have to read the contents of it and inject our own script with the reloading logic.
Using a HTML related crate would be the safe way to do it, but we can also try to work around it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Run Related to the bevy run command A-Web Building or running Bevy apps targeting the browser C-Feature Make something new possible D-Modest A "normal" level of difficulty; suitable for simple features or challenging fixes S-Needs-Design This issue requires design work to think about how it would best be accomplished
Projects
None yet
Development

No branches or pull requests

2 participants