🍿 Minor Changes
-
#11234
4385bf7Thanks @ematipico! - Adds a new function calledaddServerRendererto the Container API. Use this function to manually store renderers inside the instance of your container.This new function should be preferred when using the Container API in environments like on-demand pages:
import type { APIRoute } from 'astro';import { experimental_AstroContainer } from 'astro/container';import reactRenderer from '@astrojs/react/server.js';import vueRenderer from '@astrojs/vue/server.js';import ReactComponent from '../components/button.jsx';import VueComponent from '../components/button.vue';// MDX runtime is contained inside the Astro coreimport mdxRenderer from 'astro/jsx/server.js';// In case you need to import a custom rendererimport customRenderer from '../renderers/customRenderer.js';export const GET: APIRoute = async (ctx) => {const container = await experimental_AstroContainer.create();container.addServerRenderer({ renderer: reactRenderer });container.addServerRenderer({ renderer: vueRenderer });container.addServerRenderer({ renderer: customRenderer });// You can pass a custom name toocontainer.addServerRenderer({name: 'customRenderer',renderer: customRenderer,});const vueComponent = await container.renderToString(VueComponent);return await container.renderToResponse(Component);};