Commit 9b3241d
Allow adapters to customize headers for fetch requests (#14543)
* feat: add adapter support for internal fetch headers (Netlify skew protection)
Adds a new generic mechanism for adapters to inject headers into Astro's internal fetch calls. This enables features like Netlify's skew protection.
Changes:
- Add `runtimeConfig.internalFetchHeaders` to AstroAdapter interface
- Create `astro:adapter-config/client` virtual module
- Update Actions, View Transitions, Server Islands, and Prefetch to use adapter headers
- Implement Netlify skew protection with DEPLOY_ID header
- Generate `.netlify/v1/skew-protection.json` configuration file
- Add comprehensive test fixture for skew protection
* fix: resolve TypeScript errors in adapter config implementation
- Add type declarations for astro:adapter-config/client virtual module
- Add manifest property to SSRResult interface
- Fix Object.entries type assertions in prefetch and router
- Add explicit return type to Netlify adapter's internalFetchHeaders function
* refactor: extract internalFetchHeaders from manifest into SSRResult
Follow existing pattern of extracting specific fields from manifest rather than passing the entire manifest object to SSRResult. This matches how other fields like base, trailingSlash, and serverIslandNameMap are handled.
* Address PR feedback: clean up tests and update comment
- Remove incomplete test stubs for actions and view transitions
- Remove unused manifestPath variable
- Update prefetch comment to be less strict about dependencies
* Fix import sorting in create-vite and router files
* Fix skew protection test to check correct manifest file
The test was checking ssr.mjs which is just a wrapper, but the actual
serialized manifest is in the manifest_*.mjs file in the build directory.
* Fix virtual module to return empty headers during SSR
This prevents timeouts in integration tests where client-side files
importing the virtual module are processed during SSR.
* review changes
* Update .changeset/netlify-skew-protection.md
Co-authored-by: Sarah Rainsberger <5098874+sarah11918@users.noreply.github.com>
* fix lint
* Update packages/astro/dev-only.d.ts
Co-authored-by: Florian Lefebvre <contact@florian-lefebvre.dev>
* Add assetQueryParams support for skew protection
This adds a new `assetQueryParams` configuration option to the adapter client config that allows adapters to append query parameters to all static asset URLs. This is used for Vercel's skew protection to track deployment versions.
Changes:
- Extended AstroAdapter.client interface with assetQueryParams property
- Modified getAssetsPrefix() to accept and append query parameters
- Updated manifest builder to include query params in all asset URLs
- Updated SSR element creation functions to support query params
- Updated Vercel adapter to provide deployment ID as query param when skew protection is enabled
This ensures that all asset requests include the deployment identifier, allowing Vercel to route them to the correct deployment version if there's a version mismatch between client and server.
* update imports
* update based on review comments
* switch to use URLSearchParams
* remove unneeded file
* align vercel impl with how the other works
* focus changesets a bit more
* Update .changeset/astro-asset-query-params.md
Co-authored-by: Sarah Rainsberger <5098874+sarah11918@users.noreply.github.com>
* Update .changeset/astro-asset-query-params.md
Co-authored-by: Sarah Rainsberger <5098874+sarah11918@users.noreply.github.com>
* explain how to do it yourself too
* oops
* Update packages/integrations/vercel/src/index.ts
Co-authored-by: Steven <steven@ceriously.com>
---------
Co-authored-by: Sarah Rainsberger <5098874+sarah11918@users.noreply.github.com>
Co-authored-by: Florian Lefebvre <contact@florian-lefebvre.dev>
Co-authored-by: Steven <steven@ceriously.com>1 parent e735d85 commit 9b3241d
File tree
29 files changed
+398
-23
lines changed- .changeset
- packages
- astro
- src
- actions/runtime
- assets/utils
- core
- app
- build/plugins
- render
- prefetch
- runtime/server/render
- transitions
- types/public
- vite-plugin-adapter-config
- integrations
- netlify
- src
- test/functions
- fixtures/skew-protection
- src
- actions
- components
- pages
- vercel/src
29 files changed
+398
-23
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
14 | 18 | | |
15 | 19 | | |
16 | 20 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
| 2 | + | |
2 | 3 | | |
3 | 4 | | |
4 | 5 | | |
| |||
94 | 95 | | |
95 | 96 | | |
96 | 97 | | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
97 | 102 | | |
98 | 103 | | |
99 | 104 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
4 | | - | |
5 | | - | |
6 | | - | |
7 | | - | |
8 | | - | |
9 | | - | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
10 | 16 | | |
11 | | - | |
| 17 | + | |
| 18 | + | |
12 | 19 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
95 | 95 | | |
96 | 96 | | |
97 | 97 | | |
| 98 | + | |
98 | 99 | | |
99 | 100 | | |
100 | 101 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
202 | 202 | | |
203 | 203 | | |
204 | 204 | | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
205 | 208 | | |
| 209 | + | |
206 | 210 | | |
207 | 211 | | |
208 | | - | |
| 212 | + | |
209 | 213 | | |
210 | | - | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
211 | 218 | | |
| 219 | + | |
212 | 220 | | |
213 | 221 | | |
214 | 222 | | |
| |||
341 | 349 | | |
342 | 350 | | |
343 | 351 | | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
344 | 364 | | |
345 | 365 | | |
346 | 366 | | |
| |||
372 | 392 | | |
373 | 393 | | |
374 | 394 | | |
| 395 | + | |
375 | 396 | | |
376 | 397 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
| 24 | + | |
24 | 25 | | |
25 | 26 | | |
26 | 27 | | |
| |||
156 | 157 | | |
157 | 158 | | |
158 | 159 | | |
| 160 | + | |
159 | 161 | | |
160 | 162 | | |
161 | 163 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
572 | 572 | | |
573 | 573 | | |
574 | 574 | | |
| 575 | + | |
575 | 576 | | |
576 | 577 | | |
577 | 578 | | |
| |||
0 commit comments