Dev server: hot-swap stylesheets, stream changes over SSE, revalidate SCSS partials - #91
Merged
Merged
Conversation
… SSE The dev server told the browser to reload the whole page on any change and served a stale stylesheet after a partial edit, because the compile cache was keyed on the entry's mtime alone. A change hub (`web_modules::live`) now feeds a coalescing watcher's events, mapped to the served URL, never a filesystem path, into an SSE stream; the browser client swaps a changed stylesheet's `<link>` in place and reloads the page for anything else, or only logs it under `--live-reload css`. Compiled stylesheets record the partials they read, so the cache revalidates every dependency and a partial edit names the stylesheets that include it. Hosts with their own compilers or watchers feed the same hub (`record_dependencies`, `notify`) and mount its routes where their auth wants them. `tower-livereload` is replaced by `futures-core`, the trait crate axum's SSE response takes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
The dev server reloaded the whole page on any change and served a stale stylesheet after a partial edit, because the compile cache was keyed on the entry's mtime alone.
This replaces
tower-livereloadwith a hub of our own (web_modules::live): a coalescingnotifywatcher maps edits to served URLs (never filesystem paths), an SSE stream (/_web_modules/live/events) publishes them, and an injected client (/_web_modules/live/live.js) hot-swaps a changed stylesheet's<link>in place and reloads the page for anything else. Compiled stylesheets record the partials they read (scss::compile_file_tracked), so the cache revalidates every dependency and a partial edit names exactly the stylesheets that include it.The policy is the server's:
--live-reload full(the default) reloads on non-CSS changes,--live-reload cssonly logs,--no-live-reloadserves no live routes;Dev::live_reload(ReloadMode)on the builder,dev_router_with_live/serve_with_liveas free functions. Hosts with their own watchers or compilers feed the same hub (record_dependencies,notify) and mount the routes where their auth wants them.Dependencies:
tower-livereloadout;futures-corein (theStreamtrait axum's SSE response takes, already compiled in every axum build); tokio gainssync.The stream's no-filesystem-paths rule is recorded in SECURITY.md.