diff options
author | 2021-10-12 14:30:21 -0500 | |
---|---|---|
committer | 2021-10-12 15:30:21 -0400 | |
commit | c7ca17c5ec44dfcd731c7d9e33a1e0d82e3bf520 (patch) | |
tree | 914b23ac84b694cba92e6622d9c122384db923c1 | |
parent | 86ddc8cf38cc0878510738ed9ffed0dfe7fba5dc (diff) | |
download | astro-c7ca17c5ec44dfcd731c7d9e33a1e0d82e3bf520.tar.gz astro-c7ca17c5ec44dfcd731c7d9e33a1e0d82e3bf520.tar.zst astro-c7ca17c5ec44dfcd731c7d9e33a1e0d82e3bf520.zip |
docs: fix knownEntryPoints and add async renderToStaticMarkup example (#1489)
-rw-r--r-- | docs/src/pages/reference/renderer-reference.md | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/docs/src/pages/reference/renderer-reference.md b/docs/src/pages/reference/renderer-reference.md index 15c90a3c2..a4bd63bf4 100644 --- a/docs/src/pages/reference/renderer-reference.md +++ b/docs/src/pages/reference/renderer-reference.md @@ -58,7 +58,7 @@ export default { server: './server.js', // optional, relative path to the server entrypoint snowpackPlugin: '@snowpack/plugin-xxx', // optional, the name of a snowpack plugin to inject snowpackPluginOptions: { example: true }, // optional, any options to be forwarded to the snowpack plugin - knownEntrypoint: ['framework'], // optional, entrypoint modules that will be used by compiled source + knownEntrypoints: ['framework'], // optional, entrypoint modules that will be used by compiled source external: ['dep'], // optional, dependencies that should not be built by snowpack polyfills: ['./shadow-dom-polyfill.js'], // optional, module scripts that should be loaded before client hydration. hydrationPolyfills: ['./hydrate-framework.js'], // optional, polyfills that need to run before hydration ever occurs. @@ -153,7 +153,7 @@ function check(Component, props, childHTML) { `renderToStaticMarkup` is a function that renders a Component to a static string of HTML. There's usually a method exported by frameworks named something like `renderToString`. ```js -import { renderToString } from 'xxx'; +import { h, renderToString } from 'xxx'; function renderToStaticMarkup(Component, props, childHTML) { const html = renderToString(h(Component, { ...props, innerHTML: childHTML })); @@ -177,6 +177,19 @@ function renderToStaticMarkup(Component, props, childHTML) { } ``` +The `renderToStaticMarkup` function also supports `async/await` for render functions that return a `Promise`. + +```js +import { h, renderToString } from 'xxx'; + +async function renderToStaticMarkup(Component, props, childHTML) { + const html = await renderToString( + h(Component, { ...props, innerHTML: childHTML }) + ); + return { html }; +} +``` + ### Client Entrypoint (`client.js`) The client entrypoint of a renderer is responsible for rehydrating static HTML (the result of `renderToStaticMarkup`) back into a fully interactive component. Its `default` export should be a `function` which accepts the host element of the Component, an `astro-root` custom element. @@ -184,7 +197,7 @@ The client entrypoint of a renderer is responsible for rehydrating static HTML ( > If your framework supports non-destructive component hydration (as opposed to a destructive `render` method), be sure to use that! Following your framework's Server Side Rendering (SSR) guide should point you in the right direction. ```js -import { hydrate } from 'xxx'; +import { h, hydrate } from 'xxx'; export default (element) => { return (Component, props, childHTML) => { |