Skip to content

Conversation

@ematipico
Copy link
Member

Changes

This PR updates Astro to use the information we already have of scripts and styles to create hashes and render them in the emitted HTML page.

This PR focus only SSG for now, I will follow up with another PR to implement the same logic for SSR.

  • SSRManifest has been extended to track new information, such as hashes coming from scripts and styles. I prefer to keep them separated because we handle them differently throughout the code base.
  • SSRResult has been extended to pass the hashes during the rendering phase. As for now, these hashes are always injected. I will change that later, and inject them only for static outputs. I need to find a way to test the static output with predictable hashes.
  • ASTRO_STYLES has been moved into a separate file, so I could add a better warning about its value. The script prebuild.js has been updated to track the hash of the styles of astro islands
  • The hashes of the astro island scripts are now compiled into a TS file, and it's imported when creating the manifest (they aren't used yet)

At the moment, the hashes of scripts and styles aren't grouped by page, but I believe we can achieve that.

Testing

I created a test for SSG, where we verify that the hashes we have in the manifest are the same of the one rendered in the final HTML file.

Docs

N/A

@changeset-bot
Copy link

changeset-bot bot commented Apr 23, 2025

⚠️ No Changeset found

Latest commit: 320d9b3

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@github-actions github-actions bot added pkg: astro Related to the core `astro` package (scope) docs pr labels Apr 23, 2025
@ematipico ematipico force-pushed the feat/csp-render-head branch from bf9697a to a80ed77 Compare April 23, 2025 11:09
@ematipico ematipico merged commit b9320db into feat/csp Apr 23, 2025
15 checks passed
@ematipico ematipico deleted the feat/csp-render-head branch April 23, 2025 12:56
ematipico added a commit that referenced this pull request Apr 23, 2025
ematipico added a commit that referenced this pull request May 1, 2025
ematipico added a commit that referenced this pull request May 14, 2025
ematipico added a commit that referenced this pull request May 22, 2025
ascorbic added a commit that referenced this pull request Jun 4, 2025
* chore: build hashes of scripts (#13590)

* chore: build hashes of scripts

* chore: fix changes

* chore: fix changes

* chore: fix changes

* feat(csp): create hashes of tracked scripts and hashes (#13675)

Co-authored-by: florian-lefebvre <[email protected]>

* feat(csp): fix CSP header, inject astro island script/style (#13687)

* feat(csp): track client scripts and CSS (#13725)

Co-authored-by: ascorbic <[email protected]>

* feat(csp): support view transitions (#13738)

Co-authored-by: florian-lefebvre <[email protected]>
Co-authored-by: ascorbic <[email protected]>
fix CSP header, inject astro island script/style (#13687)

* feat(csp): server islands (#13775)

Co-authored-by: florian-lefebvre <[email protected]>

* feat(csp): customise algorithm (#13803)

Co-authored-by: Florian Lefebvre <[email protected]>

* chore: build hashes of scripts (#13590) (#13805)

Co-authored-by: Florian Lefebvre <[email protected]>

* feat(csp): allow additional directives (#13810)

Co-authored-by: ascorbic <[email protected]>
Co-authored-by: florian-lefebvre <[email protected]>

* feat(csp): resources for script and styles directives (#13812)

Co-authored-by: ascorbic <[email protected]>

* feat(csp): runtime APIs (#13824)

Co-authored-by: Matt Kane <[email protected]>

* feat(csp): add script-dynamic keyword support (#13834)

* update lockfile

* chore: docs and changeset (#13870)

* chore: add changeset

* grammar

* Apply suggestions from code review

Co-authored-by: Sarah Rainsberger <[email protected]>

* Update JSDoc with examples to match docs

* Sarah's changeset edits

* Apply suggestions from code review

Thanks, @ArmandPhilippot

Co-authored-by: Armand Philippot <[email protected]>

* Fix indentation

* Update .changeset/crazy-doors-buy.md

* Apply suggestions from code review

Co-authored-by: Sarah Rainsberger <[email protected]>

---------

Co-authored-by: Sarah Rainsberger <[email protected]>
Co-authored-by: Matt Kane <[email protected]>
Co-authored-by: Armand Philippot <[email protected]>

* Update lockfile

* dedupe deps

* Lock

* Lock

* fix: server islands in mdx

---------

Co-authored-by: florian-lefebvre <[email protected]>
Co-authored-by: ascorbic <[email protected]>
Co-authored-by: Florian Lefebvre <[email protected]>
Co-authored-by: Matt Kane <[email protected]>
Co-authored-by: Sarah Rainsberger <[email protected]>
Co-authored-by: Armand Philippot <[email protected]>
openscript pushed a commit to openscript/astro that referenced this pull request Sep 12, 2025
* chore: build hashes of scripts (withastro#13590)

* chore: build hashes of scripts

* chore: fix changes

* chore: fix changes

* chore: fix changes

* feat(csp): create hashes of tracked scripts and hashes (withastro#13675)

Co-authored-by: florian-lefebvre <[email protected]>

* feat(csp): fix CSP header, inject astro island script/style (withastro#13687)

* feat(csp): track client scripts and CSS (withastro#13725)

Co-authored-by: ascorbic <[email protected]>

* feat(csp): support view transitions (withastro#13738)

Co-authored-by: florian-lefebvre <[email protected]>
Co-authored-by: ascorbic <[email protected]>
fix CSP header, inject astro island script/style (withastro#13687)

* feat(csp): server islands (withastro#13775)

Co-authored-by: florian-lefebvre <[email protected]>

* feat(csp): customise algorithm (withastro#13803)

Co-authored-by: Florian Lefebvre <[email protected]>

* chore: build hashes of scripts (withastro#13590) (withastro#13805)

Co-authored-by: Florian Lefebvre <[email protected]>

* feat(csp): allow additional directives (withastro#13810)

Co-authored-by: ascorbic <[email protected]>
Co-authored-by: florian-lefebvre <[email protected]>

* feat(csp): resources for script and styles directives (withastro#13812)

Co-authored-by: ascorbic <[email protected]>

* feat(csp): runtime APIs (withastro#13824)

Co-authored-by: Matt Kane <[email protected]>

* feat(csp): add script-dynamic keyword support (withastro#13834)

* update lockfile

* chore: docs and changeset (withastro#13870)

* chore: add changeset

* grammar

* Apply suggestions from code review

Co-authored-by: Sarah Rainsberger <[email protected]>

* Update JSDoc with examples to match docs

* Sarah's changeset edits

* Apply suggestions from code review

Thanks, @ArmandPhilippot

Co-authored-by: Armand Philippot <[email protected]>

* Fix indentation

* Update .changeset/crazy-doors-buy.md

* Apply suggestions from code review

Co-authored-by: Sarah Rainsberger <[email protected]>

---------

Co-authored-by: Sarah Rainsberger <[email protected]>
Co-authored-by: Matt Kane <[email protected]>
Co-authored-by: Armand Philippot <[email protected]>

* Update lockfile

* dedupe deps

* Lock

* Lock

* fix: server islands in mdx

---------

Co-authored-by: florian-lefebvre <[email protected]>
Co-authored-by: ascorbic <[email protected]>
Co-authored-by: Florian Lefebvre <[email protected]>
Co-authored-by: Matt Kane <[email protected]>
Co-authored-by: Sarah Rainsberger <[email protected]>
Co-authored-by: Armand Philippot <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs pr pkg: astro Related to the core `astro` package (scope)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants