DevTools Protocol
The Dioxus CLI runs a WebSocket server that communicates with your running application. This enables hot-reload, code patching, and debugging features.Connecting to DevServer
packages/devtools/src/lib.rs:60-111
Message Types
The devtools protocol supports several message types:Hot Reload Integration
Dioxus supports two types of hot-reloading:1. RSX Template Hot Reload
Updates UI templates without restarting the app:- Template is parsed and compiled
- Signal with matching file/line/column is found
- Signal value is updated with new template
- Components using that template automatically re-render
packages/devtools/src/lib.rs:9-14
2. Subsecond Code Patching
Patches Rust code changes at runtime using jump table indirection:- Compiling only changed functions to a dynamic library
- Loading the library at runtime
- Updating a global jump table to redirect calls to new code
packages/devtools/src/lib.rs:75-86
Debugging Tools
Inspecting the VirtualDOM
Access VirtualDOM state for debugging:packages/core/src/virtual_dom.rs:333-345
Scope Inspection
Inspect component scope state:Tracing Integration
Dioxus uses thetracing crate for structured logging:
- Scope creation and destruction
- Re-renders and diffs
- Task polling
- Event handling
packages/core/src/virtual_dom.rs:307-331
Performance Profiling
Render Time Tracking
Measure component render times:Memory Profiling
Track memory usage:Custom DevTools Integration
Building a Custom DevTool
Create custom debugging tools for your app:Intercepting Hot Reload Events
packages/devtools/src/lib.rs:88-111
Subsecond Hot-Patching
Using Subsecond in Your App
For non-Dioxus apps that want hot-patching:packages/devtools/src/lib.rs:141-148
With Arguments
Pass arguments to hot-patched functions:packages/devtools/src/lib.rs:176-220
WebSocket Protocol Details
The devserver WebSocket protocol:Connection
aslr_reference: Memory address offset for ASLRbuild_id: Build identifier for version matchingpid: Process ID for targeting specific instances
Message Format
Messages are JSON-encoded:Best Practices
- Disable in Production: Devtools should only run in development builds
- Error Handling: Handle devserver disconnections gracefully
- Security: Never expose devtools WebSocket to the internet
- Logging: Use structured logging (tracing) for debugging
- Hot Reload Limits: Not all code changes can be hot-reloaded (see Subsecond limitations)
Troubleshooting
Hot Reload Not Working
Code Patches Failing
Additional Resources
- Subsecond architecture:
/notes/architecture/07-HOTRELOAD.md - DevTools types:
packages/devtools-types/src/lib.rs - CLI implementation:
packages/cli/src/