mirror of
https://github.com/withastro/astro.git
synced 2025-02-03 22:29:08 -05:00
skip client directives via option
This commit is contained in:
parent
2eb8a84493
commit
5ebe041f0e
2 changed files with 17 additions and 7 deletions
|
@ -84,6 +84,13 @@ export type ContainerRenderOptions = {
|
|||
* ```
|
||||
*/
|
||||
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 =
|
||||
|
@ -436,8 +443,9 @@ export class experimental_AstroContainer {
|
|||
pathname: url.pathname,
|
||||
locals: options?.locals ?? {},
|
||||
});
|
||||
// client directives aren't needed in this case
|
||||
renderContext.skipHydration = true;
|
||||
if (options.skipClientDirectives === true) {
|
||||
renderContext.skipHydration = true;
|
||||
}
|
||||
if (options.params) {
|
||||
renderContext.params = options.params;
|
||||
}
|
||||
|
|
|
@ -1,10 +1,12 @@
|
|||
import type {APIRoute, SSRLoadedRenderer} from "astro";
|
||||
import { experimental_AstroContainer } from "astro/container";
|
||||
import type { APIRoute, SSRLoadedRenderer } from 'astro';
|
||||
import { experimental_AstroContainer } from 'astro/container';
|
||||
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) => {
|
||||
const container = await experimental_AstroContainer.create();
|
||||
container.addServerRenderer({ renderer });
|
||||
return await container.renderToResponse(Component);
|
||||
}
|
||||
return await container.renderToResponse(Component, {
|
||||
skipClientDirectives: true,
|
||||
});
|
||||
};
|
||||
|
|
Loading…
Add table
Reference in a new issue