diff --git a/.changeset/pre.json b/.changeset/pre.json index 7b422da6859c..a08df62b1c29 100644 --- a/.changeset/pre.json +++ b/.changeset/pre.json @@ -94,6 +94,7 @@ "poor-frogs-dream", "poor-seals-clap", "pretty-walls-camp", + "proud-games-repair", "quick-ads-exercise", "quick-onions-leave", "rotten-phones-scream", @@ -110,6 +111,7 @@ "strange-sheep-film", "strong-months-grab", "sweet-timers-smash", + "tall-waves-impress", "tame-pumpkins-swim", "tame-rats-cross", "ten-students-repair", diff --git a/examples/basics/package.json b/examples/basics/package.json index a36bc626e2ee..7073ff822afe 100644 --- a/examples/basics/package.json +++ b/examples/basics/package.json @@ -10,6 +10,6 @@ "astro": "astro" }, "dependencies": { - "astro": "^5.0.0-beta.7" + "astro": "^5.0.0-beta.8" } } diff --git a/examples/blog/package.json b/examples/blog/package.json index 83896b87ddda..0e13ddef6dcb 100644 --- a/examples/blog/package.json +++ b/examples/blog/package.json @@ -13,6 +13,6 @@ "@astrojs/mdx": "^4.0.0-beta.3", "@astrojs/rss": "^4.0.9", "@astrojs/sitemap": "^3.2.1", - "astro": "^5.0.0-beta.7" + "astro": "^5.0.0-beta.8" } } diff --git a/examples/component/package.json b/examples/component/package.json index ada92f61dc03..27c20d0592e8 100644 --- a/examples/component/package.json +++ b/examples/component/package.json @@ -15,7 +15,7 @@ ], "scripts": {}, "devDependencies": { - "astro": "^5.0.0-beta.7" + "astro": "^5.0.0-beta.8" }, "peerDependencies": { "astro": "^4.0.0 || ^5.0.0" diff --git a/examples/container-with-vitest/package.json b/examples/container-with-vitest/package.json index 17bbe0847818..5cb0084ac1c6 100644 --- a/examples/container-with-vitest/package.json +++ b/examples/container-with-vitest/package.json @@ -11,7 +11,7 @@ "test": "vitest run" }, "dependencies": { - "astro": "^5.0.0-beta.7", + "astro": "^5.0.0-beta.8", "@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 7cd3d314c1bf..698088fcfe5c 100644 --- a/examples/framework-alpine/package.json +++ b/examples/framework-alpine/package.json @@ -13,6 +13,6 @@ "@astrojs/alpinejs": "^0.4.0", "@types/alpinejs": "^3.13.10", "alpinejs": "^3.14.3", - "astro": "^5.0.0-beta.7" + "astro": "^5.0.0-beta.8" } } diff --git a/examples/framework-multiple/package.json b/examples/framework-multiple/package.json index f184bb9c5fb1..4bbb934655c4 100644 --- a/examples/framework-multiple/package.json +++ b/examples/framework-multiple/package.json @@ -17,7 +17,7 @@ "@astrojs/vue": "^5.0.0-beta.1", "@types/react": "^18.3.12", "@types/react-dom": "^18.3.1", - "astro": "^5.0.0-beta.7", + "astro": "^5.0.0-beta.8", "preact": "^10.24.3", "react": "^18.3.1", "react-dom": "^18.3.1", diff --git a/examples/framework-preact/package.json b/examples/framework-preact/package.json index 476d94318d53..445c836fcfff 100644 --- a/examples/framework-preact/package.json +++ b/examples/framework-preact/package.json @@ -12,7 +12,7 @@ "dependencies": { "@astrojs/preact": "^3.5.3", "@preact/signals": "^1.3.0", - "astro": "^5.0.0-beta.7", + "astro": "^5.0.0-beta.8", "preact": "^10.24.3" } } diff --git a/examples/framework-react/package.json b/examples/framework-react/package.json index 084ceb7e390a..b0541cba7cd4 100644 --- a/examples/framework-react/package.json +++ b/examples/framework-react/package.json @@ -13,7 +13,7 @@ "@astrojs/react": "^3.6.2", "@types/react": "^18.3.12", "@types/react-dom": "^18.3.1", - "astro": "^5.0.0-beta.7", + "astro": "^5.0.0-beta.8", "react": "^18.3.1", "react-dom": "^18.3.1" } diff --git a/examples/framework-solid/package.json b/examples/framework-solid/package.json index b38380ec7a71..31b0691ca386 100644 --- a/examples/framework-solid/package.json +++ b/examples/framework-solid/package.json @@ -11,7 +11,7 @@ }, "dependencies": { "@astrojs/solid-js": "^4.4.2", - "astro": "^5.0.0-beta.7", + "astro": "^5.0.0-beta.8", "solid-js": "^1.9.2" } } diff --git a/examples/framework-svelte/package.json b/examples/framework-svelte/package.json index f7ccc842d38b..c7308a1ab374 100644 --- a/examples/framework-svelte/package.json +++ b/examples/framework-svelte/package.json @@ -11,7 +11,7 @@ }, "dependencies": { "@astrojs/svelte": "^6.0.0-beta.2", - "astro": "^5.0.0-beta.7", + "astro": "^5.0.0-beta.8", "svelte": "^4.2.19" } } diff --git a/examples/framework-vue/package.json b/examples/framework-vue/package.json index 6ca9585e5a36..ae8a1403f34d 100644 --- a/examples/framework-vue/package.json +++ b/examples/framework-vue/package.json @@ -11,7 +11,7 @@ }, "dependencies": { "@astrojs/vue": "^5.0.0-beta.1", - "astro": "^5.0.0-beta.7", + "astro": "^5.0.0-beta.8", "vue": "^3.5.12" } } diff --git a/examples/hackernews/package.json b/examples/hackernews/package.json index b26d8ce2b465..71bdd46ea7ff 100644 --- a/examples/hackernews/package.json +++ b/examples/hackernews/package.json @@ -11,6 +11,6 @@ }, "dependencies": { "@astrojs/node": "^9.0.0-alpha.1", - "astro": "^5.0.0-beta.7" + "astro": "^5.0.0-beta.8" } } diff --git a/examples/integration/package.json b/examples/integration/package.json index 2e2e6d47698e..b591fedb5812 100644 --- a/examples/integration/package.json +++ b/examples/integration/package.json @@ -15,7 +15,7 @@ ], "scripts": {}, "devDependencies": { - "astro": "^5.0.0-beta.7" + "astro": "^5.0.0-beta.8" }, "peerDependencies": { "astro": "^4.0.0" diff --git a/examples/minimal/package.json b/examples/minimal/package.json index e671b25fb4b7..f792c9b96a9c 100644 --- a/examples/minimal/package.json +++ b/examples/minimal/package.json @@ -10,6 +10,6 @@ "astro": "astro" }, "dependencies": { - "astro": "^5.0.0-beta.7" + "astro": "^5.0.0-beta.8" } } diff --git a/examples/portfolio/package.json b/examples/portfolio/package.json index 8c2e2d0695fe..fe41095bdd51 100644 --- a/examples/portfolio/package.json +++ b/examples/portfolio/package.json @@ -10,6 +10,6 @@ "astro": "astro" }, "dependencies": { - "astro": "^5.0.0-beta.7" + "astro": "^5.0.0-beta.8" } } diff --git a/examples/ssr/package.json b/examples/ssr/package.json index e588e5575bc5..63d27d3b2250 100644 --- a/examples/ssr/package.json +++ b/examples/ssr/package.json @@ -13,7 +13,7 @@ "dependencies": { "@astrojs/node": "^9.0.0-alpha.1", "@astrojs/svelte": "^6.0.0-beta.2", - "astro": "^5.0.0-beta.7", + "astro": "^5.0.0-beta.8", "svelte": "^4.2.19" } } diff --git a/examples/starlog/package.json b/examples/starlog/package.json index a9c76c4b49e9..ffcae20cca4c 100644 --- a/examples/starlog/package.json +++ b/examples/starlog/package.json @@ -9,7 +9,7 @@ "astro": "astro" }, "dependencies": { - "astro": "^5.0.0-beta.7", + "astro": "^5.0.0-beta.8", "sass": "^1.80.6", "sharp": "^0.33.3" } diff --git a/examples/toolbar-app/package.json b/examples/toolbar-app/package.json index 340d4f576cc9..5b03d6f85e2e 100644 --- a/examples/toolbar-app/package.json +++ b/examples/toolbar-app/package.json @@ -15,6 +15,6 @@ "./app": "./dist/app.js" }, "devDependencies": { - "astro": "^5.0.0-beta.7" + "astro": "^5.0.0-beta.8" } } diff --git a/examples/with-markdoc/package.json b/examples/with-markdoc/package.json index aa7473c2310b..9916a485102d 100644 --- a/examples/with-markdoc/package.json +++ b/examples/with-markdoc/package.json @@ -11,6 +11,6 @@ }, "dependencies": { "@astrojs/markdoc": "^0.12.0-beta.0", - "astro": "^5.0.0-beta.7" + "astro": "^5.0.0-beta.8" } } diff --git a/examples/with-mdx/package.json b/examples/with-mdx/package.json index a1f517effe35..4642aa9ef490 100644 --- a/examples/with-mdx/package.json +++ b/examples/with-mdx/package.json @@ -12,7 +12,7 @@ "dependencies": { "@astrojs/mdx": "^4.0.0-beta.3", "@astrojs/preact": "^3.5.3", - "astro": "^5.0.0-beta.7", + "astro": "^5.0.0-beta.8", "preact": "^10.24.3" } } diff --git a/examples/with-nanostores/package.json b/examples/with-nanostores/package.json index 8ff59c197c9f..19cd884f955f 100644 --- a/examples/with-nanostores/package.json +++ b/examples/with-nanostores/package.json @@ -12,7 +12,7 @@ "dependencies": { "@astrojs/preact": "^3.5.3", "@nanostores/preact": "^0.5.2", - "astro": "^5.0.0-beta.7", + "astro": "^5.0.0-beta.8", "nanostores": "^0.11.3", "preact": "^10.24.3" } diff --git a/examples/with-tailwindcss/package.json b/examples/with-tailwindcss/package.json index 0a7be2f9aeb3..fcfe676f1784 100644 --- a/examples/with-tailwindcss/package.json +++ b/examples/with-tailwindcss/package.json @@ -13,7 +13,7 @@ "@astrojs/mdx": "^4.0.0-beta.3", "@astrojs/tailwind": "^5.1.2", "@types/canvas-confetti": "^1.6.4", - "astro": "^5.0.0-beta.7", + "astro": "^5.0.0-beta.8", "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 e907caae43f8..24c9cb1b02d3 100644 --- a/examples/with-vitest/package.json +++ b/examples/with-vitest/package.json @@ -11,7 +11,7 @@ "test": "vitest" }, "dependencies": { - "astro": "^5.0.0-beta.7", + "astro": "^5.0.0-beta.8", "vitest": "^2.1.4" } } diff --git a/packages/astro/CHANGELOG.md b/packages/astro/CHANGELOG.md index aa3d02e32fa5..2d5bd7070206 100644 --- a/packages/astro/CHANGELOG.md +++ b/packages/astro/CHANGELOG.md @@ -1,5 +1,74 @@ # astro +## 5.0.0-beta.8 + +### Minor Changes + +- [#12373](https://github.com/withastro/astro/pull/12373) [`d10f918`](https://github.com/withastro/astro/commit/d10f91815e63f169cff3d1daef5505aef077c76c) Thanks [@bholmesdev](https://github.com/bholmesdev)! - Changes the default behavior for Astro Action form requests to a standard POST submission. + + In Astro 4.x, actions called from an HTML form would trigger a redirect with the result forwarded using cookies. This caused issues for large form errors and return values that exceeded the 4 KB limit of cookie-based storage. + + Astro 5.0 now renders the result of an action as a POST result without any forwarding. This will introduce a "confirm form resubmission?" dialog when a user attempts to refresh the page, though it no longer imposes a 4 KB limit on action return value. + + ## Customize form submission behavior + + If you prefer to address the "confirm form resubmission?" dialog on refresh, or to preserve action results across sessions, you can now [customize action result handling from middleware](https://5-0-0-beta.docs.astro.build/en/guides/actions/#advanced-persist-action-results-with-a-session). + + We recommend using a session storage provider [as described in our Netlify Blob example](https://5-0-0-beta.docs.astro.build/en/guides/actions/#advanced-persist-action-results-with-a-session). However, if you prefer the cookie forwarding behavior from 4.X and accept the 4 KB size limit, you can implement the pattern as shown in this sample snippet: + + ```ts + // src/middleware.ts + import { defineMiddleware } from 'astro:middleware'; + import { getActionContext } from 'astro:actions'; + + export const onRequest = defineMiddleware(async (context, next) => { + // Skip requests for prerendered pages + if (context.isPrerendered) return next(); + + const { action, setActionResult, serializeActionResult } = getActionContext(context); + + // If an action result was forwarded as a cookie, set the result + // to be accessible from `Astro.getActionResult()` + const payload = context.cookies.get('ACTION_PAYLOAD'); + if (payload) { + const { actionName, actionResult } = payload.json(); + setActionResult(actionName, actionResult); + context.cookies.delete('ACTION_PAYLOAD'); + return next(); + } + + // If an action was called from an HTML form action, + // call the action handler and redirect with the result as a cookie. + if (action?.calledFrom === 'form') { + const actionResult = await action.handler(); + + context.cookies.set('ACTION_PAYLOAD', { + actionName: action.name, + actionResult: serializeActionResult(actionResult), + }); + + if (actionResult.error) { + // Redirect back to the previous page on error + const referer = context.request.headers.get('Referer'); + if (!referer) { + throw new Error('Internal: Referer unexpectedly missing from Action POST request.'); + } + return context.redirect(referer); + } + // Redirect to the destination page on success + return context.redirect(context.originPathname); + } + + return next(); + }); + ``` + +### Patch Changes + +- [#12339](https://github.com/withastro/astro/pull/12339) [`bdb75a8`](https://github.com/withastro/astro/commit/bdb75a87f24d7f032797483164fb2f82aa691fee) Thanks [@ematipico](https://github.com/ematipico)! - Adds an error when `Astro.rewrite()` is used to rewrite an on-demand route with a static route when using the `"server"` output. + + This is a forbidden rewrite because Astro can't retrieve the emitted static route at runtime. This route is served by the hosting platform, and not Astro itself. + ## 5.0.0-beta.7 ### Minor Changes diff --git a/packages/astro/package.json b/packages/astro/package.json index a678ba60b2ca..d29b01932b5c 100644 --- a/packages/astro/package.json +++ b/packages/astro/package.json @@ -1,6 +1,6 @@ { "name": "astro", - "version": "5.0.0-beta.7", + "version": "5.0.0-beta.8", "description": "Astro is a modern site builder with web best practices, performance, and DX front-of-mind.", "type": "module", "author": "withastro", diff --git a/packages/astro/src/actions/integration.ts b/packages/astro/src/actions/integration.ts index 23fbd904a52f..d7c99fc421e3 100644 --- a/packages/astro/src/actions/integration.ts +++ b/packages/astro/src/actions/integration.ts @@ -3,7 +3,7 @@ import { AstroError } from '../core/errors/errors.js'; import { viteID } from '../core/util.js'; import type { AstroSettings } from '../types/astro.js'; import type { AstroIntegration } from '../types/public/integrations.js'; -import { ACTIONS_TYPES_FILE, VIRTUAL_MODULE_ID, ACTION_RPC_ROUTE_PATTERN } from './consts.js'; +import { ACTIONS_TYPES_FILE, ACTION_RPC_ROUTE_PATTERN, VIRTUAL_MODULE_ID } from './consts.js'; /** * This integration is applied when the user is using Actions in their project. diff --git a/packages/astro/src/actions/runtime/virtual/server.ts b/packages/astro/src/actions/runtime/virtual/server.ts index f8fac557a09a..f28b3c2393b9 100644 --- a/packages/astro/src/actions/runtime/virtual/server.ts +++ b/packages/astro/src/actions/runtime/virtual/server.ts @@ -1,13 +1,17 @@ import { z } from 'zod'; import { ActionCalledFromServerError } from '../../../core/errors/errors-data.js'; import { AstroError } from '../../../core/errors/errors.js'; +import type { APIContext } from '../../../types/public/index.js'; +import { ACTION_RPC_ROUTE_PATTERN } from '../../consts.js'; import { - formContentTypes, - hasContentType, type ActionAPIContext, type ErrorInferenceObject, type MaybePromise, + formContentTypes, + hasContentType, } from '../utils.js'; +import type { Locals } from '../utils.js'; +import { getAction } from './get-action.js'; import { ACTION_QUERY_PARAMS, ActionError, @@ -18,10 +22,6 @@ import { deserializeActionResult, serializeActionResult, } from './shared.js'; -import type { Locals } from '../utils.js'; -import { getAction } from './get-action.js'; -import type { APIContext } from '../../../types/public/index.js'; -import { ACTION_RPC_ROUTE_PATTERN } from '../../consts.js'; export * from './shared.js'; diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 953ead5c23a7..b4099b989b74 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -143,7 +143,7 @@ importers: examples/basics: dependencies: astro: - specifier: ^5.0.0-beta.7 + specifier: ^5.0.0-beta.8 version: link:../../packages/astro examples/blog: @@ -158,13 +158,13 @@ importers: specifier: ^3.2.1 version: link:../../packages/integrations/sitemap astro: - specifier: ^5.0.0-beta.7 + specifier: ^5.0.0-beta.8 version: link:../../packages/astro examples/component: devDependencies: astro: - specifier: ^5.0.0-beta.7 + specifier: ^5.0.0-beta.8 version: link:../../packages/astro examples/container-with-vitest: @@ -173,7 +173,7 @@ importers: specifier: ^3.6.2 version: link:../../packages/integrations/react astro: - specifier: ^5.0.0-beta.7 + specifier: ^5.0.0-beta.8 version: link:../../packages/astro react: specifier: ^18.3.1 @@ -204,7 +204,7 @@ importers: specifier: ^3.14.3 version: 3.14.3 astro: - specifier: ^5.0.0-beta.7 + specifier: ^5.0.0-beta.8 version: link:../../packages/astro examples/framework-multiple: @@ -231,7 +231,7 @@ importers: specifier: ^18.3.1 version: 18.3.1 astro: - specifier: ^5.0.0-beta.7 + specifier: ^5.0.0-beta.8 version: link:../../packages/astro preact: specifier: ^10.24.3 @@ -261,7 +261,7 @@ importers: specifier: ^1.3.0 version: 1.3.0(preact@10.24.3) astro: - specifier: ^5.0.0-beta.7 + specifier: ^5.0.0-beta.8 version: link:../../packages/astro preact: specifier: ^10.24.3 @@ -279,7 +279,7 @@ importers: specifier: ^18.3.1 version: 18.3.1 astro: - specifier: ^5.0.0-beta.7 + specifier: ^5.0.0-beta.8 version: link:../../packages/astro react: specifier: ^18.3.1 @@ -294,7 +294,7 @@ importers: specifier: ^4.4.2 version: link:../../packages/integrations/solid astro: - specifier: ^5.0.0-beta.7 + specifier: ^5.0.0-beta.8 version: link:../../packages/astro solid-js: specifier: ^1.9.2 @@ -306,7 +306,7 @@ importers: specifier: ^6.0.0-beta.2 version: link:../../packages/integrations/svelte astro: - specifier: ^5.0.0-beta.7 + specifier: ^5.0.0-beta.8 version: link:../../packages/astro svelte: specifier: ^4.2.19 @@ -318,7 +318,7 @@ importers: specifier: ^5.0.0-beta.1 version: link:../../packages/integrations/vue astro: - specifier: ^5.0.0-beta.7 + specifier: ^5.0.0-beta.8 version: link:../../packages/astro vue: specifier: ^3.5.12 @@ -330,25 +330,25 @@ importers: specifier: ^9.0.0-alpha.1 version: 9.0.0-alpha.1(astro@packages+astro) astro: - specifier: ^5.0.0-beta.7 + specifier: ^5.0.0-beta.8 version: link:../../packages/astro examples/integration: devDependencies: astro: - specifier: ^5.0.0-beta.7 + specifier: ^5.0.0-beta.8 version: link:../../packages/astro examples/minimal: dependencies: astro: - specifier: ^5.0.0-beta.7 + specifier: ^5.0.0-beta.8 version: link:../../packages/astro examples/portfolio: dependencies: astro: - specifier: ^5.0.0-beta.7 + specifier: ^5.0.0-beta.8 version: link:../../packages/astro examples/ssr: @@ -360,7 +360,7 @@ importers: specifier: ^6.0.0-beta.2 version: link:../../packages/integrations/svelte astro: - specifier: ^5.0.0-beta.7 + specifier: ^5.0.0-beta.8 version: link:../../packages/astro svelte: specifier: ^4.2.19 @@ -369,7 +369,7 @@ importers: examples/starlog: dependencies: astro: - specifier: ^5.0.0-beta.7 + specifier: ^5.0.0-beta.8 version: link:../../packages/astro sass: specifier: ^1.80.6 @@ -381,7 +381,7 @@ importers: examples/toolbar-app: devDependencies: astro: - specifier: ^5.0.0-beta.7 + specifier: ^5.0.0-beta.8 version: link:../../packages/astro examples/with-markdoc: @@ -390,7 +390,7 @@ importers: specifier: ^0.12.0-beta.0 version: link:../../packages/integrations/markdoc astro: - specifier: ^5.0.0-beta.7 + specifier: ^5.0.0-beta.8 version: link:../../packages/astro examples/with-mdx: @@ -402,7 +402,7 @@ importers: specifier: ^3.5.3 version: link:../../packages/integrations/preact astro: - specifier: ^5.0.0-beta.7 + specifier: ^5.0.0-beta.8 version: link:../../packages/astro preact: specifier: ^10.24.3 @@ -417,7 +417,7 @@ importers: specifier: ^0.5.2 version: 0.5.2(nanostores@0.11.3)(preact@10.24.3) astro: - specifier: ^5.0.0-beta.7 + specifier: ^5.0.0-beta.8 version: link:../../packages/astro nanostores: specifier: ^0.11.3 @@ -438,7 +438,7 @@ importers: specifier: ^1.6.4 version: 1.6.4 astro: - specifier: ^5.0.0-beta.7 + specifier: ^5.0.0-beta.8 version: link:../../packages/astro autoprefixer: specifier: ^10.4.20 @@ -456,7 +456,7 @@ importers: examples/with-vitest: dependencies: astro: - specifier: ^5.0.0-beta.7 + specifier: ^5.0.0-beta.8 version: link:../../packages/astro vitest: specifier: ^2.1.4