Repository navigation
Fix page-ssr CSS 404s on incrementally cached API pages - #2247
Open
David Pine (IEvangelist) wants to merge 1 commit into
Open
David Pine (IEvangelist) wants to merge 1 commit into
David Pine (IEvangelist) wants to merge 1 commit into
Conversation
UnoCSS fills its page-ssr stylesheet after transform, so Astro's route dependency hash missed changes to it. When the icon safelist (fetched from the network at build time) changed between builds of one commit, restored API reference pages kept linking a page-ssr.*.css that the new build no longer emitted, causing 404s in production. Fold each page's emitted stylesheets into its dependency hash. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
🔵 Needs a closer look
The changed Astro prerender-cache contract cannot be independently verified from this snapshot, and fixture results do not cover the full-site stylesheet graph or production rebuilds with a restored cache.
No open issues 🎉
What changed in this PR
This PR prevents cached API reference pages from linking to missing CSS files after incremental builds on aspire.dev.
Changes:
- Extends Astro’s route dependency hash to include emitted stylesheets, invalidating cached pages when their CSS changes.
- Adds regression coverage for stylesheet changes and continued cache reuse when stylesheets stay unchanged.
- Documents the additional purpose of the Astro patch.
| File | Description |
|---|---|
src/frontend/tests/unit/incremental-build.vitest.test.ts |
Adds a UnoCSS fixture testing stylesheet invalidation and unchanged-page reuse. |
src/frontend/patches/README.md |
Explains how the Astro patch prevents stale stylesheet links. |
src/frontend/patches/astro@7.4.1.patch |
Includes external stylesheet URLs and inline CSS in route dependency hashes. |
Review effort: Balanced
Contributor
Frontend HTML artifact readyThe latest frontend build uploaded the This comment updates automatically when a new frontend build artifact is uploaded. |
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.
Agent assessment
Self-reported assessment, not an independent review.
Assessed revision:
ea8b396ac827b1948a26d74b991b622d76fd06b4↑ Existing incremental reuse/invalidation test still passes.
↓ Full site build and CI not yet observed.
↓ Pages whose sheets change now re-render, so a warm build after a safelist change is slower.
↑ The two CSS files differ only by one icon class (fsharp) from network icon data.
↑ Astro's skip check ignores emitted stylesheets.
↓ Internal production pipeline logs and cache state weren't inspected.
Summary
API reference pages on aspire.dev request
/_astro/page-ssr.Dm8KbnAz.css, which returns 404. Other pages at the same deployed commit (a01bf08) linkpage-ssr.BCTXfwVA.css, which exists.Cause:
starlight-plugin-iconsfetches icon data from the network at build time, and UnoCSS turns the resulting safelist into thepage-ssrstylesheet. UnoCSS fills that CSS after Vite transforms modules, so Astro's incremental-build route dependency hash doesn't see it change. API routes return acacheKeythat covers only the API document and deployment metadata. When the icon data changed between two builds of the same commit, cached API pages were restored with a link to the previous build's stylesheet, which the new build no longer emitted.Fix:
patches/astro@7.4.1.patchnow folds the stylesheets each page links (pageData.styles) into its route dependency hash. A page whose emitted CSS changes is re-rendered, and unchanged pages are still reused. Astro 7.4.12 has the same gap.The live site stays broken until production is rebuilt with this change or with a cleared Astro build cache.
Third-party links and affiliations
None
Validation
vitest run --config vitest.config.ts tests/unit/incremental-build.vitest.test.ts: before the patch, the new test failed with the production symptom (the restored page linkedcompiler.DnzRRV--.csswhile the build emittedcompiler.aYXAaYXT.css). With the patch, both tests pass.vitest run --config vitest.config.ts tests/unit/api-cache-key.vitest.test.ts tests/unit/build-performance.vitest.test.ts: passed (16 tests).eslint tests/unit/incremental-build.vitest.test.ts: passed.bun run build(left to CI).