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:
parent
2eb8a84493
commit
5ebe041f0e
2 changed files with 17 additions and 7 deletions
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
|
@ -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,
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
Loading…
Add table
Reference in a new issue