From b0493596dc338377198d0a39efc813dad515b624 Mon Sep 17 00:00:00 2001 From: Bjorn Lu Date: Mon, 14 Oct 2024 15:12:42 +0800 Subject: [PATCH 1/9] Fix setOnSetGetEnv parameter name (#12220) Co-authored-by: Fugi --- .changeset/bright-bananas-run.md | 5 +++++ packages/astro/templates/env/module.mjs | 4 +++- 2 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 .changeset/bright-bananas-run.md diff --git a/.changeset/bright-bananas-run.md b/.changeset/bright-bananas-run.md new file mode 100644 index 0000000000..cf812cfdd6 --- /dev/null +++ b/.changeset/bright-bananas-run.md @@ -0,0 +1,5 @@ +--- +"astro": patch +--- + +Fixes accidental internal `setOnSetGetEnv` parameter rename that caused runtime errors diff --git a/packages/astro/templates/env/module.mjs b/packages/astro/templates/env/module.mjs index 648556cf12..4144dde5b7 100644 --- a/packages/astro/templates/env/module.mjs +++ b/packages/astro/templates/env/module.mjs @@ -26,6 +26,8 @@ const _internalGetSecret = (key) => { }; // used while generating the virtual module -setOnSetGetEnv((_reset) => { +// biome-ignore lint/correctness/noUnusedFunctionParameters: `reset` is used by the generated code +// biome-ignore lint/correctness/noUnusedVariables: `reset` is used by the generated code +setOnSetGetEnv((reset) => { // @@ON_SET_GET_ENV@@ }); From 2aa2dfd05dc7b7e6ad13451e6cc2afa9b1c92a32 Mon Sep 17 00:00:00 2001 From: Emanuele Stoppa Date: Mon, 14 Oct 2024 09:44:39 +0100 Subject: [PATCH 2/9] fix: revert regression of port computation (#12197) * fix: revert regression of port computation * revert tests failing * address feedback * revert logic to how it was before --- .changeset/tidy-dancers-act.md | 5 +++++ packages/astro/src/core/app/node.ts | 9 ++++----- 2 files changed, 9 insertions(+), 5 deletions(-) create mode 100644 .changeset/tidy-dancers-act.md diff --git a/.changeset/tidy-dancers-act.md b/.changeset/tidy-dancers-act.md new file mode 100644 index 0000000000..abe7895da1 --- /dev/null +++ b/.changeset/tidy-dancers-act.md @@ -0,0 +1,5 @@ +--- +'astro': patch +--- + +Fix a regression where a port was incorrectly added to the `Astro.url` diff --git a/packages/astro/src/core/app/node.ts b/packages/astro/src/core/app/node.ts index 87ef2a0def..3ad965cd08 100644 --- a/packages/astro/src/core/app/node.ts +++ b/packages/astro/src/core/app/node.ts @@ -83,13 +83,12 @@ export class NodeApp extends App { const hostname = forwardedHostname ?? req.headers.host ?? req.headers[':authority']; // @example "443,8080,80" => "443" - const forwardedPort = getFirstForwardedValue(req.headers['x-forwarded-port']); - const port = - forwardedPort ?? req.socket?.remotePort?.toString() ?? (isEncrypted ? '443' : '80'); + const port = getFirstForwardedValue(req.headers['x-forwarded-port']); const portInHostname = typeof hostname === 'string' && /:\d+$/.test(hostname); - const hostnamePort = portInHostname ? hostname : `${hostname}:${port}`; - + const hostnamePort = portInHostname ? hostname : `${hostname}${port ? `:${port}` : ''}`; + + const url = `${protocol}://${hostnamePort}${req.url}`; const options: RequestInit = { method: req.method || 'GET', From 59a2fbc2132f34c4be3b2d80b0fb70e90bd081c4 Mon Sep 17 00:00:00 2001 From: Emanuele Stoppa Date: Mon, 14 Oct 2024 08:45:25 +0000 Subject: [PATCH 3/9] [ci] format --- packages/astro/src/core/app/node.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/astro/src/core/app/node.ts b/packages/astro/src/core/app/node.ts index 3ad965cd08..ff80c4e14e 100644 --- a/packages/astro/src/core/app/node.ts +++ b/packages/astro/src/core/app/node.ts @@ -87,8 +87,7 @@ export class NodeApp extends App { const portInHostname = typeof hostname === 'string' && /:\d+$/.test(hostname); const hostnamePort = portInHostname ? hostname : `${hostname}${port ? `:${port}` : ''}`; - - + const url = `${protocol}://${hostnamePort}${req.url}`; const options: RequestInit = { method: req.method || 'GET', From a33804110df32a7b5d1ae5b77c5a2e050541de79 Mon Sep 17 00:00:00 2001 From: "Houston (Bot)" <108291165+astrobot-houston@users.noreply.github.com> Date: Mon, 14 Oct 2024 01:55:46 -0700 Subject: [PATCH 4/9] [ci] release (#12221) Co-authored-by: github-actions[bot] --- .changeset/bright-bananas-run.md | 5 --- .changeset/tidy-dancers-act.md | 5 --- examples/basics/package.json | 2 +- examples/blog/package.json | 2 +- examples/component/package.json | 2 +- examples/container-with-vitest/package.json | 2 +- examples/framework-alpine/package.json | 2 +- examples/framework-lit/package.json | 2 +- examples/framework-multiple/package.json | 2 +- examples/framework-preact/package.json | 2 +- examples/framework-react/package.json | 2 +- examples/framework-solid/package.json | 2 +- examples/framework-svelte/package.json | 2 +- examples/framework-vue/package.json | 2 +- examples/hackernews/package.json | 2 +- examples/integration/package.json | 2 +- examples/minimal/package.json | 2 +- examples/portfolio/package.json | 2 +- examples/ssr/package.json | 2 +- examples/starlog/package.json | 2 +- examples/toolbar-app/package.json | 2 +- examples/with-markdoc/package.json | 2 +- examples/with-mdx/package.json | 2 +- examples/with-nanostores/package.json | 2 +- examples/with-tailwindcss/package.json | 2 +- examples/with-vitest/package.json | 2 +- packages/astro/CHANGELOG.md | 8 ++++ packages/astro/package.json | 2 +- pnpm-lock.yaml | 48 ++++++++++----------- 29 files changed, 57 insertions(+), 59 deletions(-) delete mode 100644 .changeset/bright-bananas-run.md delete mode 100644 .changeset/tidy-dancers-act.md diff --git a/.changeset/bright-bananas-run.md b/.changeset/bright-bananas-run.md deleted file mode 100644 index cf812cfdd6..0000000000 --- a/.changeset/bright-bananas-run.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -"astro": patch ---- - -Fixes accidental internal `setOnSetGetEnv` parameter rename that caused runtime errors diff --git a/.changeset/tidy-dancers-act.md b/.changeset/tidy-dancers-act.md deleted file mode 100644 index abe7895da1..0000000000 --- a/.changeset/tidy-dancers-act.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -'astro': patch ---- - -Fix a regression where a port was incorrectly added to the `Astro.url` diff --git a/examples/basics/package.json b/examples/basics/package.json index 45a4d6819f..67ac030aec 100644 --- a/examples/basics/package.json +++ b/examples/basics/package.json @@ -11,6 +11,6 @@ "astro": "astro" }, "dependencies": { - "astro": "^4.16.2" + "astro": "^4.16.3" } } diff --git a/examples/blog/package.json b/examples/blog/package.json index 2e66bd1f86..5a875765e1 100644 --- a/examples/blog/package.json +++ b/examples/blog/package.json @@ -14,6 +14,6 @@ "@astrojs/mdx": "^3.1.8", "@astrojs/rss": "^4.0.8", "@astrojs/sitemap": "^3.2.0", - "astro": "^4.16.2" + "astro": "^4.16.3" } } diff --git a/examples/component/package.json b/examples/component/package.json index 85bc36ecd6..ed83162781 100644 --- a/examples/component/package.json +++ b/examples/component/package.json @@ -15,7 +15,7 @@ ], "scripts": {}, "devDependencies": { - "astro": "^4.16.2" + "astro": "^4.16.3" }, "peerDependencies": { "astro": "^4.0.0" diff --git a/examples/container-with-vitest/package.json b/examples/container-with-vitest/package.json index d017b4e2d7..260cb00f6b 100644 --- a/examples/container-with-vitest/package.json +++ b/examples/container-with-vitest/package.json @@ -12,7 +12,7 @@ "test": "vitest run" }, "dependencies": { - "astro": "^4.16.2", + "astro": "^4.16.3", "@astrojs/react": "^3.6.2", "react": "^18.3.1", "react-dom": "^18.3.1", diff --git a/examples/framework-alpine/package.json b/examples/framework-alpine/package.json index fed6acb1ed..e6c27023aa 100644 --- a/examples/framework-alpine/package.json +++ b/examples/framework-alpine/package.json @@ -14,6 +14,6 @@ "@astrojs/alpinejs": "^0.4.0", "@types/alpinejs": "^3.13.10", "alpinejs": "^3.14.1", - "astro": "^4.16.2" + "astro": "^4.16.3" } } diff --git a/examples/framework-lit/package.json b/examples/framework-lit/package.json index adf093eecb..4c437bc5ea 100644 --- a/examples/framework-lit/package.json +++ b/examples/framework-lit/package.json @@ -13,7 +13,7 @@ "dependencies": { "@astrojs/lit": "^4.3.0", "@webcomponents/template-shadowroot": "^0.2.1", - "astro": "^4.16.2", + "astro": "^4.16.3", "lit": "^3.2.0" } } diff --git a/examples/framework-multiple/package.json b/examples/framework-multiple/package.json index b1dbdbdc89..3f8ab04edc 100644 --- a/examples/framework-multiple/package.json +++ b/examples/framework-multiple/package.json @@ -18,7 +18,7 @@ "@astrojs/vue": "^4.5.2", "@types/react": "^18.3.11", "@types/react-dom": "^18.3.0", - "astro": "^4.16.2", + "astro": "^4.16.3", "preact": "^10.24.2", "react": "^18.3.1", "react-dom": "^18.3.1", diff --git a/examples/framework-preact/package.json b/examples/framework-preact/package.json index 9a9517e90a..95c4043779 100644 --- a/examples/framework-preact/package.json +++ b/examples/framework-preact/package.json @@ -13,7 +13,7 @@ "dependencies": { "@astrojs/preact": "^3.5.3", "@preact/signals": "^1.3.0", - "astro": "^4.16.2", + "astro": "^4.16.3", "preact": "^10.24.2" } } diff --git a/examples/framework-react/package.json b/examples/framework-react/package.json index b3d7916635..78f617437d 100644 --- a/examples/framework-react/package.json +++ b/examples/framework-react/package.json @@ -14,7 +14,7 @@ "@astrojs/react": "^3.6.2", "@types/react": "^18.3.11", "@types/react-dom": "^18.3.0", - "astro": "^4.16.2", + "astro": "^4.16.3", "react": "^18.3.1", "react-dom": "^18.3.1" } diff --git a/examples/framework-solid/package.json b/examples/framework-solid/package.json index 2b9b241275..6d8db3a999 100644 --- a/examples/framework-solid/package.json +++ b/examples/framework-solid/package.json @@ -12,7 +12,7 @@ }, "dependencies": { "@astrojs/solid-js": "^4.4.2", - "astro": "^4.16.2", + "astro": "^4.16.3", "solid-js": "^1.9.1" } } diff --git a/examples/framework-svelte/package.json b/examples/framework-svelte/package.json index fea663dc42..a301c46dca 100644 --- a/examples/framework-svelte/package.json +++ b/examples/framework-svelte/package.json @@ -12,7 +12,7 @@ }, "dependencies": { "@astrojs/svelte": "^5.7.2", - "astro": "^4.16.2", + "astro": "^4.16.3", "svelte": "^4.2.19" } } diff --git a/examples/framework-vue/package.json b/examples/framework-vue/package.json index 88b83cc361..3d6858ee7e 100644 --- a/examples/framework-vue/package.json +++ b/examples/framework-vue/package.json @@ -12,7 +12,7 @@ }, "dependencies": { "@astrojs/vue": "^4.5.2", - "astro": "^4.16.2", + "astro": "^4.16.3", "vue": "^3.5.11" } } diff --git a/examples/hackernews/package.json b/examples/hackernews/package.json index 6e99ec8a04..b3b5549f7e 100644 --- a/examples/hackernews/package.json +++ b/examples/hackernews/package.json @@ -12,6 +12,6 @@ }, "dependencies": { "@astrojs/node": "^8.3.4", - "astro": "^4.16.2" + "astro": "^4.16.3" } } diff --git a/examples/integration/package.json b/examples/integration/package.json index 5ccb188a6f..760e5df099 100644 --- a/examples/integration/package.json +++ b/examples/integration/package.json @@ -15,7 +15,7 @@ ], "scripts": {}, "devDependencies": { - "astro": "^4.16.2" + "astro": "^4.16.3" }, "peerDependencies": { "astro": "^4.0.0" diff --git a/examples/minimal/package.json b/examples/minimal/package.json index a044695461..f2b36332d3 100644 --- a/examples/minimal/package.json +++ b/examples/minimal/package.json @@ -11,6 +11,6 @@ "astro": "astro" }, "dependencies": { - "astro": "^4.16.2" + "astro": "^4.16.3" } } diff --git a/examples/portfolio/package.json b/examples/portfolio/package.json index bf2620b50c..a0b9eee55e 100644 --- a/examples/portfolio/package.json +++ b/examples/portfolio/package.json @@ -11,6 +11,6 @@ "astro": "astro" }, "dependencies": { - "astro": "^4.16.2" + "astro": "^4.16.3" } } diff --git a/examples/ssr/package.json b/examples/ssr/package.json index f4e6addb57..2f2c1698f7 100644 --- a/examples/ssr/package.json +++ b/examples/ssr/package.json @@ -14,7 +14,7 @@ "dependencies": { "@astrojs/node": "^8.3.4", "@astrojs/svelte": "^5.7.2", - "astro": "^4.16.2", + "astro": "^4.16.3", "svelte": "^4.2.19" } } diff --git a/examples/starlog/package.json b/examples/starlog/package.json index 0df145bca3..51b908d801 100644 --- a/examples/starlog/package.json +++ b/examples/starlog/package.json @@ -10,7 +10,7 @@ "astro": "astro" }, "dependencies": { - "astro": "^4.16.2", + "astro": "^4.16.3", "sass": "^1.79.4", "sharp": "^0.33.3" } diff --git a/examples/toolbar-app/package.json b/examples/toolbar-app/package.json index 1a1bb089fc..68bc16f246 100644 --- a/examples/toolbar-app/package.json +++ b/examples/toolbar-app/package.json @@ -15,6 +15,6 @@ "./app": "./dist/app.js" }, "devDependencies": { - "astro": "^4.16.2" + "astro": "^4.16.3" } } diff --git a/examples/with-markdoc/package.json b/examples/with-markdoc/package.json index 74ab8917e8..b48f790764 100644 --- a/examples/with-markdoc/package.json +++ b/examples/with-markdoc/package.json @@ -12,6 +12,6 @@ }, "dependencies": { "@astrojs/markdoc": "^0.11.5", - "astro": "^4.16.2" + "astro": "^4.16.3" } } diff --git a/examples/with-mdx/package.json b/examples/with-mdx/package.json index 79e8addd2f..fb3a90eadc 100644 --- a/examples/with-mdx/package.json +++ b/examples/with-mdx/package.json @@ -13,7 +13,7 @@ "dependencies": { "@astrojs/mdx": "^3.1.8", "@astrojs/preact": "^3.5.3", - "astro": "^4.16.2", + "astro": "^4.16.3", "preact": "^10.24.2" } } diff --git a/examples/with-nanostores/package.json b/examples/with-nanostores/package.json index c4509ea624..fb700b3911 100644 --- a/examples/with-nanostores/package.json +++ b/examples/with-nanostores/package.json @@ -13,7 +13,7 @@ "dependencies": { "@astrojs/preact": "^3.5.3", "@nanostores/preact": "^0.5.2", - "astro": "^4.16.2", + "astro": "^4.16.3", "nanostores": "^0.11.3", "preact": "^10.24.2" } diff --git a/examples/with-tailwindcss/package.json b/examples/with-tailwindcss/package.json index 69dada7bd6..0b43ff3689 100644 --- a/examples/with-tailwindcss/package.json +++ b/examples/with-tailwindcss/package.json @@ -14,7 +14,7 @@ "@astrojs/mdx": "^3.1.8", "@astrojs/tailwind": "^5.1.2", "@types/canvas-confetti": "^1.6.4", - "astro": "^4.16.2", + "astro": "^4.16.3", "autoprefixer": "^10.4.20", "canvas-confetti": "^1.9.3", "postcss": "^8.4.47", diff --git a/examples/with-vitest/package.json b/examples/with-vitest/package.json index defcf48489..a0cf5747aa 100644 --- a/examples/with-vitest/package.json +++ b/examples/with-vitest/package.json @@ -12,7 +12,7 @@ "test": "vitest" }, "dependencies": { - "astro": "^4.16.2", + "astro": "^4.16.3", "vitest": "^2.1.2" } } diff --git a/packages/astro/CHANGELOG.md b/packages/astro/CHANGELOG.md index 37f6917f7d..8312da15df 100644 --- a/packages/astro/CHANGELOG.md +++ b/packages/astro/CHANGELOG.md @@ -1,5 +1,13 @@ # astro +## 4.16.3 + +### Patch Changes + +- [#12220](https://github.com/withastro/astro/pull/12220) [`b049359`](https://github.com/withastro/astro/commit/b0493596dc338377198d0a39efc813dad515b624) Thanks [@bluwy](https://github.com/bluwy)! - Fixes accidental internal `setOnSetGetEnv` parameter rename that caused runtime errors + +- [#12197](https://github.com/withastro/astro/pull/12197) [`2aa2dfd`](https://github.com/withastro/astro/commit/2aa2dfd05dc7b7e6ad13451e6cc2afa9b1c92a32) Thanks [@ematipico](https://github.com/ematipico)! - Fix a regression where a port was incorrectly added to the `Astro.url` + ## 4.16.2 ### Patch Changes diff --git a/packages/astro/package.json b/packages/astro/package.json index a5dd2f4a17..c0d9965650 100644 --- a/packages/astro/package.json +++ b/packages/astro/package.json @@ -1,6 +1,6 @@ { "name": "astro", - "version": "4.16.2", + "version": "4.16.3", "description": "Astro is a modern site builder with web best practices, performance, and DX front-of-mind.", "type": "module", "author": "withastro", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index c278ff4202..9ee4fe3123 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -113,7 +113,7 @@ importers: examples/basics: dependencies: astro: - specifier: ^4.16.2 + specifier: ^4.16.3 version: link:../../packages/astro examples/blog: @@ -128,13 +128,13 @@ importers: specifier: ^3.2.0 version: link:../../packages/integrations/sitemap astro: - specifier: ^4.16.2 + specifier: ^4.16.3 version: link:../../packages/astro examples/component: devDependencies: astro: - specifier: ^4.16.2 + specifier: ^4.16.3 version: link:../../packages/astro examples/container-with-vitest: @@ -143,7 +143,7 @@ importers: specifier: ^3.6.2 version: link:../../packages/integrations/react astro: - specifier: ^4.16.2 + specifier: ^4.16.3 version: link:../../packages/astro react: specifier: ^18.3.1 @@ -174,7 +174,7 @@ importers: specifier: ^3.14.1 version: 3.14.1 astro: - specifier: ^4.16.2 + specifier: ^4.16.3 version: link:../../packages/astro examples/framework-lit: @@ -186,7 +186,7 @@ importers: specifier: ^0.2.1 version: 0.2.1 astro: - specifier: ^4.16.2 + specifier: ^4.16.3 version: link:../../packages/astro lit: specifier: ^3.2.0 @@ -216,7 +216,7 @@ importers: specifier: ^18.3.0 version: 18.3.0 astro: - specifier: ^4.16.2 + specifier: ^4.16.3 version: link:../../packages/astro preact: specifier: ^10.24.2 @@ -246,7 +246,7 @@ importers: specifier: ^1.3.0 version: 1.3.0(preact@10.24.2) astro: - specifier: ^4.16.2 + specifier: ^4.16.3 version: link:../../packages/astro preact: specifier: ^10.24.2 @@ -264,7 +264,7 @@ importers: specifier: ^18.3.0 version: 18.3.0 astro: - specifier: ^4.16.2 + specifier: ^4.16.3 version: link:../../packages/astro react: specifier: ^18.3.1 @@ -279,7 +279,7 @@ importers: specifier: ^4.4.2 version: link:../../packages/integrations/solid astro: - specifier: ^4.16.2 + specifier: ^4.16.3 version: link:../../packages/astro solid-js: specifier: ^1.9.1 @@ -291,7 +291,7 @@ importers: specifier: ^5.7.2 version: link:../../packages/integrations/svelte astro: - specifier: ^4.16.2 + specifier: ^4.16.3 version: link:../../packages/astro svelte: specifier: ^4.2.19 @@ -303,7 +303,7 @@ importers: specifier: ^4.5.2 version: link:../../packages/integrations/vue astro: - specifier: ^4.16.2 + specifier: ^4.16.3 version: link:../../packages/astro vue: specifier: ^3.5.11 @@ -315,25 +315,25 @@ importers: specifier: ^8.3.4 version: 8.3.4(astro@packages+astro) astro: - specifier: ^4.16.2 + specifier: ^4.16.3 version: link:../../packages/astro examples/integration: devDependencies: astro: - specifier: ^4.16.2 + specifier: ^4.16.3 version: link:../../packages/astro examples/minimal: dependencies: astro: - specifier: ^4.16.2 + specifier: ^4.16.3 version: link:../../packages/astro examples/portfolio: dependencies: astro: - specifier: ^4.16.2 + specifier: ^4.16.3 version: link:../../packages/astro examples/ssr: @@ -345,7 +345,7 @@ importers: specifier: ^5.7.2 version: link:../../packages/integrations/svelte astro: - specifier: ^4.16.2 + specifier: ^4.16.3 version: link:../../packages/astro svelte: specifier: ^4.2.19 @@ -354,7 +354,7 @@ importers: examples/starlog: dependencies: astro: - specifier: ^4.16.2 + specifier: ^4.16.3 version: link:../../packages/astro sass: specifier: ^1.79.4 @@ -366,7 +366,7 @@ importers: examples/toolbar-app: devDependencies: astro: - specifier: ^4.16.2 + specifier: ^4.16.3 version: link:../../packages/astro examples/with-markdoc: @@ -375,7 +375,7 @@ importers: specifier: ^0.11.5 version: link:../../packages/integrations/markdoc astro: - specifier: ^4.16.2 + specifier: ^4.16.3 version: link:../../packages/astro examples/with-mdx: @@ -387,7 +387,7 @@ importers: specifier: ^3.5.3 version: link:../../packages/integrations/preact astro: - specifier: ^4.16.2 + specifier: ^4.16.3 version: link:../../packages/astro preact: specifier: ^10.24.2 @@ -402,7 +402,7 @@ importers: specifier: ^0.5.2 version: 0.5.2(nanostores@0.11.3)(preact@10.24.2) astro: - specifier: ^4.16.2 + specifier: ^4.16.3 version: link:../../packages/astro nanostores: specifier: ^0.11.3 @@ -423,7 +423,7 @@ importers: specifier: ^1.6.4 version: 1.6.4 astro: - specifier: ^4.16.2 + specifier: ^4.16.3 version: link:../../packages/astro autoprefixer: specifier: ^10.4.20 @@ -441,7 +441,7 @@ importers: examples/with-vitest: dependencies: astro: - specifier: ^4.16.2 + specifier: ^4.16.3 version: link:../../packages/astro vitest: specifier: ^2.1.2 From 07754f5873b05ab4dae31ded7264fe4056c2dfc8 Mon Sep 17 00:00:00 2001 From: Ming-jun Lu <40516784+mingjunlu@users.noreply.github.com> Date: Mon, 14 Oct 2024 20:45:24 +0800 Subject: [PATCH 5/9] fix(sitemap): add missing `xslURL` property to `SitemapOptions` type (#12156) --- .changeset/funny-onions-grin.md | 5 +++++ packages/integrations/sitemap/src/index.ts | 2 ++ 2 files changed, 7 insertions(+) create mode 100644 .changeset/funny-onions-grin.md diff --git a/.changeset/funny-onions-grin.md b/.changeset/funny-onions-grin.md new file mode 100644 index 0000000000..902bcb1aee --- /dev/null +++ b/.changeset/funny-onions-grin.md @@ -0,0 +1,5 @@ +--- +'@astrojs/sitemap': patch +--- + +Adds missing `xslURL` property to `SitemapOptions` type. diff --git a/packages/integrations/sitemap/src/index.ts b/packages/integrations/sitemap/src/index.ts index 4342ed5dba..9bbd39e4a7 100644 --- a/packages/integrations/sitemap/src/index.ts +++ b/packages/integrations/sitemap/src/index.ts @@ -35,6 +35,8 @@ export type SitemapOptions = // called for each sitemap item just before to save them on disk, sync or async serialize?(item: SitemapItem): SitemapItem | Promise | undefined; + + xslURL?: string; } | undefined; From c3513523608f319b43c050e391be08e68b801329 Mon Sep 17 00:00:00 2001 From: Emanuele Stoppa Date: Mon, 14 Oct 2024 14:58:33 +0100 Subject: [PATCH 6/9] fix(i18n): correctly compute the current locale (#12199) * fix(i18n): correctly compute the current locale * Update packages/astro/test/fixtures/i18n-routing-dynamic/src/pages/[language].astro Co-authored-by: Bjorn Lu * make code more readable * rebase --------- Co-authored-by: Bjorn Lu --- .changeset/sharp-garlics-float.md | 5 ++++ packages/astro/src/core/render-context.ts | 20 ++++++++----- packages/astro/src/i18n/utils.ts | 1 - .../i18n-routing-dynamic/astro.config.mjs | 13 +++++++++ .../i18n-routing-dynamic/package.json | 8 ++++++ .../src/pages/[language].astro | 11 ++++++++ .../src/pages/index.astro | 0 packages/astro/test/i18n-routing.test.js | 28 +++++++++++++++++-- pnpm-lock.yaml | 6 ++++ 9 files changed, 82 insertions(+), 10 deletions(-) create mode 100644 .changeset/sharp-garlics-float.md create mode 100644 packages/astro/test/fixtures/i18n-routing-dynamic/astro.config.mjs create mode 100644 packages/astro/test/fixtures/i18n-routing-dynamic/package.json create mode 100644 packages/astro/test/fixtures/i18n-routing-dynamic/src/pages/[language].astro create mode 100644 packages/astro/test/fixtures/i18n-routing-dynamic/src/pages/index.astro diff --git a/.changeset/sharp-garlics-float.md b/.changeset/sharp-garlics-float.md new file mode 100644 index 0000000000..c619d91c86 --- /dev/null +++ b/.changeset/sharp-garlics-float.md @@ -0,0 +1,5 @@ +--- +'astro': patch +--- + +Fixes a regression in the computation of `Astro.currentLocale` diff --git a/packages/astro/src/core/render-context.ts b/packages/astro/src/core/render-context.ts index 8850da132e..dcce29f07c 100644 --- a/packages/astro/src/core/render-context.ts +++ b/packages/astro/src/core/render-context.ts @@ -531,13 +531,19 @@ export class RenderContext { ? defaultLocale : undefined; - // TODO: look into why computeCurrentLocale() needs routeData.route to pass ctx.currentLocale tests, - // and url.pathname to pass Astro.currentLocale tests. - // A single call with `routeData.pathname ?? routeData.route` as the pathname still fails. - return (this.#currentLocale ??= - computeCurrentLocale(routeData.route, locales, defaultLocale) ?? - computeCurrentLocale(url.pathname, locales, defaultLocale) ?? - fallbackTo); + if (this.#currentLocale) { + return this.#currentLocale + } + + let computedLocale; + if (routeData.pathname) { + computedLocale = computeCurrentLocale(routeData.pathname, locales, defaultLocale) + } else { + computedLocale = computeCurrentLocale(url.pathname, locales, defaultLocale) + } + this.#currentLocale = computedLocale ?? fallbackTo; + + return this.#currentLocale } #preferredLocale: APIContext['preferredLocale']; diff --git a/packages/astro/src/i18n/utils.ts b/packages/astro/src/i18n/utils.ts index c79c66612d..ab0679c38a 100644 --- a/packages/astro/src/i18n/utils.ts +++ b/packages/astro/src/i18n/utils.ts @@ -157,7 +157,6 @@ export function computeCurrentLocale( for (const locale of locales) { if (typeof locale === 'string') { // we skip ta locale that isn't present in the current segment - if (!segment.includes(locale)) continue; if (normalizeTheLocale(locale) === normalizeTheLocale(segment)) { return locale; diff --git a/packages/astro/test/fixtures/i18n-routing-dynamic/astro.config.mjs b/packages/astro/test/fixtures/i18n-routing-dynamic/astro.config.mjs new file mode 100644 index 0000000000..d283edf6fb --- /dev/null +++ b/packages/astro/test/fixtures/i18n-routing-dynamic/astro.config.mjs @@ -0,0 +1,13 @@ +import { defineConfig } from "astro/config"; + +// https://astro.build/config +export default defineConfig({ + i18n: { + defaultLocale: "ru", + locales: ["ru", "en"], + routing: { + prefixDefaultLocale: true, + }, + }, +}); + diff --git a/packages/astro/test/fixtures/i18n-routing-dynamic/package.json b/packages/astro/test/fixtures/i18n-routing-dynamic/package.json new file mode 100644 index 0000000000..074b37b7dc --- /dev/null +++ b/packages/astro/test/fixtures/i18n-routing-dynamic/package.json @@ -0,0 +1,8 @@ +{ + "name": "@test/i18n-routing-dynamic", + "version": "0.0.0", + "private": true, + "dependencies": { + "astro": "workspace:*" + } +} diff --git a/packages/astro/test/fixtures/i18n-routing-dynamic/src/pages/[language].astro b/packages/astro/test/fixtures/i18n-routing-dynamic/src/pages/[language].astro new file mode 100644 index 0000000000..0721acd19d --- /dev/null +++ b/packages/astro/test/fixtures/i18n-routing-dynamic/src/pages/[language].astro @@ -0,0 +1,11 @@ +--- +export async function getStaticPaths() { + return [{ params: { language: "ru" } }, { params: { language: "en" } }]; +} + +const { currentLocale } = Astro; +--- + +
+ {currentLocale} +
diff --git a/packages/astro/test/fixtures/i18n-routing-dynamic/src/pages/index.astro b/packages/astro/test/fixtures/i18n-routing-dynamic/src/pages/index.astro new file mode 100644 index 0000000000..e69de29bb2 diff --git a/packages/astro/test/i18n-routing.test.js b/packages/astro/test/i18n-routing.test.js index 18b8fe6705..10c35bacd9 100644 --- a/packages/astro/test/i18n-routing.test.js +++ b/packages/astro/test/i18n-routing.test.js @@ -1,5 +1,5 @@ import * as assert from 'node:assert/strict'; -import { after, before, describe, it } from 'node:test'; +import { after, afterEach, before, describe, it } from 'node:test'; import * as cheerio from 'cheerio'; import testAdapter from './test-adapter.js'; import { loadFixture } from './test-utils.js'; @@ -1105,7 +1105,7 @@ describe('[SSG] i18n routing', () => { }); it('should return the default locale', async () => { - const html = await fixture.readFile('/current-locale/index.html'); + let html = await fixture.readFile('/current-locale/index.html'); assert.equal(html.includes('Current Locale: es'), true); }); @@ -1151,6 +1151,30 @@ describe('[SSG] i18n routing', () => { assert.equal(html.includes('Current Locale: pt'), true); }); }); + + describe('with dynamic paths', async () => { + /** @type {import('./test-utils').Fixture} */ + let fixture; + let devServer; + + before(async () => { + fixture = await loadFixture({ + root: './fixtures/i18n-routing/', + }); + devServer = await fixture.startDevServer(); + }); + + afterEach(async () => { + devServer.stop(); + }); + + it('should return the correct current locale', async () => { + let html = await fixture.fetch('/en').then((r) => r.text()); + assert.match(html, /en/); + html = await fixture.fetch('/ru').then((r) => r.text()); + assert.match(html, /ru/); + }); + }); }); }); describe('[SSR] i18n routing', () => { diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 9ee4fe3123..3a2831e26e 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -3135,6 +3135,12 @@ importers: specifier: workspace:* version: link:../../.. + packages/astro/test/fixtures/i18n-routing-dynamic: + dependencies: + astro: + specifier: workspace:* + version: link:../../.. + packages/astro/test/fixtures/i18n-routing-fallback: dependencies: astro: From d6f03e405d142363083db5f42b836aacdad561b4 Mon Sep 17 00:00:00 2001 From: Emanuele Stoppa Date: Mon, 14 Oct 2024 13:59:30 +0000 Subject: [PATCH 7/9] [ci] format --- packages/astro/src/core/render-context.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/astro/src/core/render-context.ts b/packages/astro/src/core/render-context.ts index dcce29f07c..952c9c03b2 100644 --- a/packages/astro/src/core/render-context.ts +++ b/packages/astro/src/core/render-context.ts @@ -532,18 +532,18 @@ export class RenderContext { : undefined; if (this.#currentLocale) { - return this.#currentLocale + return this.#currentLocale; } - + let computedLocale; if (routeData.pathname) { - computedLocale = computeCurrentLocale(routeData.pathname, locales, defaultLocale) + computedLocale = computeCurrentLocale(routeData.pathname, locales, defaultLocale); } else { - computedLocale = computeCurrentLocale(url.pathname, locales, defaultLocale) + computedLocale = computeCurrentLocale(url.pathname, locales, defaultLocale); } this.#currentLocale = computedLocale ?? fallbackTo; - - return this.#currentLocale + + return this.#currentLocale; } #preferredLocale: APIContext['preferredLocale']; From fb5569583b11ef585cd0a79e97e7e9dc653f6afa Mon Sep 17 00:00:00 2001 From: Emanuele Stoppa Date: Mon, 14 Oct 2024 15:35:24 +0100 Subject: [PATCH 8/9] fix(middleware): compute client address (#12222) * fix(middleware): compute client address * add unit test --- .changeset/slimy-kids-peel.md | 5 +++++ packages/astro/src/core/middleware/index.ts | 12 ++++++++--- packages/astro/src/core/routing/request.ts | 20 +++++++++++++++++++ .../test/units/routing/api-context.test.js | 19 ++++++++++++++++++ 4 files changed, 53 insertions(+), 3 deletions(-) create mode 100644 .changeset/slimy-kids-peel.md create mode 100644 packages/astro/src/core/routing/request.ts create mode 100644 packages/astro/test/units/routing/api-context.test.js diff --git a/.changeset/slimy-kids-peel.md b/.changeset/slimy-kids-peel.md new file mode 100644 index 0000000000..706d01d47c --- /dev/null +++ b/.changeset/slimy-kids-peel.md @@ -0,0 +1,5 @@ +--- +'astro': patch +--- + +Fixes an issue where the edge middleware couldn't correctly compute the client IP address when calling `ctx.clientAddress()` diff --git a/packages/astro/src/core/middleware/index.ts b/packages/astro/src/core/middleware/index.ts index 2ca8021266..a684d23c01 100644 --- a/packages/astro/src/core/middleware/index.ts +++ b/packages/astro/src/core/middleware/index.ts @@ -8,6 +8,7 @@ import { import { ASTRO_VERSION, clientAddressSymbol, clientLocalsSymbol } from '../constants.js'; import { AstroCookies } from '../cookies/index.js'; import { AstroError, AstroErrorData } from '../errors/index.js'; +import { getClientIpAddress } from '../routing/request.js'; import { sequence } from './sequence.js'; function defineMiddleware(fn: MiddlewareHandler) { @@ -50,6 +51,7 @@ function createContext({ let preferredLocale: string | undefined = undefined; let preferredLocaleList: string[] | undefined = undefined; let currentLocale: string | undefined = undefined; + let clientIpAddress: string | undefined; const url = new URL(request.url); const route = url.pathname; @@ -85,10 +87,14 @@ function createContext({ }, url, get clientAddress() { - if (clientAddressSymbol in request) { - return Reflect.get(request, clientAddressSymbol) as string; + if (clientIpAddress) { + return clientIpAddress; } - throw new AstroError(AstroErrorData.StaticClientAddressNotAvailable); + clientIpAddress = getClientIpAddress(request); + if (!clientIpAddress) { + throw new AstroError(AstroErrorData.StaticClientAddressNotAvailable); + } + return clientIpAddress; }, get locals() { let locals = Reflect.get(request, clientLocalsSymbol); diff --git a/packages/astro/src/core/routing/request.ts b/packages/astro/src/core/routing/request.ts new file mode 100644 index 0000000000..f7e917a53c --- /dev/null +++ b/packages/astro/src/core/routing/request.ts @@ -0,0 +1,20 @@ +/** + * Utilities for extracting information from `Request` + */ + +// Parses multiple header and returns first value if available. +export function getFirstForwardedValue(multiValueHeader?: string | string[] | null) { + return multiValueHeader + ?.toString() + ?.split(',') + .map((e) => e.trim())?.[0]; +} + +/** + * Returns the first value associated to the `x-forwarded-for` header. + * + * @param {Request} request + */ +export function getClientIpAddress(request: Request): string | undefined { + return getFirstForwardedValue(request.headers.get('x-forwarded-for')); +} diff --git a/packages/astro/test/units/routing/api-context.test.js b/packages/astro/test/units/routing/api-context.test.js new file mode 100644 index 0000000000..1e955e50cc --- /dev/null +++ b/packages/astro/test/units/routing/api-context.test.js @@ -0,0 +1,19 @@ +import assert from 'node:assert/strict'; +import { describe, it } from 'node:test'; +import { createContext } from '../../../dist/core/middleware/index.js'; + +describe('createAPIContext', () => { + it('should return the clientAddress', () => { + const request = new Request('http://example.com', { + headers: { + 'x-forwarded-for': '192.0.2.43, 172.16.58.3', + }, + }); + + const context = createContext({ + request, + }); + + assert.equal(context.clientAddress, '192.0.2.43'); + }); +}); From 79ffa5d9f75c16465134aa4ed4a3d1d59908ba8b Mon Sep 17 00:00:00 2001 From: Armand Philippot Date: Mon, 14 Oct 2024 18:14:23 +0200 Subject: [PATCH 9/9] fix(dev-toolbar): false positive in Audit with a11y check on labels (#12223) * fix(dev-toolbar): false positive in Audit with a11y check on labels * test: add e2e test for a11y audit on labelable elements * docs: complete changeset to explain why this is a problem --- .changeset/selfish-toes-carry.md | 7 +++ packages/astro/e2e/dev-toolbar-audits.test.js | 14 +++++ .../src/pages/a11y-labelable.astro | 54 +++++++++++++++++++ .../dev-toolbar/apps/audit/rules/a11y.ts | 2 +- 4 files changed, 76 insertions(+), 1 deletion(-) create mode 100644 .changeset/selfish-toes-carry.md create mode 100644 packages/astro/e2e/fixtures/dev-toolbar/src/pages/a11y-labelable.astro diff --git a/.changeset/selfish-toes-carry.md b/.changeset/selfish-toes-carry.md new file mode 100644 index 0000000000..2933b214bb --- /dev/null +++ b/.changeset/selfish-toes-carry.md @@ -0,0 +1,7 @@ +--- +'astro': patch +--- + +Fixes a false positive reported by the dev toolbar Audit app where a label was considered missing when associated with a button + +The `button` element can be [used with a label](https://www.w3.org/TR/2011/WD-html5-author-20110809/forms.html#category-label) (e.g. to create a switch) and should not be reported as an accessibility issue when used as a child of a `label`. diff --git a/packages/astro/e2e/dev-toolbar-audits.test.js b/packages/astro/e2e/dev-toolbar-audits.test.js index d0c5da847f..ca74763142 100644 --- a/packages/astro/e2e/dev-toolbar-audits.test.js +++ b/packages/astro/e2e/dev-toolbar-audits.test.js @@ -170,4 +170,18 @@ test.describe('Dev Toolbar - Audits', () => { const count = await auditHighlights.count(); expect(count).toEqual(0); }); + + test('does not warn about label with valid labelable elements', async ({ page, astro }) => { + await page.goto(astro.resolveUrl('/a11y-labelable')); + + const toolbar = page.locator('astro-dev-toolbar'); + const appButton = toolbar.locator('button[data-app-id="astro:audit"]'); + await appButton.click(); + + const auditCanvas = toolbar.locator('astro-dev-toolbar-app-canvas[data-app-id="astro:audit"]'); + const auditHighlights = auditCanvas.locator('astro-dev-toolbar-highlight'); + + const count = await auditHighlights.count(); + expect(count).toEqual(0); + }); }); diff --git a/packages/astro/e2e/fixtures/dev-toolbar/src/pages/a11y-labelable.astro b/packages/astro/e2e/fixtures/dev-toolbar/src/pages/a11y-labelable.astro new file mode 100644 index 0000000000..ecdeeb683e --- /dev/null +++ b/packages/astro/e2e/fixtures/dev-toolbar/src/pages/a11y-labelable.astro @@ -0,0 +1,54 @@ +--- + +--- + + + + + + + + +75% + + +"Hello, world!" + + +70% + + + + + +