Rebuild router on every hot reload message #4537
Merged
+50
−51
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is an attempt to fix magic number/word error when in fullstack mode and hot patching is active:
Why this happens?
This bug is present only in fullstack mode, the cause is axum router that serves static assets needs to be rebuilt to serve newly added file, and rebuild was only triggered if incoming hot-reload message included a server patch jumptable.
This meant if client didn't generate wasm patch file before server patch was ready, router would respond with a 404 even if the file was present in the filesystem, and magic number error would apear
The fix:
I'm not sure if this is the right way to fix this, but it does work in web and desktop targets without issues.
Currently change is very simple, router rebuild logic was moved outside conditional that required message to be a server patch, so router now gets rebuilt on every patch
Limitations of the current fix:
There is one "downside" to this patch, if developers setup axum server manually dev tools are never connected, see launch.rs for more info
The manual approach looks something like this, taken from https://dioxuslabs.com/learn/0.6/guides/fullstack/axum