0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2025-02-10 22:38:53 -05:00

skip client directives via option

This commit is contained in:
Emanuele Stoppa 2024-06-27 10:53:25 +01:00
parent 2eb8a84493
commit 5ebe041f0e
2 changed files with 17 additions and 7 deletions

View file

@ -84,6 +84,13 @@ export type ContainerRenderOptions = {
* ``` * ```
*/ */
props?: Props; props?: Props;
/**
* Allows to bypass clientside hydration of components.
*
* If you're testing components that use `client:*` directives, you might want to use this option.
*/
skipClientDirectives?: boolean;
}; };
export type AddServerRenderer = export type AddServerRenderer =
@ -436,8 +443,9 @@ export class experimental_AstroContainer {
pathname: url.pathname, pathname: url.pathname,
locals: options?.locals ?? {}, locals: options?.locals ?? {},
}); });
// client directives aren't needed in this case if (options.skipClientDirectives === true) {
renderContext.skipHydration = true; renderContext.skipHydration = true;
}
if (options.params) { if (options.params) {
renderContext.params = options.params; renderContext.params = options.params;
} }

View file

@ -1,10 +1,12 @@
import type {APIRoute, SSRLoadedRenderer} from "astro"; import type { APIRoute, SSRLoadedRenderer } from 'astro';
import { experimental_AstroContainer } from "astro/container"; import { experimental_AstroContainer } from 'astro/container';
import renderer from '@astrojs/react/server.js'; import renderer from '@astrojs/react/server.js';
import Component from "../components/buttonDirective.astro" import Component from '../components/buttonDirective.astro';
export const GET: APIRoute = async (ctx) => { export const GET: APIRoute = async (ctx) => {
const container = await experimental_AstroContainer.create(); const container = await experimental_AstroContainer.create();
container.addServerRenderer({ renderer }); container.addServerRenderer({ renderer });
return await container.renderToResponse(Component); return await container.renderToResponse(Component, {
} skipClientDirectives: true,
});
};