From 45d879d30418d8c15f747543deafbf874c3e222d Mon Sep 17 00:00:00 2001 From: Kian Newman-Hazel Date: Tue, 18 Mar 2025 15:18:36 +0000 Subject: [PATCH 1/3] [Docs Site] Add React to Container API --- src/util/container.ts | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/util/container.ts b/src/util/container.ts index f1ed02544ab3bbc..fc5031ed717de9f 100644 --- a/src/util/container.ts +++ b/src/util/container.ts @@ -1,5 +1,6 @@ import { experimental_AstroContainer } from "astro/container"; -import { getContainerRenderer } from "@astrojs/mdx"; +import reactRenderer from "@astrojs/react/server.js"; +import mdxRenderer from "@astrojs/mdx/server.js"; import { loadRenderers } from "astro:container"; import { render, type CollectionEntry } from "astro:content"; import type { AstroComponentFactory } from "astro/runtime/server/index.js"; @@ -12,9 +13,14 @@ export async function entryToString( return entry.rendered.html; } - const renderers = await loadRenderers([getContainerRenderer()]); - const container = await experimental_AstroContainer.create({ - renderers, + const container = await experimental_AstroContainer.create({}); + container.addServerRenderer({ + name: "astro:jsx", + renderer: mdxRenderer, + }); + container.addServerRenderer({ + name: "@astrojs/react", + renderer: reactRenderer, }); const { Content } = await render(entry); From 5dc425a8e2045098c1af73f25916dbf0ee650520 Mon Sep 17 00:00:00 2001 From: Kian Newman-Hazel Date: Tue, 18 Mar 2025 15:24:40 +0000 Subject: [PATCH 2/3] fix componentToString --- src/util/container.ts | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/util/container.ts b/src/util/container.ts index fc5031ed717de9f..5ee40b96c2a6256 100644 --- a/src/util/container.ts +++ b/src/util/container.ts @@ -37,9 +37,14 @@ export async function componentToString( component: AstroComponentFactory, props: any, ) { - const renderers = await loadRenderers([getContainerRenderer()]); - const container = await experimental_AstroContainer.create({ - renderers, + const container = await experimental_AstroContainer.create({}); + container.addServerRenderer({ + name: "astro:jsx", + renderer: mdxRenderer, + }); + container.addServerRenderer({ + name: "@astrojs/react", + renderer: reactRenderer, }); const html = await container.renderToString(component, { From 78bf32c37f7c50c886ed1703e78bf3352b340c0f Mon Sep 17 00:00:00 2001 From: Kian Newman-Hazel Date: Tue, 18 Mar 2025 15:28:16 +0000 Subject: [PATCH 3/3] fix import --- src/util/container.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/util/container.ts b/src/util/container.ts index 5ee40b96c2a6256..bf22794f0a13d96 100644 --- a/src/util/container.ts +++ b/src/util/container.ts @@ -1,7 +1,6 @@ import { experimental_AstroContainer } from "astro/container"; import reactRenderer from "@astrojs/react/server.js"; import mdxRenderer from "@astrojs/mdx/server.js"; -import { loadRenderers } from "astro:container"; import { render, type CollectionEntry } from "astro:content"; import type { AstroComponentFactory } from "astro/runtime/server/index.js";