diff options
author | 2021-05-26 13:30:22 -0500 | |
---|---|---|
committer | 2021-05-26 13:30:22 -0500 | |
commit | 643c880f280c3f571a022b6f4d40b6d5a0e911b5 (patch) | |
tree | 787fcf4e12d20166ee1bd8c18ba38d6e12c499e6 /packages/renderers/react/static-html.js | |
parent | 31e52c2e4c138fe6608f60e8f43647c664b31d6a (diff) | |
download | astro-643c880f280c3f571a022b6f4d40b6d5a0e911b5.tar.gz astro-643c880f280c3f571a022b6f4d40b6d5a0e911b5.tar.zst astro-643c880f280c3f571a022b6f4d40b6d5a0e911b5.zip |
Renderer plugins (#231)
* refactor: pluggable renderers
* refactor: cache renderer per component
* docs: update comments on snowpack plugin `transform` method
* docs: add comments to renderer plugins
* refactor: convert components to Map
* fix: pass children through to astro __render
* refactor: move Components/ComponentInfo to shared types
* refactor: remove `gatherRuntimes` step, just scan output for imports
* refactor: update isComponentTag logic
* chore: move dependencies to renderers
* fix: cross-platform transform injection
* feat: defer renderer to react, fallback to preact
* fix: use double quotes in generated script
* test: fix failing children tests
* test: add workspaceRoot to all tests
* fix: pass props to renderer check
* chore: add test:core script back for convenience
* chore: remove unused external
* chore: rename renderers
* chore: add astring, estree-util-value-to-estree
* chore: render-component => __astro_component
* refactor: split hydrate logic to own file
* refactor: use `astro-fragment` rather than `div`
* chore: remove unused hooks
* chore: delete unused file
* chore: add changesets
* fix: Astro renderer should be async
* fix: remove <astro-fragment> for static content
* test: fix failing test
* chore: normalize config interface
* feat: allow renderers to inject a snowpackPlugin
* fix: resolve import URL before using dynamic import
* refactor: update renderers to use separate /server entrypoint
* refactor: update server renderer interface
* fix: get renderers working again
* test: debug failing test
* test: better debug
* test: better debug
* test: remove debug
* fix: support esm and cjs packages via "resolve"
* refactor: split hydrate functions into individual files
* fix: dependency resolution relative to projectRoot
* fix: @snowpack/plugin-postcss needs to be hoisted
* fix: do not test prettier-plugin-astro as it's not ready for primetime
Diffstat (limited to 'packages/renderers/react/static-html.js')
-rw-r--r-- | packages/renderers/react/static-html.js | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/packages/renderers/react/static-html.js b/packages/renderers/react/static-html.js new file mode 100644 index 000000000..a50068605 --- /dev/null +++ b/packages/renderers/react/static-html.js @@ -0,0 +1,24 @@ +import { createElement as h } from 'react'; + +/** + * Astro passes `children` as a string of HTML, so we need + * a wrapper `div` to render that content as VNodes. + * + * As a bonus, we can signal to React that this subtree is + * entirely static and will never change via `shouldComponentUpdate`. + */ +const StaticHtml = ({ value }) => { + if (!value) return null; + return h('astro-fragment', { suppressHydrationWarning: true, dangerouslySetInnerHTML: { __html: value }}); +} + +/** + * This tells React to opt-out of re-rendering this subtree, + * In addition to being a performance optimization, + * this also allows other frameworks to attach to `children`. + * + * See https://preactjs.com/guide/v8/external-dom-mutations + */ +StaticHtml.shouldComponentUpdate = () => false; + +export default StaticHtml; |