Hot Reload¶
Hot reload enables live updates during development without restarting your application.
Enable Hot Reload¶
Via Constructor¶
At Runtime¶
Via Configuration¶
Behavior¶
| File Type | Behavior |
|---|---|
| CSS | Injected without page reload |
| JS/HTML | Full page refresh with scroll preservation |
Watch Files¶
Use the watch parameter to enable file watching:
With HtmlContent¶
from pywry import PyWry, HtmlContent
app = PyWry(hot_reload=True)
content = HtmlContent(
html="<div id='app'></div>",
css_files=["styles/main.css", "styles/theme.css"],
script_files=["js/app.js"],
watch=True,
)
app.show(content)
With show()¶
When watch=True, editing main.css will inject new styles instantly without refreshing the page.
Manual CSS Reload¶
# Reload CSS for all windows
app.refresh_css()
# Reload CSS for specific window
app.refresh_css(label="main-window")
Configuration Options¶
[hot_reload]
enabled = true
debounce_ms = 100 # Wait before reloading (milliseconds)
css_reload = "inject" # "inject" or "refresh"
preserve_scroll = true # Keep scroll position on JS refresh
watch_directories = ["./src", "./styles"]
Options¶
| Option | Default | Description |
|---|---|---|
enabled |
false |
Enable hot reload |
debounce_ms |
100 |
Debounce delay before reloading |
css_reload |
"inject" |
"inject" for inline update, "refresh" for page reload |
preserve_scroll |
true |
Maintain scroll position on JS refresh |
watch_directories |
[] |
Additional directories to watch |
How It Works¶
- PyWry uses
watchdogto monitor files for changes - When a file changes, it determines the file type
- CSS files are injected directly into the page
- JS/HTML changes trigger a full refresh with scroll preservation
Best Practices¶
Development Workflow¶
from pywry import PyWry, HtmlContent
app = PyWry(hot_reload=True)
# Use external CSS files for easy editing
content = HtmlContent(
html="<div id='app'></div>",
css_files=["styles/main.css"],
watch=True,
)
handle = app.show(content)
# Edit main.css and see changes immediately!
app.block()
Disable in Production¶
Or via environment variable:
Troubleshooting¶
Changes Not Detected¶
- Ensure
watch=Trueis set - Check that file paths are correct
- Verify the file is in a watched directory
CSS Not Updating¶
- Check for CSS syntax errors
- Ensure
css_reload = "inject"is set - Try
app.refresh_css()manually
Page Keeps Refreshing¶
- Increase
debounce_msto reduce sensitivity - Check for infinite loops in your code
- Ensure you're not modifying watched files in callbacks
Next Steps¶
- Configuration — Full configuration reference
- Theming & CSS — Styling your application