Repository navigation
A canvas patch no longer puts stale CSS back over a stylesheet Vite hot-swapped - #37
Merged
flowtricks merged 1 commit intoOct 13, 2026
Conversation
A style edit written to a stylesheet that reaches the page through a CSS `@import` (global.css importing utilities.css) showed on the canvas and was then lost, or never showed: the file held the new value, the canvas the one from when the dev server started. Astro renders such a stylesheet from its first server-side compile for as long as the server runs, while Vite hot-swaps the live <style> on every write. refreshDevStyles (413e468) copied the server's text into any live dev stylesheet whose text differed, so each patch of the page put that first compile back over what Vite had just written. Measured on a real dev server (Astro 7.1.4, `@layer` + `@import … layer()`): after three writes the canvas read 30px and the server's HTML still said 1px; the next `avb:patch-now` set the canvas back to 1px. The patch now takes the server's text only when the server changed it between its previous rendering and this one. That is still what brings a page's own <style> (the case 413e468 fixed): the server's text changes with the edit. A stylesheet the server renders as it did before keeps its live text, which is Vite's to update. One the previous rendering did not carry takes the server's text, as before. With the fix the same run keeps 30px across three patches, and test/integration/styleLatency.js, opened as the canvas opens it (`#avb-design`), still shows every page and component style edit within 100 ms on Astro 7.2.10. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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 bug
A style edit written to a stylesheet that reaches the page through a CSS
@importis lost on the canvas: the file holds the new value, the canvas shows the one from when the dev server started. I hit it on a project whoseglobal.cssimports its sheets with@import "./utilities.css" layer(utilities);, where dragging a padding in the style panel never moved the canvas.The cause
Astro renders such a stylesheet from its first server-side compile for as long as the server runs, while Vite hot-swaps the live
<style>on every write.refreshDevStyles(413e468) copies the server's text into any live dev stylesheet whose text differs, so each patch of the page puts that first compile back over what Vite just wrote.Measured on a real dev server (Astro 7.1.4, a page importing
global.css, which@importsutilities.cssinto a layer), withstyle:writeFileand the page opened as the canvas opens it:padding-leftavb:patch-nowThe fix
The patch takes the server's text only when the server changed it between its previous rendering and this one.
<style>, the case 413e468 fixed, still updates: the server's text changes with the edit.With the fix the same run keeps 30px across three patches.
Tests
test/electron/previewClient/morph.test.jsgets two cases: a hot-swapped stylesheet the server renders stale keeps its text, and a stylesheet new to the rendering takes the server's.test/integration/styleLatency.js, opened with#avb-design, still shows every page and component style edit within 100 ms on Astro 7.2.10, and a text-only edit rewrites no stylesheet.One thing I noticed on the way
npm run integration:styleopens${server.url}/without the#avb-designhash, so the page runs as a browser tab and reloads on a page edit. Its counters come backNaNand "a text-only edit rewrites no stylesheet" fails. I did not check whether that predates this branch, and left the script alone.🤖 Generated with Claude Code