0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2024-12-30 22:03:56 -05:00

Merge branch 'main' into main

This commit is contained in:
Jahir Vidrio 2024-10-14 10:16:28 -06:00 committed by GitHub
commit 1122fd2058
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
47 changed files with 280 additions and 69 deletions

View file

@ -0,0 +1,5 @@
---
'@astrojs/sitemap': patch
---
Adds missing `xslURL` property to `SitemapOptions` type.

View file

@ -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`.

View file

@ -0,0 +1,5 @@
---
'astro': patch
---
Fixes a regression in the computation of `Astro.currentLocale`

View file

@ -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()`

View file

@ -11,6 +11,6 @@
"astro": "astro"
},
"dependencies": {
"astro": "^4.16.2"
"astro": "^4.16.3"
}
}

View file

@ -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"
}
}

View file

@ -15,7 +15,7 @@
],
"scripts": {},
"devDependencies": {
"astro": "^4.16.2"
"astro": "^4.16.3"
},
"peerDependencies": {
"astro": "^4.0.0"

View file

@ -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",

View file

@ -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"
}
}

View file

@ -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"
}
}

View file

@ -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",

View file

@ -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"
}
}

View file

@ -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"
}

View file

@ -12,7 +12,7 @@
},
"dependencies": {
"@astrojs/solid-js": "^4.4.2",
"astro": "^4.16.2",
"astro": "^4.16.3",
"solid-js": "^1.9.1"
}
}

View file

@ -12,7 +12,7 @@
},
"dependencies": {
"@astrojs/svelte": "^5.7.2",
"astro": "^4.16.2",
"astro": "^4.16.3",
"svelte": "^4.2.19"
}
}

View file

@ -12,7 +12,7 @@
},
"dependencies": {
"@astrojs/vue": "^4.5.2",
"astro": "^4.16.2",
"astro": "^4.16.3",
"vue": "^3.5.11"
}
}

View file

@ -12,6 +12,6 @@
},
"dependencies": {
"@astrojs/node": "^8.3.4",
"astro": "^4.16.2"
"astro": "^4.16.3"
}
}

View file

@ -15,7 +15,7 @@
],
"scripts": {},
"devDependencies": {
"astro": "^4.16.2"
"astro": "^4.16.3"
},
"peerDependencies": {
"astro": "^4.0.0"

View file

@ -11,6 +11,6 @@
"astro": "astro"
},
"dependencies": {
"astro": "^4.16.2"
"astro": "^4.16.3"
}
}

View file

@ -11,6 +11,6 @@
"astro": "astro"
},
"dependencies": {
"astro": "^4.16.2"
"astro": "^4.16.3"
}
}

View file

@ -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"
}
}

View file

@ -10,7 +10,7 @@
"astro": "astro"
},
"dependencies": {
"astro": "^4.16.2",
"astro": "^4.16.3",
"sass": "^1.79.4",
"sharp": "^0.33.3"
}

View file

@ -15,6 +15,6 @@
"./app": "./dist/app.js"
},
"devDependencies": {
"astro": "^4.16.2"
"astro": "^4.16.3"
}
}

View file

@ -12,6 +12,6 @@
},
"dependencies": {
"@astrojs/markdoc": "^0.11.5",
"astro": "^4.16.2"
"astro": "^4.16.3"
}
}

View file

@ -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"
}
}

View file

@ -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"
}

View file

@ -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",

View file

@ -12,7 +12,7 @@
"test": "vitest"
},
"dependencies": {
"astro": "^4.16.2",
"astro": "^4.16.3",
"vitest": "^2.1.2"
}
}

View file

@ -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

View file

@ -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);
});
});

View file

@ -0,0 +1,54 @@
---
---
<label for="button1">Button label</label>
<button id="button1" />
<label>
Button label as child
<button>Activate?</button>
</label>
<label for="input1">Input label</label>
<input id="input1" />
<label>
Input label as child
<input type="text" />
</label>
<label for="meter1">Meter label</label>
<meter id="meter1" min="0" max="100" value="75">75%</meter>
<label>
Meter label as child
<meter min="0" max="100" value="75">75%</meter>
</label>
<label for="output1">Output label</label>
<output id="output1">"Hello, world!"</output>
<label>
Output label as child
<output>"Hello, world!"</output>
</label>
<label for="progress1">Progress label</label>
<progress id="progress1" max="100" value="70">70%</progress>
<label>
Progress label as child
<progress max="100" value="70">70%</progress>
</label>
<label for="select1">Select label</label>
<select id="select1">
<option>Option 1</option>
<option>Option 2</option>
<option>Option 3</option>
</select>
<label>
Select label as child
<select>
<option>Option 1</option>
<option>Option 2</option>
<option>Option 3</option>
</select>
</label>
<label for="textarea1">Textarea label</label>
<textarea cols="33" id="textarea1" rows="5" />
<label>
Textarea label as child
<textarea cols="33" rows="5" />
</label>

View file

@ -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",

View file

@ -90,13 +90,10 @@ export class NodeApp extends App {
: req.headers.host ?? req.headers[':authority'];
/** @example "443,8080,80" => "443" */
const forwardedPort = getFirstForwardedValue(req.headers['x-forwarded-port']);
const port = trustDownstreamProxy && forwardedPort
? 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 = {

View file

@ -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);

View file

@ -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'];

View file

@ -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'));
}

View file

@ -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;

View file

@ -62,7 +62,7 @@ const interactiveElements = [
...MAYBE_INTERACTIVE.keys(),
];
const labellableElements = ['input', 'meter', 'output', 'progress', 'select', 'textarea'];
const labellableElements = ['button', 'input', 'meter', 'output', 'progress', 'select', 'textarea'];
const aria_non_interactive_roles = [
'alert',

View file

@ -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@@
});

View file

@ -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,
},
},
});

View file

@ -0,0 +1,8 @@
{
"name": "@test/i18n-routing-dynamic",
"version": "0.0.0",
"private": true,
"dependencies": {
"astro": "workspace:*"
}
}

View file

@ -0,0 +1,11 @@
---
export async function getStaticPaths() {
return [{ params: { language: "ru" } }, { params: { language: "en" } }];
}
const { currentLocale } = Astro;
---
<div>
{currentLocale}
</div>

View file

@ -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', () => {

View file

@ -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');
});
});

View file

@ -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<SitemapItem | undefined> | undefined;
xslURL?: string;
}
| undefined;

View file

@ -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
@ -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: