-
-
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.
fix(container): emit components as partials (#12239)
Co-authored-by: Sarah Rainsberger <[email protected]>
- Loading branch information
1 parent
a3d30a6
commit 2b6daa5
Showing
5 changed files
with
60 additions
and
2 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,22 @@ | ||
--- | ||
"astro": patch | ||
--- | ||
|
||
**BREAKING CHANGE to the experimental Container API only** | ||
|
||
Changes the default page rendering behavior of Astro components in containers, and adds a new option `partial: false` to render full Astro pages as before. | ||
|
||
Previously, the Container API was rendering all Astro components as if they were full Astro pages containing `<!DOCTYPE html>` by default. This was not intended, and now by default, all components will render as [page partials](https://docs.astro.build/en/basics/astro-pages/#page-partials): only the contents of the components without a page shell. | ||
|
||
To render the component as a full-fledged Astro page, pass a new option called `partial: false` to `renderToString()` and `renderToResponse()`: | ||
|
||
```js | ||
import { experimental_AstroContainer as AstroContainer } from 'astro/container'; | ||
import Card from "../src/components/Card.astro"; | ||
|
||
const container = AstroContainer.create(); | ||
|
||
await container.renderToString(Card); // the string will not contain `<!DOCTYPE html>` | ||
await container.renderToString(Card, { partial: false }); // the string will contain `<!DOCTYPE html>` | ||
``` | ||
|
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
12 changes: 12 additions & 0 deletions
12
packages/astro/test/fixtures/container-custom-renderers/src/pages/react-as-page.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,12 @@ | ||
import type {APIRoute} from "astro"; | ||
import { experimental_AstroContainer } from "astro/container"; | ||
import renderer from '@astrojs/react/server.js'; | ||
import Component from "../components/button.jsx" | ||
|
||
export const GET: APIRoute = async (ctx) => { | ||
const container = await experimental_AstroContainer.create(); | ||
container.addServerRenderer({ renderer }); | ||
return await container.renderToResponse(Component, { | ||
partial: false | ||
}); | ||
} |