Skip to content

Commit

Permalink
Merge branch 'main' into arpan-withastro#12506-ref
Browse files Browse the repository at this point in the history
  • Loading branch information
apatel369 authored Nov 26, 2024
2 parents 7990ec9 + cf0d8b0 commit 89d71e0
Show file tree
Hide file tree
Showing 37 changed files with 92 additions and 88 deletions.
5 changes: 5 additions & 0 deletions .changeset/hot-dingos-dress.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'astro': patch
---

Fixes an issue where with `i18n` enabled, Astro couldn't render the `404.astro` component for non-existent routes.
5 changes: 0 additions & 5 deletions .changeset/unlucky-kids-compete.md

This file was deleted.

6 changes: 3 additions & 3 deletions .github/scripts/announce.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { setOutput } from './utils.mjs';
const { GITHUB_REF = 'main' } = process.env;
const baseUrl = new URL(`https://github.com/withastro/astro/blob/${GITHUB_REF}/`);

const emojis = ['🎉', '🥳', '🚀', '🧑‍🚀', '🎊', '🏆', '✅', '🤩', '🤖', '🙌'];
const emojis = ['🎉', '🥳', '🚀', '🧑', '🎊', '🏆', '✅', '🤩', '🤖', '🙌'];
const descriptors = [
'new releases',
'hot and fresh updates',
Expand Down Expand Up @@ -141,7 +141,7 @@ async function generateMessage() {
message += `\nAlso ${item(extraVerbs)}:`;

const remainingPackages = packages.filter((p) => p.name !== name);
for (const { name, version, url } of remainingPackages) {
for (const { name, version, _url } of remainingPackages) {
message += `\n• \`${name}@${version}\``;
}

Expand All @@ -159,7 +159,7 @@ async function generateMessage() {

async function run() {
const content = await generateMessage();
console.log(content);
console.info(content);
setOutput('DISCORD_MESSAGE', content);
}

Expand Down
6 changes: 3 additions & 3 deletions benchmark/bench/_template.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export const defaultProject = 'project-name';
* Use `console.log` to report the results too. Logs that start with 10 `=`
* and end with 10 `=` will be extracted by CI to display in the PR comment.
* Usually after the first 10 `=` you'll want to add a title like `#### Test`.
* @param {URL} projectDir
* @param {URL} outputFile
* @param {URL} _projectDir
* @param {URL} _outputFile
*/
export async function run(projectDir, outputFile) {}
export async function run(_projectDir, _outputFile) {}
2 changes: 1 addition & 1 deletion examples/basics/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@
"astro": "astro"
},
"dependencies": {
"astro": "^4.16.14"
"astro": "^4.16.15"
}
}
2 changes: 1 addition & 1 deletion examples/blog/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@
"@astrojs/mdx": "^3.1.9",
"@astrojs/rss": "^4.0.9",
"@astrojs/sitemap": "^3.2.1",
"astro": "^4.16.14"
"astro": "^4.16.15"
}
}
2 changes: 1 addition & 1 deletion examples/component/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
],
"scripts": {},
"devDependencies": {
"astro": "^4.16.14"
"astro": "^4.16.15"
},
"peerDependencies": {
"astro": "^4.0.0"
Expand Down
2 changes: 1 addition & 1 deletion examples/container-with-vitest/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"test": "vitest run"
},
"dependencies": {
"astro": "^4.16.14",
"astro": "^4.16.15",
"@astrojs/react": "^3.6.3",
"react": "^18.3.1",
"react-dom": "^18.3.1",
Expand Down
2 changes: 1 addition & 1 deletion examples/framework-alpine/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@
"@astrojs/alpinejs": "^0.4.0",
"@types/alpinejs": "^3.13.10",
"alpinejs": "^3.14.3",
"astro": "^4.16.14"
"astro": "^4.16.15"
}
}
2 changes: 1 addition & 1 deletion examples/framework-lit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"dependencies": {
"@astrojs/lit": "^4.3.0",
"@webcomponents/template-shadowroot": "^0.2.1",
"astro": "^4.16.14",
"astro": "^4.16.15",
"lit": "^3.2.1"
}
}
2 changes: 1 addition & 1 deletion examples/framework-multiple/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"@astrojs/vue": "^4.5.3",
"@types/react": "^18.3.12",
"@types/react-dom": "^18.3.1",
"astro": "^4.16.14",
"astro": "^4.16.15",
"preact": "^10.24.3",
"react": "^18.3.1",
"react-dom": "^18.3.1",
Expand Down
2 changes: 1 addition & 1 deletion examples/framework-preact/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"dependencies": {
"@astrojs/preact": "^3.5.4",
"@preact/signals": "^1.3.0",
"astro": "^4.16.14",
"astro": "^4.16.15",
"preact": "^10.24.3"
}
}
2 changes: 1 addition & 1 deletion examples/framework-react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"@astrojs/react": "^3.6.3",
"@types/react": "^18.3.12",
"@types/react-dom": "^18.3.1",
"astro": "^4.16.14",
"astro": "^4.16.15",
"react": "^18.3.1",
"react-dom": "^18.3.1"
}
Expand Down
2 changes: 1 addition & 1 deletion examples/framework-solid/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
},
"dependencies": {
"@astrojs/solid-js": "^4.4.4",
"astro": "^4.16.14",
"astro": "^4.16.15",
"solid-js": "^1.9.3"
}
}
2 changes: 1 addition & 1 deletion examples/framework-svelte/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
},
"dependencies": {
"@astrojs/svelte": "^6.0.2",
"astro": "^4.16.14",
"astro": "^4.16.15",
"svelte": "^5.1.16"
}
}
2 changes: 1 addition & 1 deletion examples/framework-vue/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
},
"dependencies": {
"@astrojs/vue": "^4.5.3",
"astro": "^4.16.14",
"astro": "^4.16.15",
"vue": "^3.5.12"
}
}
2 changes: 1 addition & 1 deletion examples/hackernews/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@
},
"dependencies": {
"@astrojs/node": "^8.3.4",
"astro": "^4.16.14"
"astro": "^4.16.15"
}
}
2 changes: 1 addition & 1 deletion examples/integration/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
],
"scripts": {},
"devDependencies": {
"astro": "^4.16.14"
"astro": "^4.16.15"
},
"peerDependencies": {
"astro": "^4.0.0"
Expand Down
2 changes: 1 addition & 1 deletion examples/minimal/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@
"astro": "astro"
},
"dependencies": {
"astro": "^4.16.14"
"astro": "^4.16.15"
}
}
2 changes: 1 addition & 1 deletion examples/portfolio/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@
"astro": "astro"
},
"dependencies": {
"astro": "^4.16.14"
"astro": "^4.16.15"
}
}
2 changes: 1 addition & 1 deletion examples/ssr/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"dependencies": {
"@astrojs/node": "^8.3.4",
"@astrojs/svelte": "^6.0.2",
"astro": "^4.16.14",
"astro": "^4.16.15",
"svelte": "^5.1.16"
}
}
2 changes: 1 addition & 1 deletion examples/starlog/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"astro": "astro"
},
"dependencies": {
"astro": "^4.16.14",
"astro": "^4.16.15",
"sass": "^1.80.6",
"sharp": "^0.33.3"
}
Expand Down
2 changes: 1 addition & 1 deletion examples/toolbar-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"./app": "./dist/app.js"
},
"devDependencies": {
"astro": "^4.16.14",
"astro": "^4.16.15",
"@types/node": "^18.17.8"
}
}
2 changes: 1 addition & 1 deletion examples/with-markdoc/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@
},
"dependencies": {
"@astrojs/markdoc": "^0.11.5",
"astro": "^4.16.14"
"astro": "^4.16.15"
}
}
2 changes: 1 addition & 1 deletion examples/with-mdx/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"dependencies": {
"@astrojs/mdx": "^3.1.9",
"@astrojs/preact": "^3.5.4",
"astro": "^4.16.14",
"astro": "^4.16.15",
"preact": "^10.24.3"
}
}
2 changes: 1 addition & 1 deletion examples/with-nanostores/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"dependencies": {
"@astrojs/preact": "^3.5.4",
"@nanostores/preact": "^0.5.2",
"astro": "^4.16.14",
"astro": "^4.16.15",
"nanostores": "^0.11.3",
"preact": "^10.24.3"
}
Expand Down
2 changes: 1 addition & 1 deletion examples/with-tailwindcss/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"@astrojs/mdx": "^3.1.9",
"@astrojs/tailwind": "^5.1.2",
"@types/canvas-confetti": "^1.6.4",
"astro": "^4.16.14",
"astro": "^4.16.15",
"autoprefixer": "^10.4.20",
"canvas-confetti": "^1.9.3",
"postcss": "^8.4.47",
Expand Down
2 changes: 1 addition & 1 deletion examples/with-vitest/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"test": "vitest"
},
"dependencies": {
"astro": "^4.16.14",
"astro": "^4.16.15",
"vitest": "^2.1.4"
}
}
6 changes: 6 additions & 0 deletions packages/astro/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# astro

## 4.16.15

### Patch Changes

- [#12498](https://github.com/withastro/astro/pull/12498) [`b140a3f`](https://github.com/withastro/astro/commit/b140a3f6d821127f927b7cb938294549e41c5168) Thanks [@ematipico](https://github.com/ematipico)! - Fixes a regression where Astro was trying to access `Request.headers`

## 4.16.14

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "astro",
"version": "4.16.14",
"version": "4.16.15",
"description": "Astro is a modern site builder with web best practices, performance, and DX front-of-mind.",
"type": "module",
"author": "withastro",
Expand Down
8 changes: 7 additions & 1 deletion packages/astro/src/i18n/middleware.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { APIContext, MiddlewareHandler, SSRManifest } from '../@types/astro.js';
import type { SSRManifestI18n } from '../core/app/types.js';
import { ROUTE_TYPE_HEADER } from '../core/constants.js';
import { REROUTE_DIRECTIVE_HEADER, ROUTE_TYPE_HEADER } from '../core/constants.js';
import {
type MiddlewarePayload,
normalizeTheLocale,
Expand Down Expand Up @@ -65,6 +65,12 @@ export function createI18nMiddleware(
return async (context, next) => {
const response = await next();
const type = response.headers.get(ROUTE_TYPE_HEADER);

// This is case where we are internally rendering a 404/500, so we need to bypass checks that were done already
const isReroute = response.headers.get(REROUTE_DIRECTIVE_HEADER);
if (isReroute === 'no' && typeof i18n.fallback === 'undefined') {
return response;
}
// If the route we're processing is not a page, then we ignore it
if (type !== 'page' && type !== 'fallback') {
return response;
Expand Down
1 change: 0 additions & 1 deletion packages/astro/src/vite-plugin-astro-server/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ export async function handleRequest({
url,
pathname: resolvedPathname,
body,
origin,
pipeline,
manifestData,
incomingRequest: incomingRequest,
Expand Down
32 changes: 9 additions & 23 deletions packages/astro/src/vite-plugin-astro-server/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@ type HandleRoute = {
url: URL;
pathname: string;
body: ArrayBuffer | undefined;
origin: string;
manifestData: ManifestData;
incomingRequest: http.IncomingMessage;
incomingResponse: http.ServerResponse;
Expand All @@ -139,7 +138,6 @@ export async function handleRoute({
url,
pathname,
body,
origin,
pipeline,
manifestData,
incomingRequest,
Expand All @@ -156,12 +154,10 @@ export async function handleRoute({
let request: Request;
let renderContext: RenderContext;
let mod: ComponentInstance | undefined = undefined;
let options: SSROptions | undefined = undefined;
let route: RouteData;
const middleware = (await loadMiddleware(loader)).onRequest;
const locals = Reflect.get(incomingRequest, clientLocalsSymbol);

const filePath: URL | undefined = matchedRoute.filePath;
const { preloadedComponent } = matchedRoute;
route = matchedRoute.route;
// Allows adapters to pass in locals in dev mode.
Expand All @@ -181,15 +177,6 @@ export async function handleRoute({
if (value) incomingResponse.setHeader(name, value);
}

options = {
pipeline,
filePath,
preload: preloadedComponent,
pathname,
request,
route,
};

mod = preloadedComponent;

renderContext = await RenderContext.create({
Expand Down Expand Up @@ -248,18 +235,17 @@ export async function handleRoute({

if (statusCode === 404 && response.headers.get(REROUTE_DIRECTIVE_HEADER) !== 'no') {
const fourOhFourRoute = await matchRoute('/404', manifestData, pipeline);
if (options && options.route !== fourOhFourRoute?.route)
return handleRoute({
...options,
matchedRoute: fourOhFourRoute,
url: new URL(pathname, url),
body,
origin,
if (fourOhFourRoute) {
renderContext = await RenderContext.create({
locals,
pipeline,
manifestData,
incomingRequest,
incomingResponse,
pathname,
middleware: isDefaultPrerendered404(fourOhFourRoute.route) ? undefined : middleware,
request,
routeData: fourOhFourRoute.route,
});
response = await renderContext.render(fourOhFourRoute.preloadedComponent);
}
}

// We remove the internally-used header before we send the response to the user agent.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const currentLocale = Astro.currentLocale;
</head>
<body>
<h1>404 - Not Found</h1>
<h2>Custom 404</h2>
<p>Current Locale: {currentLocale ? currentLocale : "none"}</p>
</body>
</html>
Loading

0 comments on commit 89d71e0

Please sign in to comment.