Skip to content

Commit

Permalink
Merge branch 'next' into arpan-withastro#12252-mdx-islands
Browse files Browse the repository at this point in the history
  • Loading branch information
apatel369 authored Nov 15, 2024
2 parents 5c1def6 + af867f3 commit e63f5a2
Show file tree
Hide file tree
Showing 198 changed files with 3,282 additions and 1,216 deletions.
5 changes: 5 additions & 0 deletions .changeset/brown-bulldogs-share.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'astro': patch
---

Fixes an issue where an incorrect usage of Astro actions was lost when porting the fix from v4 to v5
5 changes: 5 additions & 0 deletions .changeset/clean-moles-rest.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'astro': patch
---

Fixes a bug where legacy content types were generated for content layer collections if they were in the content directory
2 changes: 2 additions & 0 deletions .changeset/pre.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down
7 changes: 7 additions & 0 deletions .changeset/proud-games-repair.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'astro': patch
---

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 changes: 5 additions & 0 deletions .changeset/proud-terms-swim.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'astro': patch
---

Adds experimental reponsive image support
62 changes: 62 additions & 0 deletions .changeset/tall-waves-impress.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
---
'astro': minor
---

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();
})
```
78 changes: 46 additions & 32 deletions benchmark/bench/codspeed.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,48 +2,62 @@ import path from 'node:path';
import { withCodSpeed } from '@codspeed/tinybench-plugin';
import { Bench } from 'tinybench';
import { exec } from 'tinyexec';
import { renderPages } from '../make-project/render-default.js';
import { astroBin } from './_util.js';

export async function run({ memory: _memory, render, stress: _stress }) {
const options = {
iterations: 10,
};
const bench = process.env.CODSPEED ? withCodSpeed(new Bench(options)) : new Bench(options);
let app;
bench.add(
'Rendering',
async () => {
await exec(astroBin, ['build'], {
nodeOptions: {
cwd: render.root,
stdio: 'inherit',
},
});

const entry = new URL('./dist/server/entry.mjs', `file://${render.root}`);
const { manifest, createApp } = await import(entry);
const streamingApp = createApp(manifest, true);
const nonStreamingApp = createApp(manifest, false);
bench
.add('Rendering: streaming [true], .astro file', async () => {
console.info('Start task.');
const result = {};
for (const fileName of renderPages) {
const pathname = '/' + fileName.slice(0, -path.extname(fileName).length);
const request = new Request(new URL(pathname, 'http://exmpale.com'));
const response = await app.render(request);
const html = await response.text();
if (!result[pathname]) result[pathname] = [];
result[pathname].push(html);
}
const request = new Request(new URL('http://exmpale.com/astro'));
await streamingApp.render(request);
console.info('Finish task.');
return result;
},
{
async beforeAll() {
// build for rendering
await exec(astroBin, ['build'], {
nodeOptions: {
cwd: render.root,
stdio: 'inherit',
},
});
})
.add('Rendering: streaming [true], .md file', async () => {
console.info('Start task.');
const request = new Request(new URL('http://exmpale.com/md'));
await streamingApp.render(request);
console.info('Finish task.');
})
.add('Rendering: streaming [true], .mdx file', async () => {
console.info('Start task.');
const request = new Request(new URL('http://exmpale.com/mdx'));
await streamingApp.render(request);
console.info('Finish task.');
})

const entry = new URL('./dist/server/entry.mjs', `file://${render.root}`);
const { manifest, createApp } = await import(entry);
app = createApp(manifest);
app.manifest = manifest;
},
},
);
.add('Rendering: streaming [false], .astro file', async () => {
console.info('Start task.');
const request = new Request(new URL('http://exmpale.com/astro'));
await nonStreamingApp.render(request);
console.info('Finish task.');
})
.add('Rendering: streaming [false], .md file', async () => {
console.info('Start task.');
const request = new Request(new URL('http://exmpale.com/md'));
await nonStreamingApp.render(request);
console.info('Finish task.');
})
.add('Rendering: streaming [false], .mdx file', async () => {
console.info('Start task.');
const request = new Request(new URL('http://exmpale.com/mdx'));
await nonStreamingApp.render(request);
console.info('Finish task.');
});

await bench.run();
console.table(bench.table());
Expand Down
2 changes: 0 additions & 2 deletions benchmark/packages/adapter/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,9 @@ applyPolyfills();

class MyApp extends App {
#manifest: SSRManifest | undefined;
#streaming: boolean;
constructor(manifest: SSRManifest, streaming = false) {
super(manifest, streaming);
this.#manifest = manifest;
this.#streaming = streaming;
}

async render(request: Request) {
Expand Down
2 changes: 1 addition & 1 deletion examples/basics/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@
"astro": "astro"
},
"dependencies": {
"astro": "^5.0.0-beta.7"
"astro": "^5.0.0-beta.8"
}
}
2 changes: 1 addition & 1 deletion examples/blog/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
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": "^5.0.0-beta.7"
"astro": "^5.0.0-beta.8"
},
"peerDependencies": {
"astro": "^4.0.0 || ^5.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 @@ -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",
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 @@ -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"
}
}
6 changes: 3 additions & 3 deletions examples/framework-multiple/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@
"dependencies": {
"@astrojs/preact": "^3.5.3",
"@astrojs/react": "^3.6.2",
"@astrojs/solid-js": "^4.4.2",
"@astrojs/solid-js": "^4.4.3",
"@astrojs/svelte": "^6.0.0-beta.2",
"@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",
"solid-js": "^1.9.3",
"svelte": "^4.2.19",
"svelte": "^5.1.16",
"vue": "^3.5.12"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,14 @@
A counter written with Svelte
-->
<script lang="ts">
let count = 0;
import type { Snippet } from 'svelte';
interface Props {
children?: Snippet
}
let { children }: Props = $props();
let count = $state(0);
function add() {
count += 1;
Expand All @@ -14,10 +21,10 @@ A counter written with Svelte
</script>

<div class="counter">
<button on:click={subtract}>-</button>
<button onclick={subtract}>-</button>
<pre>{count}</pre>
<button on:click={add}>+</button>
<button onclick={add}>+</button>
</div>
<div class="counter-message">
<slot />
{@render children?.()}
</div>
2 changes: 1 addition & 1 deletion examples/framework-preact/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
2 changes: 1 addition & 1 deletion examples/framework-react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Expand Down
4 changes: 2 additions & 2 deletions examples/framework-solid/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
"astro": "astro"
},
"dependencies": {
"@astrojs/solid-js": "^4.4.2",
"astro": "^5.0.0-beta.7",
"@astrojs/solid-js": "^4.4.3",
"astro": "^5.0.0-beta.8",
"solid-js": "^1.9.2"
}
}
6 changes: 3 additions & 3 deletions examples/framework-svelte/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
"astro": "astro"
},
"dependencies": {
"@astrojs/svelte": "^6.0.0-beta.2",
"astro": "^5.0.0-beta.7",
"svelte": "^4.2.19"
"@astrojs/svelte": "^6.0.0",
"astro": "^5.0.0-beta.8",
"svelte": "^5.1.16"
}
}
15 changes: 11 additions & 4 deletions examples/framework-svelte/src/components/Counter.svelte
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
<script lang="ts">
let count = 0;
import type { Snippet } from 'svelte';
interface Props {
children?: Snippet
}
let { children }: Props = $props();
let count = $state(0);
function add() {
count += 1;
Expand All @@ -11,12 +18,12 @@
</script>

<div class="counter">
<button on:click={subtract}>-</button>
<button onclick={subtract}>-</button>
<pre>{count}</pre>
<button on:click={add}>+</button>
<button onclick={add}>+</button>
</div>
<div class="message">
<slot />
{@render children?.()}
</div>

<style>
Expand Down
2 changes: 1 addition & 1 deletion examples/framework-vue/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
2 changes: 1 addition & 1 deletion examples/hackernews/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@
},
"dependencies": {
"@astrojs/node": "^9.0.0-alpha.1",
"astro": "^5.0.0-beta.7"
"astro": "^5.0.0-beta.8"
}
}
Loading

0 comments on commit e63f5a2

Please sign in to comment.