Skip to content

live: keep the Astro carbonize style block is:inline - #993

Merged
pbakaus merged 1 commit into
mainfrom
fix/live-astro-style-reload
Oct 8, 2026
Merged

pbakaus merged 1 commit into
mainfrom
fix/live-astro-style-reload

Conversation

@pbakaus

@pbakaus pbakaus commented Oct 8, 2026 •

Copy link
Copy Markdown
Owner

Fixes #992.

The problem

On Astro 7.3.6 and later, every live accept that carries CSS ends with a 500 from the dev server and two errors in the browser console (No Astro CSS at index 1, [vite] Failed to reload ...?astro&type=style&index=1&lang.css). The page reloads and ends up correct, but the live-e2e astro-vite7 fixture fails its clean-console check, so the fixture was pinned to astro@7.3.5 to unblock a release.

Root cause

During a session the variants CSS sits in <style is:inline data-impeccable-css="ID">, which Astro's compiler leaves alone. On accept, build_carbonize_replacement wrote a bare <style data-impeccable-css="ID"> for every non-JSX file. In an .astro file Astro compiles that into a ?astro&type=style&index=N module, numbered in source order, ahead of the page's own <style>. The carbonize cleanup then deletes it again in a save that also changes markup.

Astro 7.3.6 (withastro/astro#18076) clears its compile metadata on such a save. The reload of the index that no longer exists then throws in the load hook. Before 7.3.6 the same sequence logged nothing and served stale CSS under the surviving index, so the page's own styles were wrong after an accept until the next edit. Details, the Astro diff, and a reproduction with no impeccable involved are in #992.

So this is both: a rough edge upstream (removing a <style> block together with markup is a 500 in dev) and an inconsistency of ours that walks into it on every accept.

The fix

The carbonize block takes the file type's own styleTag from resolve_source_traits, the same source inject and wrap already use. On .astro that is <style is:inline data-impeccable-css="ID">; everywhere else it is the tag that was hardcoded before, so output for other file types is byte-identical. The set of compiled Astro style modules no longer changes at any point of a live session.

Tests

  • Three unit tests in live_accept.rs: the Astro carbonize block is is:inline (also when the agent wrote the variants tag without it), the HTML block is unchanged.
  • Two new oracle cases recorded from the binary, live-accept-astro-variant-2-steps and live-accept-astro-discard. No existing golden changed.
  • tests/framework-fixtures/astro-vite7 goes back to the floating ^7.1.0 it had before the pin, so CI keeps catching drift. It resolves to 7.3.8 today.
  • docs/CLI-CONTRACT.md gains the Astro line under the carbonize block shape.

Verification

  • IMPECCABLE_E2E_ONLY=astro-vite7 IMPECCABLE_E2E_SCENARIOS=core,agent-target bun run test:live-e2e on Astro 7.3.8: fails with the pinned 0.1.12 release binary, passes with a binary built from this branch.
  • Standalone three-state reproduction (variants, carbonize, clean) on Astro 7.3.5, 7.3.6 and 7.3.8: with the bare tag, 500 on 7.3.6 and 7.3.8 and stale styles on 7.3.5; with is:inline, no failed request and correct computed styles on all three.
  • cargo test --workspace, bun run build, bun run test (with IMPECCABLE_BIN pointing at this branch's build): green.
  • Full bun run test:live-e2e locally: 44 of 47 passed, astro-vite7 among them. vite8-react-plain failed once in the full run and passed when rerun. nextjs-app-router failed on a DOM wait and fails the same way with the pinned release binary on this machine (load average around 12 during the run), at a different step each time, so it does not come from this change. The CI smoke job runs that fixture and is the cleaner signal.

No version bump and no changelog entry. Users get the fix with the next engine release.

This PR was prepared by an AI agent (Claude Code) working under pbakaus's instructions.

🤖 Generated with Claude Code


Note

Medium Risk
Changes live-accept source rewriting for Astro (and any future file types using custom style tags); behavior is covered by new tests and should be byte-identical for non-Astro templates.

Overview
Live accept now emits carbonize <style> openings from each file type’s styleTag (resolve_source_traits) instead of a hardcoded bare <style data-impeccable-css="ID">. On .astro that means is:inline, matching the variants preview block so accept/cleanup no longer add and remove a compiled Astro style module (which triggered dev-server 500s on Astro 7.3.6+ and wrong CSS on earlier versions).

Non-Astro HTML output stays the same. build_carbonize_replacement takes a style_open argument; carbonize_style_open centralizes the tag choice.

Tests & docs: Rust carbonize unit tests (Astro inline vs HTML plain), oracle live-accept-astro-* goldens and stageWrappedAstro, CLI-CONTRACT.md Astro carbonize note, and astro-vite7 fixture dependency restored to ^7.1.0 (drops the 7.3.5 pin).

Reviewed by Cursor Bugbot for commit 2ec8c64. Bugbot is set up for automated code reviews on this repo. Configure here.

On accept, the carbonize block was written with a bare <style> on every
non-JSX file. In an .astro file that is not the same thing as the
is:inline tag the variants block used: Astro compiles it into a
?astro&type=style&index=N module ahead of the page's own, and the
carbonize cleanup then deletes it again together with a markup change.

Astro 7.3.6 (withastro/astro#18076) drops its compile metadata on such a
save, so the reload of the index that vanished fails with "No Astro CSS
at index 1": a 500 in the dev server and two errors in the browser
console after every accept that carries CSS. On 7.3.5 and earlier the
same sequence logged nothing but served stale CSS under the surviving
index.

The carbonize block now takes the file type's own styleTag, so on Astro
it stays is:inline and the set of compiled style modules never changes
during a session. Output for every other file type is byte-identical.

The astro-vite7 live-e2e fixture goes back to a floating ^7.1.0 (it was
pinned to 7.3.5 to unblock a release). New oracle cases
live-accept-astro-variant-2-steps and live-accept-astro-discard were
recorded from the binary; no existing golden changed.

Fixes #992

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Copilot AI balanced review requested due to automatic review settings October 8, 2026 21:22

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The targeted fix is consistent with source traits and is covered across unit, oracle, and runtime tests.

0 open findings

What changed in this PR

Fixes Astro live-accept styling by preserving is:inline during carbonization, preventing style-module churn and dev-server errors.

Changes:

  • Uses source-specific style tags during carbonization.
  • Adds Rust, oracle, and Astro runtime regression coverage.
  • Restores floating Astro 7 fixture updates and documents the behavior.
File Description
crates/​live/​src/​live_accept.rs Preserves Astro’s inline style tag and adds unit tests.
docs/​CLI-CONTRACT.md Documents Astro carbonization behavior.
tests/​framework-fixtures/​astro-vite7/​files/​package.json Restores the Astro 7 version range.
tests/​oracle/​cases/​live-accept.mjs Adds Astro accept and discard cases.
tests/​oracle/​live-helpers.mjs Adds Astro wrapper staging.
tests/​oracle/​golden/​live-accept-astro-variant-2-steps.json Records Astro accept output.
tests/​oracle/​golden/​live-accept-astro-discard.json Records Astro discard output.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@greptile-apps

greptile-apps Bot commented Oct 8, 2026 •

Copy link
Copy Markdown

RetriggerConfidence Score: 5/5

[Medium impact] This PR appears safe to merge; no actionable issues were found.

Summary

Keeps the temporary CSS block marked is:inline when accepting a live variant in .astro files. Other file types keep their existing output.

  • Reuses the file type’s styleTag instead of a hardcoded tag.
  • Adds three Rust tests and two Astro oracle cases.
  • Documents the Astro tag and restores the fixture’s floating Astro range.

Acknowledged intent: pbakaus explicitly chose the floating fixture range so CI keeps catching framework changes. The PR also identifies unrelated full-suite failures as pre-existing or intermittent; these were not treated as findings.

Reviews (1) · Last reviewed commit: "live: keep the Astro carbonize style blo..." · Reviewed by Greptile

@pbakaus
pbakaus merged commit d8c478a into main Oct 8, 2026
22 checks passed
@linear-code

linear-code Bot commented Oct 8, 2026

Copy link
Copy Markdown

REN-758

@pbakaus
pbakaus deleted the fix/live-astro-style-reload branch October 8, 2026 23:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] live: accept on Astro 7.3.6+ makes the dev server 500 on a style module (carbonize block drops is:inline)

2 participants