- RSX Template Hot-Reload - Instant UI updates for template changes (milliseconds)
- Subsecond Hot-Patching - Full Rust code hot-reload without restart (experimental)
dx serve.
RSX Template Hot-Reload
The RSX hot-reload system instantly updates your UI when you modify RSX templates, without recompiling or restarting your application.What Can Be Hot-Reloaded?
RSX hot-reload works for changes to: ✅ Hot-Reloadable:- Literal text:
"Hello World" - Component children content
- Attribute values and reordering
- Dynamic text segments:
"{class}" - Literal component properties:
value: 123 - Template structure shuffling
- Rust code changes outside RSX
- Component structure changes
- Control flow logic (
if,for,match) - Hook definitions
- Number of
rsx!macro invocations
How It Works
Conservative Detection
The hot-reload system uses a conservative approach to determine if a change is hot-reloadable:- Parse old and new files into syntax trees
- Replace all
rsx!bodies with emptyrsx! {} - Remove doc comments (they don’t affect runtime)
- Compare the modified files
- If identical → Only RSX changed → Hot-reload
- If different → Rust code changed → Full rebuild
Template Diffing Algorithm
When a change is hot-reloadable, the CLI:-
Extracts dynamic pools from the last build:
- Dynamic text segments (
"{variable}") - Dynamic nodes (components, loops)
- Dynamic attributes
- Dynamic text segments (
-
Matches new templates to old templates using greedy algorithm:
- Find candidates with compatible structure
- Score by unused dynamic items
- Select best match (least waste)
- Sends template updates via WebSocket to the running app
- Marks components dirty for re-render with new templates
Performance
RSX hot-reload is extremely fast:- Template parsing: ~1-5ms
- Diff computation: ~1-10ms
- WebSocket transmission: ~1-5ms
- DOM update: ~1-10ms
Enabling RSX Hot-Reload
Enabled by default indx serve:
File Watching
The CLI watches these paths by default (configurable inDioxus.toml):
- Linux/macOS: Native filesystem events (instant)
- Windows: Native filesystem events (instant)
- WSL: Polling (configurable interval)
Subsecond Hot-Patching
Subsecond is an experimental system that hot-patches Rust code changes without restarting your application.What Is Hot-Patching?
When you modify Rust code (not just RSX), Subsecond:- Recompiles only changed functions into a patch library
- Loads the patch dylib into the running process
- Updates the jump table to redirect calls to new code
- Continues execution without restart
Architecture: Jump Table Indirection
Instead of directly calling functions, hot-patchable code uses a jump table:- Original binary remains unchanged
- Jump table updated with new addresses
- Next call uses the patched version
Enabling Hot-Patching
How It Works
Build Process
Initial Build (Fat Binary):- Full compilation with all symbols
- Symbol table extraction
- Jump table creation
- Detect changed files
- Compile only modified functions
- Link against cached dependencies
- Produce minimal patch dylib
Patch Application
- CLI sends patch via WebSocket
- App loads dylib using
libloading - ASLR adjustment calculates address offsets
- Jump table update atomically swaps function pointers
- Execution continues with new code
ASLR Handling
Operating systems randomize load addresses (ASLR). Subsecond handles this:Limitations
Supported:- Function body changes
- Adding/removing functions
- Changing logic and algorithms
- Global and static variables
- Struct layout changes → Crashes (size/alignment mismatch)
- Dependency changes → Only tip crate patches
- Static initializer changes → Not re-run
- Thread-local changes in tip crate → Reset to initial values
Platform Support
| Platform | Status |
|---|---|
| Linux (x86_64, aarch64) | ✅ Supported |
| macOS (x86_64, aarch64) | ✅ Supported |
| Windows (x86_64, aarch64) | ✅ Supported |
| Android (arm64-v8a, armeabi-v7a) | ✅ Supported |
| iOS Simulator | ✅ Supported |
| iOS Device | ❌ Not supported (code signing) |
| WASM32 | ⚠️ Limited (module reloading) |
Performance
Hot-patching is slower than RSX hot-reload but much faster than full rebuild:- Small change: 100-500ms (single function)
- Medium change: 500ms-2s (multiple functions)
- Large change: 2-5s (many functions)
Debugging Hot-Patching
Enable verbose logging:- Likely struct layout change
- Check if you modified struct fields
- Requires full rebuild
- Check WebSocket connection
- Verify PID matches (multi-process apps)
- Ensure
--hot-patchflag is set
- Inlining may have occurred
- Not all call sites are patched
- Use
#[inline(never)]for critical functions
Development Workflow
Recommended Setup
For the best development experience:Interactive Mode
The TUI shows hot-reload status:r- Force full rebuild (useful if hot-reload gets confused)p- Pause/resume automatic rebuildsv- Toggle verbose logging
Manual Rebuild Trigger
If hot-reload fails or produces unexpected results, force a full rebuild:- Press
rin interactive mode - Or restart
dx serve
DevTools Protocol
WebSocket Connection
The running app connects to the dev server via WebSocket:build_id- Identifies the build (for multi-target setups)pid- Process ID (for multi-instance filtering)aslr_reference- Runtime address ofmain(for patching)
Message Types
Server → App messages:Custom Integration
Integrate hot-reload in non-Dioxus apps:Troubleshooting
Hot-Reload Not Working
Check WebSocket connection:Templates Not Updating
- Check for Rust code changes - Hot-reload only works for pure RSX changes
- Force rebuild - Press
rin interactive mode - Restart server - Sometimes file watcher needs reset
Hot-Patching Crashes
- Struct layout change - Rebuild required
- Dependency change - Rebuild required
- Static initializer - Rebuild required
r to force full rebuild.
Best Practices
Maximize Hot-Reload Hits
Do:- Separate UI (RSX) from logic (Rust functions)
- Keep RSX templates self-contained
- Use props for dynamic values
- Complex logic inside RSX blocks
- Conditional compilation in RSX
- Mixing Rust code changes with RSX changes
Optimize for Fast Iteration
Testing Without Hot-Reload
Before deploying, test without hot-reload to ensure code works correctly:Next Steps
Commands
Learn about dx serve options
Configuration
Configure file watching