Skip to content

Commit

Permalink
Merge branch 'next' into feat/dotastro-move
Browse files Browse the repository at this point in the history
  • Loading branch information
florian-lefebvre authored Sep 23, 2024
2 parents 46fd026 + 325a57c commit d077e47
Show file tree
Hide file tree
Showing 56 changed files with 730 additions and 117 deletions.
5 changes: 5 additions & 0 deletions .changeset/beige-points-search.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'astro': patch
---

Fixes an issue where component styles were not correctly included in rendered MDX
5 changes: 5 additions & 0 deletions .changeset/cold-bananas-hear.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'astro': patch
---

Correctly parse values returned from inline loader
5 changes: 5 additions & 0 deletions .changeset/hot-camels-move.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'astro': patch
---

Properly handle including trailing slash on the image endpoint route based on the trailingSlash config
7 changes: 7 additions & 0 deletions .changeset/sixty-oranges-walk.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'astro': patch
---

Resolves image paths in content layer with initial slash as project-relative

When using the `image()` schema helper, previously paths with an initial slash were treated as public URLs. This was to match the behavior of markdown images. However this is a change from before, where paths with an initial slash were treated as project-relative. This change restores the previous behavior, so that paths with an initial slash are treated as project-relative.
2 changes: 1 addition & 1 deletion examples/component/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@
"astro": "^5.0.0-beta.1"
},
"peerDependencies": {
"astro": "^4.0.0"
"astro": "^4.0.0 || ^5.0.0"
}
}
2 changes: 1 addition & 1 deletion examples/server-islands/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"devDependencies": {
"@astrojs/node": "^9.0.0-alpha.1",
"@astrojs/react": "^3.6.2",
"@astrojs/tailwind": "^5.1.0",
"@astrojs/tailwind": "^5.1.1",
"@fortawesome/fontawesome-free": "^6.6.0",
"@tailwindcss/forms": "^0.5.9",
"@types/react": "^18.3.5",
Expand Down
8 changes: 8 additions & 0 deletions packages/astro/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,14 @@

- [#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.7

### Patch Changes

- [#12000](https://github.com/withastro/astro/pull/12000) [`a2f8c5d`](https://github.com/withastro/astro/commit/a2f8c5d85ff15803f5cedf9148cd70ffc138ddef) Thanks [@ArmandPhilippot](https://github.com/ArmandPhilippot)! - Fixes an outdated link used to document Content Layer API

- [#11915](https://github.com/withastro/astro/pull/11915) [`0b59fe7`](https://github.com/withastro/astro/commit/0b59fe74d5922c572007572ddca8d11482e2fb5c) Thanks [@azhirov](https://github.com/azhirov)! - Fix: prevent island from re-rendering when using transition:persist (#11854)

## 4.15.6

### Patch Changes
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
import nodejs from '@astrojs/node';
import react from '@astrojs/react';
import svelte from '@astrojs/svelte';
import solidjs from '@astrojs/solid-js';
import vue from '@astrojs/vue';
import { defineConfig } from 'astro/config';

// https://astro.build/config
export default defineConfig({
output: 'static',
adapter: nodejs({ mode: 'standalone' }),
integrations: [react(),vue(),svelte()],
integrations: [react( {
exclude: ['**/solid/**'],
}),vue(),svelte(),solidjs({
include: ['**/solid/**'],
})],
redirects: {
'/redirect-two': '/two',
'/redirect-external': 'http://example.com/',
Expand Down
4 changes: 3 additions & 1 deletion packages/astro/e2e/fixtures/view-transitions/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@
"@astrojs/react": "workspace:*",
"@astrojs/svelte": "workspace:*",
"@astrojs/vue": "workspace:*",
"@astrojs/solid-js": "workspace:*",
"astro": "workspace:*",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"svelte": "^4.2.19",
"vue": "^3.5.3"
"vue": "^3.5.3",
"solid-js": "^1.8.0"
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<script lang="ts">
let count = 0;
export let prefix = "";
function add() {
count += 1;
Expand All @@ -11,9 +12,9 @@
</script>

<div class="counter">
<button on:click={subtract}>-</button>
<pre>{count}</pre>
<button on:click={add}>+</button>
<button on:click={subtract} class="decrement">-</button>
<pre>{prefix}{count}</pre>
<button on:click={add} class="increment">+</button>
</div>
<div class="message">
<slot />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<template>
<div class="counter">
<button @click="subtract()">-</button>
<pre>{{ count }}</pre>
<button @click="add()">+</button>
<button @click="subtract()" class="decrement">-</button>
<pre>{{prefix}}{{ count }}</pre>
<button @click="add()" class="increment">+</button>
</div>
<div class="counter-message">
<slot />
Expand All @@ -12,6 +12,12 @@
<script lang="ts">
import { ref } from 'vue';
export default {
props: {
prefix: {
type: String,
default: '',
},
},
setup() {
const count = ref(0);
const add = () => (count.value = count.value + 1);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import {createSignal} from "solid-js";

export default function Counter(props) {
const [count, setCount] = createSignal(0);
const add = () => setCount(count() + 1);
const subtract = () => setCount(count() - 1);

return (
<>
<div class="counter">
<button onClick={subtract} class="decrement">-</button>

<pre>{props.prefix ?? ''}{count()}{props.postfix ?? ""}</pre>
<button onClick={add} class="increment">+</button>
</div>
<div class="counter-message">{props.children}</div>
</>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
import Layout from '../components/Layout.astro';
import Counter from '../components/solid/Counter.jsx';
export const prerender = false;
---
<Layout>
<p id="island-one">Page 1</p>
<a id="click-two" href="/island-solid-two">go to 2</a>
<Counter prefix="A" client:load transition:persist transition:name="counter" />
</Layout>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
import Layout from '../components/Layout.astro';
import Counter from '../components/solid/Counter.jsx';
export const prerender = false;
---
<Layout>
<p id="island-two">Page 2</p>
<a id="click-one" href="/island-solid-one">go to 1</a>
<Counter prefix="B" postfix="!" client:load transition:persist transition:name="counter" />
</Layout>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
import Counter from '../components/SvelteCounter.svelte';
import Layout from '../components/Layout.astro';
export const prerender = false;
---
<Layout>
<p id="island-one">Page 1</p>
<a id="click-two" href="/island-svelte-two">go to 2</a>
<Counter prefix="A" client:load transition:persist transition:name="counter"/>
</Layout>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
import Counter from '../components/SvelteCounter.svelte';
import Layout from '../components/Layout.astro';
export const prerender = false;
---
<Layout>
<p id="island-two">Page 2</p>
<a id="click-one" href="/island-svelte-one">go to 1</a>
<Counter prefix="B" client:load transition:persist transition:name="counter"/>
</Layout>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
import Layout from '../components/Layout.astro';
import Counter from '../components/VueCounter.vue';
export const prerender = false;
---
<Layout>
<p id="island-one">Page 1</p>
<a id="click-two" href="/island-vue-two">go to 2</a>
<Counter prefix="AA" client:load transition:persist transition:name="counter" />
</Layout>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
import Layout from '../components/Layout.astro';
import Counter from '../components/VueCounter.vue';
export const prerender = false;
---
<Layout>
<p id="island-two">Page 2</p>
<a id="click-two" href="/island-vue-one">go to 1</a>
<Counter prefix="BB" client:load transition:persist transition:name="counter" />
</Layout>
63 changes: 62 additions & 1 deletion packages/astro/e2e/view-transitions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,7 @@ test.describe('View Transitions', () => {
expect(secondTime).toBeGreaterThanOrEqual(firstTime);
});

test('Islands can persist using transition:persist', async ({ page, astro }) => {
test('React Islands can persist using transition:persist', async ({ page, astro }) => {
// Go to page 1
await page.goto(astro.resolveUrl('/island-one'));
let cnt = page.locator('.counter pre');
Expand All @@ -544,6 +544,67 @@ test.describe('View Transitions', () => {
await expect(pageTitle).toHaveText('Island 2');
});

test('Solid Islands can persist using transition:persist', async ({ page, astro }) => {
// Go to page 1
await page.goto(astro.resolveUrl('/island-solid-one'));
let cnt = page.locator('.counter pre');
await expect(cnt).toHaveText('A0');

await page.click('.increment');
await expect(cnt).toHaveText('A1');

// Navigate to page 2
await page.click('#click-two');
let p = page.locator('#island-two');
await expect(p).toBeVisible();
cnt = page.locator('.counter pre');
// Count should remain, but the prefix should be updated
await expect(cnt).toHaveText('B1!');

await page.click('#click-one');
p = page.locator('#island-one');
await expect(p).toBeVisible();
cnt = page.locator('.counter pre');
// Count should remain, but the postfix should be removed again (to test unsetting props)
await expect(cnt).toHaveText('A1');
});

test('Svelte Islands can persist using transition:persist', async ({ page, astro }) => {
// Go to page 1
await page.goto(astro.resolveUrl('/island-svelte-one'));
let cnt = page.locator('.counter pre');
await expect(cnt).toHaveText('A0');

await page.click('.increment');
await expect(cnt).toHaveText('A1');

// Navigate to page 2
await page.click('#click-two');
let p = page.locator('#island-two');
await expect(p).toBeVisible();
cnt = page.locator('.counter pre');
// Count should remain, but the prefix should be updated
await expect(cnt).toHaveText('B1');
});

test('Vue Islands can persist using transition:persist', async ({ page, astro }) => {
// Go to page 1
await page.goto(astro.resolveUrl('/island-vue-one'));
let cnt = page.locator('.counter pre');
await expect(cnt).toHaveText('AA0');

await page.click('.increment');
await expect(cnt).toHaveText('AA1');

// Navigate to page 2
await page.click('#click-two');
const p = page.locator('#island-two');
await expect(p).toBeVisible();
cnt = page.locator('.counter pre');
// Count should remain, but the prefix should be updated
await expect(cnt).toHaveText('BB1');
});

test('transition:persist-props prevents props from changing', async ({ page, astro }) => {
// Go to page 1
await page.goto(astro.resolveUrl('/island-one?persist'));
Expand Down
5 changes: 4 additions & 1 deletion packages/astro/src/assets/services/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,10 @@ export const baseService: Omit<LocalImageService, 'transform'> = {
options[key] && searchParams.append(param, options[key].toString());
});

const imageEndpoint = joinPaths(import.meta.env.BASE_URL, imageConfig.endpoint.route);
const imageEndpoint = joinPaths(
import.meta.env.BASE_URL,
imageConfig.endpoint.route
);
return `${imageEndpoint}?${searchParams}`;
},
parseURL(url) {
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/src/assets/utils/resolveImports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export function imageSrcToImportId(imageSrc: string, filePath?: string): string
imageSrc = removeBase(imageSrc, IMAGE_IMPORT_PREFIX);

// We only care about local imports
if (isRemotePath(imageSrc) || imageSrc.startsWith('/')) {
if (isRemotePath(imageSrc)) {
return;
}
// We only care about images
Expand Down
48 changes: 44 additions & 4 deletions packages/astro/src/content/content-layer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { promises as fs, existsSync } from 'node:fs';
import * as fastq from 'fastq';
import type { FSWatcher } from 'vite';
import xxhash from 'xxhash-wasm';
import { AstroError, AstroErrorData } from '../core/errors/index.js';
import type { Logger } from '../core/logger/core.js';
import type { AstroSettings } from '../types/astro.js';
import type { ContentEntryType, RefreshContentOptions } from '../types/public/content.js';
Expand Down Expand Up @@ -263,15 +264,54 @@ export class ContentLayer {
}

export async function simpleLoader<TData extends { id: string }>(
handler: () => Array<TData> | Promise<Array<TData>>,
handler: () =>
| Array<TData>
| Promise<Array<TData>>
| Record<string, Record<string, unknown>>
| Promise<Record<string, Record<string, unknown>>>,
context: LoaderContext,
) {
const data = await handler();
context.store.clear();
for (const raw of data) {
const item = await context.parseData({ id: raw.id, data: raw });
context.store.set({ id: raw.id, data: item });
if (Array.isArray(data)) {
for (const raw of data) {
if (!raw.id) {
throw new AstroError({
...AstroErrorData.ContentLoaderInvalidDataError,
message: AstroErrorData.ContentLoaderInvalidDataError.message(
context.collection,
`Entry missing ID:\n${JSON.stringify({ ...raw, id: undefined }, null, 2)}`,
),
});
}
const item = await context.parseData({ id: raw.id, data: raw });
context.store.set({ id: raw.id, data: item });
}
return;
}
if (typeof data === 'object') {
for (const [id, raw] of Object.entries(data)) {
if (raw.id && raw.id !== id) {
throw new AstroError({
...AstroErrorData.ContentLoaderInvalidDataError,
message: AstroErrorData.ContentLoaderInvalidDataError.message(
context.collection,
`Object key ${JSON.stringify(id)} does not match ID ${JSON.stringify(raw.id)}`,
),
});
}
const item = await context.parseData({ id, data: raw });
context.store.set({ id, data: item });
}
return;
}
throw new AstroError({
...AstroErrorData.ExpectedImageOptions,
message: AstroErrorData.ContentLoaderInvalidDataError.message(
context.collection,
`Invalid data type: ${typeof data}`,
),
});
}
/**
* Get the path to the data store file.
Expand Down
Loading

0 comments on commit d077e47

Please sign in to comment.