From d3bc1cec76d9f9755f8bd7785954a56e02b15b5f Mon Sep 17 00:00:00 2001
From: HiDeoo <494699+HiDeoo@users.noreply.github.com>
Date: Tue, 18 Feb 2025 20:51:16 +0100
Subject: [PATCH 1/3] chore: add repro
---
docs/astro.config.mjs | 3 ++-
docs/package.json | 1 +
docs/src/content/docs/index.mdx | 4 ++++
packages/repro-plugin/Route.astro | 15 +++++++++++++++
packages/repro-plugin/index.ts | 26 ++++++++++++++++++++++++++
packages/repro-plugin/package.json | 20 ++++++++++++++++++++
pnpm-lock.yaml | 9 +++++++++
7 files changed, 77 insertions(+), 1 deletion(-)
create mode 100644 packages/repro-plugin/Route.astro
create mode 100644 packages/repro-plugin/index.ts
create mode 100644 packages/repro-plugin/package.json
diff --git a/docs/astro.config.mjs b/docs/astro.config.mjs
index 9906df38447..04b950366cd 100644
--- a/docs/astro.config.mjs
+++ b/docs/astro.config.mjs
@@ -3,6 +3,7 @@ import { defineConfig } from 'astro/config';
import starlight from '@astrojs/starlight';
import starlightLinksValidator from 'starlight-links-validator';
import markdocGrammar from './grammars/markdoc.tmLanguage.json';
+import reproPlugin from 'repro-plugin';
export const locales = {
root: { label: 'English', lang: 'en' },
@@ -189,7 +190,7 @@ export default defineConfig({
errorOnInconsistentLocale: true,
}),
]
- : [],
+ : [reproPlugin()],
}),
],
});
diff --git a/docs/package.json b/docs/package.json
index 6ee67487e85..1c7f3244a1d 100644
--- a/docs/package.json
+++ b/docs/package.json
@@ -22,6 +22,7 @@
"@types/culori": "^2.1.1",
"astro": "^5.1.5",
"culori": "^4.0.1",
+ "repro-plugin": "workspace:*",
"sharp": "^0.32.5"
},
"devDependencies": {
diff --git a/docs/src/content/docs/index.mdx b/docs/src/content/docs/index.mdx
index 985a7e61a15..d507e234fa4 100644
--- a/docs/src/content/docs/index.mdx
+++ b/docs/src/content/docs/index.mdx
@@ -28,6 +28,10 @@ hero:
link: https://github.com/withastro/starlight
---
+import { YouTube } from '@astro-community/astro-embed-youtube';
+
+
+
import { CardGrid, Card } from '@astrojs/starlight/components';
import AboutAstro from '~/components/about-astro.astro';
import TestimonialGrid from '~/components/testimonial-grid.astro';
diff --git a/packages/repro-plugin/Route.astro b/packages/repro-plugin/Route.astro
new file mode 100644
index 00000000000..d74717a8664
--- /dev/null
+++ b/packages/repro-plugin/Route.astro
@@ -0,0 +1,15 @@
+---
+import StarlightPage from '@astrojs/starlight/components/StarlightPage.astro';
+
+export function getStaticPaths() {
+ return [
+ { params: { dog: 'clifford' } },
+ { params: { dog: 'rover' } },
+ { params: { dog: 'spot' } },
+ ];
+}
+---
+
+
+ This is a custom page with a custom component:
+
diff --git a/packages/repro-plugin/index.ts b/packages/repro-plugin/index.ts
new file mode 100644
index 00000000000..667c2b6ffa0
--- /dev/null
+++ b/packages/repro-plugin/index.ts
@@ -0,0 +1,26 @@
+import type { StarlightPlugin } from '@astrojs/starlight/types';
+
+export default function reproPlugin(): StarlightPlugin {
+ return {
+ name: 'repro-plugin',
+ hooks: {
+ 'config:setup': ({ addIntegration }) => {
+ addIntegration({
+ name: 'repro-integration',
+ hooks: {
+ 'astro:config:setup': ({ injectRoute }) => {
+ injectRoute({
+ entrypoint: 'repro-plugin/Route.astro',
+ // This seems to trigger the issue
+ pattern: '[...dog]',
+ // Using this pattern instead works
+ // pattern: '/repro',
+ prerender: true,
+ });
+ },
+ },
+ });
+ },
+ },
+ };
+}
diff --git a/packages/repro-plugin/package.json b/packages/repro-plugin/package.json
new file mode 100644
index 00000000000..d2fcd5f5f2b
--- /dev/null
+++ b/packages/repro-plugin/package.json
@@ -0,0 +1,20 @@
+{
+ "name": "repro-plugin",
+ "version": "0.0.1",
+ "private": true,
+ "type": "module",
+ "files": [
+ "index.ts",
+ "Route.astro"
+ ],
+ "exports": {
+ ".": "./index.ts",
+ "./Route.astro": "./Route.astro"
+ },
+ "peerDependencies": {
+ "@astrojs/starlight": ">=0.32.0"
+ },
+ "devDependencies": {
+ "@astrojs/starlight": "workspace:*"
+ }
+}
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index e18443bc237..b66fec858eb 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -56,6 +56,9 @@ importers:
culori:
specifier: ^4.0.1
version: 4.0.1
+ repro-plugin:
+ specifier: workspace:*
+ version: link:../packages/repro-plugin
sharp:
specifier: ^0.32.5
version: 0.32.6
@@ -162,6 +165,12 @@ importers:
specifier: ^3.0.5
version: 3.0.5(@types/node@18.16.19)
+ packages/repro-plugin:
+ devDependencies:
+ '@astrojs/starlight':
+ specifier: workspace:*
+ version: link:../starlight
+
packages/starlight:
dependencies:
'@astrojs/mdx':
From f356443fce470318f1cd0d8316fe6d1acab6e2a1 Mon Sep 17 00:00:00 2001
From: HiDeoo <494699+HiDeoo@users.noreply.github.com>
Date: Wed, 19 Feb 2025 10:03:56 +0100
Subject: [PATCH 2/3] chore: remove plugin from repro
---
docs/astro.config.mjs | 3 +--
docs/package.json | 1 -
docs/src/components/Test.astro | 7 ++++++
docs/src/content/docs/index.mdx | 4 ++--
docs/src/pages/[...dog].astro | 36 ++++++++++++++++++++++++++++++
packages/repro-plugin/Route.astro | 15 -------------
packages/repro-plugin/index.ts | 26 ---------------------
packages/repro-plugin/package.json | 20 -----------------
pnpm-lock.yaml | 9 --------
9 files changed, 46 insertions(+), 75 deletions(-)
create mode 100644 docs/src/components/Test.astro
create mode 100644 docs/src/pages/[...dog].astro
delete mode 100644 packages/repro-plugin/Route.astro
delete mode 100644 packages/repro-plugin/index.ts
delete mode 100644 packages/repro-plugin/package.json
diff --git a/docs/astro.config.mjs b/docs/astro.config.mjs
index 04b950366cd..9906df38447 100644
--- a/docs/astro.config.mjs
+++ b/docs/astro.config.mjs
@@ -3,7 +3,6 @@ import { defineConfig } from 'astro/config';
import starlight from '@astrojs/starlight';
import starlightLinksValidator from 'starlight-links-validator';
import markdocGrammar from './grammars/markdoc.tmLanguage.json';
-import reproPlugin from 'repro-plugin';
export const locales = {
root: { label: 'English', lang: 'en' },
@@ -190,7 +189,7 @@ export default defineConfig({
errorOnInconsistentLocale: true,
}),
]
- : [reproPlugin()],
+ : [],
}),
],
});
diff --git a/docs/package.json b/docs/package.json
index 1c7f3244a1d..6ee67487e85 100644
--- a/docs/package.json
+++ b/docs/package.json
@@ -22,7 +22,6 @@
"@types/culori": "^2.1.1",
"astro": "^5.1.5",
"culori": "^4.0.1",
- "repro-plugin": "workspace:*",
"sharp": "^0.32.5"
},
"devDependencies": {
diff --git a/docs/src/components/Test.astro b/docs/src/components/Test.astro
new file mode 100644
index 00000000000..5d3bcaf7a17
--- /dev/null
+++ b/docs/src/components/Test.astro
@@ -0,0 +1,7 @@
+
I am purple
+
+
diff --git a/docs/src/content/docs/index.mdx b/docs/src/content/docs/index.mdx
index d507e234fa4..fb6a2f47b6e 100644
--- a/docs/src/content/docs/index.mdx
+++ b/docs/src/content/docs/index.mdx
@@ -28,9 +28,9 @@ hero:
link: https://github.com/withastro/starlight
---
-import { YouTube } from '@astro-community/astro-embed-youtube';
+import Test from '../../components/Test.astro';
-
+
import { CardGrid, Card } from '@astrojs/starlight/components';
import AboutAstro from '~/components/about-astro.astro';
diff --git a/docs/src/pages/[...dog].astro b/docs/src/pages/[...dog].astro
new file mode 100644
index 00000000000..b7c79b64c24
--- /dev/null
+++ b/docs/src/pages/[...dog].astro
@@ -0,0 +1,36 @@
+---
+import StarlightPage from '@astrojs/starlight/components/StarlightPage.astro';
+
+/**
+ * Two conditions must be met for the issue to occur:
+ *
+ * - Use a rest parameter for the route
+ * - Render ``
+ */
+
+export function getStaticPaths() {
+ return [
+ { params: { dog: 'clifford' } },
+ { params: { dog: 'rover' } },
+ { params: { dog: 'spot' } },
+ ];
+}
+---
+
+
+ This is a custom page
+
+
+
+
+
diff --git a/packages/repro-plugin/Route.astro b/packages/repro-plugin/Route.astro
deleted file mode 100644
index d74717a8664..00000000000
--- a/packages/repro-plugin/Route.astro
+++ /dev/null
@@ -1,15 +0,0 @@
----
-import StarlightPage from '@astrojs/starlight/components/StarlightPage.astro';
-
-export function getStaticPaths() {
- return [
- { params: { dog: 'clifford' } },
- { params: { dog: 'rover' } },
- { params: { dog: 'spot' } },
- ];
-}
----
-
-
- This is a custom page with a custom component:
-
diff --git a/packages/repro-plugin/index.ts b/packages/repro-plugin/index.ts
deleted file mode 100644
index 667c2b6ffa0..00000000000
--- a/packages/repro-plugin/index.ts
+++ /dev/null
@@ -1,26 +0,0 @@
-import type { StarlightPlugin } from '@astrojs/starlight/types';
-
-export default function reproPlugin(): StarlightPlugin {
- return {
- name: 'repro-plugin',
- hooks: {
- 'config:setup': ({ addIntegration }) => {
- addIntegration({
- name: 'repro-integration',
- hooks: {
- 'astro:config:setup': ({ injectRoute }) => {
- injectRoute({
- entrypoint: 'repro-plugin/Route.astro',
- // This seems to trigger the issue
- pattern: '[...dog]',
- // Using this pattern instead works
- // pattern: '/repro',
- prerender: true,
- });
- },
- },
- });
- },
- },
- };
-}
diff --git a/packages/repro-plugin/package.json b/packages/repro-plugin/package.json
deleted file mode 100644
index d2fcd5f5f2b..00000000000
--- a/packages/repro-plugin/package.json
+++ /dev/null
@@ -1,20 +0,0 @@
-{
- "name": "repro-plugin",
- "version": "0.0.1",
- "private": true,
- "type": "module",
- "files": [
- "index.ts",
- "Route.astro"
- ],
- "exports": {
- ".": "./index.ts",
- "./Route.astro": "./Route.astro"
- },
- "peerDependencies": {
- "@astrojs/starlight": ">=0.32.0"
- },
- "devDependencies": {
- "@astrojs/starlight": "workspace:*"
- }
-}
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index b66fec858eb..e18443bc237 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -56,9 +56,6 @@ importers:
culori:
specifier: ^4.0.1
version: 4.0.1
- repro-plugin:
- specifier: workspace:*
- version: link:../packages/repro-plugin
sharp:
specifier: ^0.32.5
version: 0.32.6
@@ -165,12 +162,6 @@ importers:
specifier: ^3.0.5
version: 3.0.5(@types/node@18.16.19)
- packages/repro-plugin:
- devDependencies:
- '@astrojs/starlight':
- specifier: workspace:*
- version: link:../starlight
-
packages/starlight:
dependencies:
'@astrojs/mdx':
From 65283708faebaa201c366b3bfee20a4fbeb2b264 Mon Sep 17 00:00:00 2001
From: HiDeoo <494699+HiDeoo@users.noreply.github.com>
Date: Wed, 19 Feb 2025 11:20:23 +0100
Subject: [PATCH 3/3] fix: i don't know
---
packages/starlight/routes/common.astro | 2 +-
packages/starlight/utils/routing/data.ts | 2 +-
packages/starlight/utils/routing/use-data.ts | 14 ++++++++++++++
3 files changed, 16 insertions(+), 2 deletions(-)
create mode 100644 packages/starlight/utils/routing/use-data.ts
diff --git a/packages/starlight/routes/common.astro b/packages/starlight/routes/common.astro
index b96ef3fba4c..396f6c8ced0 100644
--- a/packages/starlight/routes/common.astro
+++ b/packages/starlight/routes/common.astro
@@ -1,6 +1,6 @@
---
import Page from '../components/Page.astro';
-import { useRouteData } from '../utils/routing/data';
+import { useRouteData } from '../utils/routing/use-data';
import { attachRouteDataAndRunMiddleware } from '../utils/routing/middleware';
await attachRouteDataAndRunMiddleware(Astro, await useRouteData(Astro));
diff --git a/packages/starlight/utils/routing/data.ts b/packages/starlight/utils/routing/data.ts
index 302532d98e5..350d1d71040 100644
--- a/packages/starlight/utils/routing/data.ts
+++ b/packages/starlight/utils/routing/data.ts
@@ -117,7 +117,7 @@ export function getSiteTitleHref(locale: string | undefined): string {
}
/** Generate a route object for Starlight’s 404 page. */
-async function get404Route(locals: App.Locals): Promise {
+export async function get404Route(locals: App.Locals): Promise {
const { lang = BuiltInDefaultLocale.lang, dir = BuiltInDefaultLocale.dir } =
config.defaultLocale || {};
let locale = config.defaultLocale?.locale;
diff --git a/packages/starlight/utils/routing/use-data.ts b/packages/starlight/utils/routing/use-data.ts
new file mode 100644
index 00000000000..5964f16f5f3
--- /dev/null
+++ b/packages/starlight/utils/routing/use-data.ts
@@ -0,0 +1,14 @@
+import type { APIContext } from 'astro';
+import { getRouteBySlugParam } from '../routing';
+import type { StarlightRouteData } from './types';
+import { render } from 'astro:content';
+import { generateRouteData, get404Route } from './data';
+
+export async function useRouteData(context: APIContext): Promise {
+ const route =
+ ('slug' in context.params && getRouteBySlugParam(context.params.slug)) ||
+ (await get404Route(context.locals));
+ const { Content, headings } = await render(route.entry);
+ const routeData = generateRouteData({ props: { ...route, headings }, url: context.url });
+ return { ...routeData, Content };
+}