diff options
author | 2022-09-22 10:32:42 -0400 | |
---|---|---|
committer | 2022-09-22 10:32:42 -0400 | |
commit | 25a5b9a89aee81c87affca64e1682ebc0c553eaf (patch) | |
tree | d635f1f003f7f3eff5ee6516387f7ba1a4066c62 /packages/integrations/preact/static-html.js | |
parent | d650a1161a0288f8f2d35ae67771279d067920e9 (diff) | |
download | astro-25a5b9a89aee81c87affca64e1682ebc0c553eaf.tar.gz astro-25a5b9a89aee81c87affca64e1682ebc0c553eaf.tar.zst astro-25a5b9a89aee81c87affca64e1682ebc0c553eaf.zip |
Revert preact signals support (#4843)
* Revert "Update preact example to match @astrojs/preact ranges (#4840)"
This reverts commit d650a1161a0288f8f2d35ae67771279d067920e9.
* Revert "[ci] format"
This reverts commit e3c78c5b164c338389c437743ba02a7be64e27fb.
* Revert "Support shared signals in Preact islands (#4763)"
This reverts commit 5e46be54683592773e6dfc2d33825493886114b0.
Diffstat (limited to 'packages/integrations/preact/static-html.js')
-rw-r--r-- | packages/integrations/preact/static-html.js | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/packages/integrations/preact/static-html.js b/packages/integrations/preact/static-html.js new file mode 100644 index 000000000..7e964ef06 --- /dev/null +++ b/packages/integrations/preact/static-html.js @@ -0,0 +1,24 @@ +import { h } from 'preact'; + +/** + * 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 Preact that this subtree is + * entirely static and will never change via `shouldComponentUpdate`. + */ +const StaticHtml = ({ value, name }) => { + if (!value) return null; + return h('astro-slot', { name, dangerouslySetInnerHTML: { __html: value } }); +}; + +/** + * This tells Preact 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; |