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

Merge branch 'main' into next

This commit is contained in:
Matthew Phillips 2024-09-13 16:08:58 -04:00
commit 4724b14431
13 changed files with 149 additions and 89 deletions

View file

@ -1,63 +0,0 @@
---
'astro': patch
---
Adds support for Zod discriminated unions on Action form inputs. This allows forms with different inputs to be submitted to the same action, using a given input to decide which object should be used for validation.
This example accepts either a `create` or `update` form submission, and uses the `type` field to determine which object to validate against.
```ts
import { defineAction } from 'astro:actions';
import { z } from 'astro:schema';
export const server = {
changeUser: defineAction({
accept: 'form',
input: z.discriminatedUnion('type', [
z.object({
type: z.literal('create'),
name: z.string(),
email: z.string().email(),
}),
z.object({
type: z.literal('update'),
id: z.number(),
name: z.string(),
email: z.string().email(),
}),
]),
async handler(input) {
if (input.type === 'create') {
// input is { type: 'create', name: string, email: string }
} else {
// input is { type: 'update', id: number, name: string, email: string }
}
},
}),
}
```
The corresponding `create` and `update` forms may look like this:
```astro
---
import { actions } from 'astro:actions';
---
<!--Create-->
<form action={actions.changeUser} method="POST">
<input type="hidden" name="type" value="create" />
<input type="text" name="name" required />
<input type="email" name="email" required />
<button type="submit">Create User</button>
</form>
<!--Update-->
<form action={actions.changeUser} method="POST">
<input type="hidden" name="type" value="update" />
<input type="hidden" name="id" value="user-123" />
<input type="text" name="name" required />
<input type="email" name="email" required />
<button type="submit">Update User</button>
</form>
```

View file

@ -18,7 +18,7 @@
"@types/react": "^18.3.5",
"@types/react-dom": "^18.3.0",
"astro": "^5.0.0-alpha.7",
"postcss": "^8.4.43",
"postcss": "^8.4.45",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"tailwindcss": "^3.4.10"

View file

@ -11,7 +11,7 @@
},
"dependencies": {
"astro": "^5.0.0-alpha.7",
"sass": "^1.77.8",
"sass": "^1.78.0",
"sharp": "^0.33.3"
}
}

View file

@ -137,6 +137,20 @@
- [#11974](https://github.com/withastro/astro/pull/11974) [`60211de`](https://github.com/withastro/astro/commit/60211defbfb2992ba17d1369e71c146d8928b09a) Thanks [@ascorbic](https://github.com/ascorbic)! - Exports the `RenderResult` type
## 4.15.6
### Patch Changes
- [#11993](https://github.com/withastro/astro/pull/11993) [`ffba5d7`](https://github.com/withastro/astro/commit/ffba5d716edcdfc42899afaa4188b7a4cd0c91eb) Thanks [@matthewp](https://github.com/matthewp)! - Fix getStaticPaths regression
This reverts a previous change meant to remove a dependency, to fix a regression with multiple nested spread routes.
- [#11964](https://github.com/withastro/astro/pull/11964) [`06eff60`](https://github.com/withastro/astro/commit/06eff60cabb55d91fe4075421b1693b1ab33225c) Thanks [@TheOtterlord](https://github.com/TheOtterlord)! - Add wayland (wl-copy) support to `astro info`
## 4.15.5
### Patch Changes
- [#11939](https://github.com/withastro/astro/pull/11939) [`7b09c62`](https://github.com/withastro/astro/commit/7b09c62b565cd7b50c35fb68d390729f936a43fb) Thanks [@bholmesdev](https://github.com/bholmesdev)! - Adds support for Zod discriminated unions on Action form inputs. This allows forms with different inputs to be submitted to the same action, using a given input to decide which object should be used for validation.
This example accepts either a `create` or `update` form submission, and uses the `type` field to determine which object to validate against.
@ -265,6 +279,9 @@
}),
});
```
- [#11968](https://github.com/withastro/astro/pull/11968) [`86ad1fd`](https://github.com/withastro/astro/commit/86ad1fd223e2d2c448372caa159090efbee69237) Thanks [@NikolaRHristov](https://github.com/NikolaRHristov)! - Fixes a typo in the server island JSDoc
- [#11983](https://github.com/withastro/astro/pull/11983) [`633eeaa`](https://github.com/withastro/astro/commit/633eeaa9d8a8a35bba638fde06fd8f52cc1c2ce3) Thanks [@uwej711](https://github.com/uwej711)! - Remove dependency on path-to-regexp
## 4.15.4

View file

@ -165,7 +165,7 @@
"ora": "^8.1.0",
"p-limit": "^6.1.0",
"p-queue": "^8.0.1",
"path-to-regexp": "^6.2.2",
"path-to-regexp": "6.2.2",
"preferred-pm": "^4.0.0",
"prompts": "^2.4.2",
"rehype": "^13.0.1",

View file

@ -55,6 +55,7 @@ export async function printInfo({ flags }: InfoOptions) {
}
async function copyToClipboard(text: string) {
text = text.trim();
const system = platform();
let command = '';
if (system === 'darwin') {
@ -62,18 +63,26 @@ async function copyToClipboard(text: string) {
} else if (system === 'win32') {
command = 'clip';
} else {
try {
// Unix: check if `xclip` is installed
const output = execSync('which xclip', { encoding: 'utf8' });
if (output[0] !== '/') {
// Did not find a path for xclip, bail out!
return;
// Unix: check if a supported command is installed
const unixCommands = [
['xclip', '-sel clipboard -l 1'],
['wl-copy', '"$0"'],
];
for (const [unixCommand, args] of unixCommands) {
try {
const output = execSync(`which ${unixCommand}`, { encoding: 'utf8', stdio: 'pipe' });
if (output[0] !== '/') {
// Did not find a path. Skip!
continue;
}
command = `${unixCommand} ${args}`;
} catch {
// Failed to execute which. Skip!
continue;
}
command = 'xclip -sel clipboard -l 1';
} catch {
// Did not find xclip, bail out!
return;
}
// Did not find supported command. Bail out!
if (!command) return;
}
console.log();
@ -86,8 +95,9 @@ async function copyToClipboard(text: string) {
if (!shouldCopy) return;
try {
execSync(command, {
input: text.trim(),
execSync(command.replaceAll('$0', text), {
stdio: 'ignore',
input: text,
encoding: 'utf8',
});
} catch {

View file

@ -0,0 +1,37 @@
---
export async function getStaticPaths({ paginate }) {
const paths = [
{
slug: 'news/july-2024',
items: ['item 1', 'item 2', 'item 3', 'item 4', 'item 5', 'item 6'],
contentType: 'news',
monthYear: 'july-2024',
}
];
return paths.flatMap((path) => {
return paginate(path.items, {
params: { slug: path.slug },
props: {
contentType: path.contentType,
monthYear: path.monthYear,
},
pageSize: 2,
});
});
}
const { slug, page } = Astro.params;
---
<html>
<head>
<title>Testing</title>
</head>
<body>
<h1>Testing</h1>
<p id="slug">{slug}</p>
<p id="page">{page}</p>
</body>
</html>

View file

@ -25,4 +25,12 @@ describe('getStaticPaths with trailingSlash: ignore', () => {
let $ = cheerio.load(html);
assert.equal($('h1').text(), 'Page 2');
});
// for regression: https://github.com/withastro/astro/issues/11990
it('nested static paths generate', async () => {
let html = await fixture.readFile('/archive/news/july-2024/2/index.html');
let $ = cheerio.load(html);
assert.equal($('#slug').text(), 'news');
assert.equal($('#page').text(), 'july-2024/2');
});
});

View file

@ -23,6 +23,12 @@
- astro@5.0.0-alpha.0
- @astrojs/markdown-remark@6.0.0-alpha.0
## 3.1.6
### Patch Changes
- [#11975](https://github.com/withastro/astro/pull/11975) [`c9ae7b1`](https://github.com/withastro/astro/commit/c9ae7b1b89e050900bbc111f29e8c5d95c26bf36) Thanks [@bluwy](https://github.com/bluwy)! - Handles nested root hast node when optimizing MDX
## 3.1.5
### Patch Changes

View file

@ -64,8 +64,14 @@ export const rehypeOptimizeStatic: RehypePlugin<[OptimizeOptions?]> = (options)
* A non-static node causes all its parents to be non-optimizable
*/
const isNodeNonStatic = (node: Node) => {
// @ts-expect-error Access `.tagName` naively for perf
return node.type.startsWith('mdx') || ignoreElementNames.has(node.tagName);
return (
node.type.startsWith('mdx') ||
// @ts-expect-error `node` should never have `type: 'root'`, but in some cases plugins may inject it as children,
// which MDX will render as a fragment instead (an MDX fragment is a `mdxJsxFlowElement` type).
node.type === 'root' ||
// @ts-expect-error Access `.tagName` naively for perf
ignoreElementNames.has(node.tagName)
);
};
visit(tree as any, {

View file

@ -1,9 +1,37 @@
import mdx from '@astrojs/mdx';
export default {
integrations: [mdx({
optimize: {
ignoreElementNames: ['strong']
}
})]
}
integrations: [
mdx({
optimize: {
ignoreElementNames: ['strong'],
},
}),
],
markdown: {
rehypePlugins: [
() => {
return (tree) => {
tree.children.push({
type: 'root',
children: [
{
type: 'element',
tagName: 'p',
properties: {
id: 'injected-root-hast',
},
children: [
{
type: 'text',
value: 'Injected root hast from rehype plugin',
},
],
},
],
});
};
},
],
},
};

View file

@ -47,4 +47,15 @@ describe('MDX optimize', () => {
assert.notEqual(blockquote, null);
assert.equal(blockquote.textContent.includes('I like pancakes'), true);
});
it('renders MDX with rehype plugin that incorrectly injects root hast node', async () => {
const html = await fixture.readFile('/import/index.html');
const { document } = parseHTML(html);
assert.doesNotMatch(html, /set:html=/);
assert.equal(
document.getElementById('injected-root-hast').textContent,
'Injected root hast from rehype plugin',
);
});
});

View file

@ -373,7 +373,7 @@ importers:
specifier: ^5.0.0-alpha.7
version: link:../../packages/astro
postcss:
specifier: ^8.4.43
specifier: ^8.4.45
version: 8.4.45
react:
specifier: ^18.3.1
@ -406,7 +406,7 @@ importers:
specifier: ^5.0.0-alpha.7
version: link:../../packages/astro
sass:
specifier: ^1.77.8
specifier: ^1.78.0
version: 1.78.0
sharp:
specifier: ^0.33.3
@ -670,7 +670,7 @@ importers:
specifier: ^8.0.1
version: 8.0.1
path-to-regexp:
specifier: ^6.2.2
specifier: 6.2.2
version: 6.2.2
preferred-pm:
specifier: ^4.0.0