-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
feat(csp): server islands #13775
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(csp): server islands #13775
Conversation
|
81aaf83 to
7850461
Compare
7850461 to
53e1f7a
Compare
abaca7e to
13478f1
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not very familiar with this part of Astro but I haven't seen anything weird, LGTM!
Co-authored-by: florian-lefebvre <[email protected]>
Co-authored-by: florian-lefebvre <[email protected]>
* 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]>
* 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]>
Changes
This adds support for CSP for server islands. To support this feature, we have to apply a refactor to how server islands are rendered inside our engine. The new version of the compiler adds the
propagationmetadata to a route when one of its modules contains theserver:deferattribute.With that information available, the server island has been refactored into a class that contains two methods:
initandrender.The method
initis the important one, because that's the method that gets called when executing the head propagation. Theinitis called inside the following function:astro/packages/astro/src/runtime/server/render/astro/render.ts
Lines 186 to 199 in 1609044
As you might noticed, we also check if the returned value is an actual head. To comply, I created a new
ThinHeadtype that just holds theSymbolthat we use to tag head content. I created this type because the server island, as for now, doesn't return any content. I decided not to return any content to keep the rendering as similar as possible the one we have now. Of course, this changed regardless, because now some scripts are rendered in the head, as you might notice inextraHead.push()The rendering of the server island changed slightly:
initmethod, but not thefallbackslotfallbackslot is rendered inside therendermethodinit, we savehostIdand the content of the scripts so we can render them inside therenderfunctionFinally, when we create a
ServerIslandComponent, we add it to the list ofpropagators. These components are called inside the function I showed at the very beginning :)Testing
The current tests should still pass.
Created new tests: integration and e2e
Docs
N/A