-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(container): client hydration (#11486)
* fix: prevent client hydration when rendering via Container API * revert change that is not needed * skip client directives via option * reword changeset * Fix types of react server.d.ts * add new API --------- Co-authored-by: Matthew Phillips <matthew@skypack.dev>
- Loading branch information
Showing
8 changed files
with
99 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
--- | ||
'astro': patch | ||
--- | ||
|
||
Adds a new function called `addClientRenderer` to the Container API. | ||
|
||
This function should be used when rendering components using the `client:*` directives. The `addClientRenderer` API must be used | ||
*after* the use of the `addServerRenderer`: | ||
|
||
```js | ||
const container = await experimental_AstroContainer.create(); | ||
container.addServerRenderer({renderer}); | ||
container.addClientRenderer({name: '@astrojs/react', entrypoint: '@astrojs/react/client.js'}); | ||
const response = await container.renderToResponse(Component); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
packages/astro/test/fixtures/container-custom-renderers/src/components/buttonDirective.astro
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
--- | ||
import Button from "./button.jsx" | ||
--- | ||
|
||
<div> | ||
<p>Button not rendered</p> | ||
<Button client:idle/> | ||
</div> |
11 changes: 11 additions & 0 deletions
11
packages/astro/test/fixtures/container-custom-renderers/src/pages/button-directive.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
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'; | ||
|
||
export const GET: APIRoute = async (ctx) => { | ||
const container = await experimental_AstroContainer.create(); | ||
container.addServerRenderer({ renderer }); | ||
container.addClientRenderer({ name: '@astrojs/react', entrypoint: '@astrojs/react/client.js' }); | ||
return await container.renderToResponse(Component); | ||
}; |
2 changes: 1 addition & 1 deletion
2
packages/astro/test/fixtures/container-custom-renderers/src/pages/react.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
import type { NamedSSRLoadedRendererValue } from 'astro'; | ||
export default NamedSSRLoadedRendererValue; | ||
|
||
declare const renderer: NamedSSRLoadedRendererValue; | ||
export default renderer; |