summaryrefslogtreecommitdiff
path: root/packages/renderers/renderer-preact/static-html.js
diff options
context:
space:
mode:
authorGravatar Nate Moore <natemoo-re@users.noreply.github.com> 2021-05-28 17:19:40 -0500
committerGravatar GitHub <noreply@github.com> 2021-05-28 17:19:40 -0500
commit3df41d23089142ea9b0895110f28a2d4a43a9059 (patch)
tree4b590cdb86e647b479730f5b4f83ee7c147aaf69 /packages/renderers/renderer-preact/static-html.js
parent630c36f3516bb500ca6a4bfe84c972b1093b8177 (diff)
downloadastro-3df41d23089142ea9b0895110f28a2d4a43a9059.tar.gz
astro-3df41d23089142ea9b0895110f28a2d4a43a9059.tar.zst
astro-3df41d23089142ea9b0895110f28a2d4a43a9059.zip
Bugbash! (#263)
* fix(vscode): Markdown frontmatter should use TSX, not YAML * test: add test for #153 * chore: bump deps * chore: update to use @astrojs scope * fix: Markdown parse error when only child is `{expression}` * fix: update renderer edge cases * fix: failing test * fix: update renderer
Diffstat (limited to 'packages/renderers/renderer-preact/static-html.js')
-rw-r--r--packages/renderers/renderer-preact/static-html.js24
1 files changed, 24 insertions, 0 deletions
diff --git a/packages/renderers/renderer-preact/static-html.js b/packages/renderers/renderer-preact/static-html.js
new file mode 100644
index 000000000..5a31a68af
--- /dev/null
+++ b/packages/renderers/renderer-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 }) => {
+ if (!value) return null;
+ return h('astro-fragment', { 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;
/td>1-0/+1 2022-02-03[ci] yarn formatGravatar FredKSchott 2-3/+85 2022-02-02Handles all http error code file names the same as 404 files. (#2525)Gravatar Zade Viggers 2-4/+7 2022-02-02fix(sitemap): remove debug if sitemap disabled (#2514)Gravatar Mark Pinero 1-2/+2 2022-02-02[ci] update lockfile (#2515)Gravatar Fred K. Schott 1-276/+279 2022-02-02[ci] yarn formatGravatar matthewp 1-8/+8 2022-02-02[ci] release (next) (#2523)astro@0.23.0-next.1Gravatar github-actions[bot] 28-34/+41 2022-02-02[ci] yarn formatGravatar matthewp 2-17/+29 2022-02-02Fix support for scss in static build (#2522)Gravatar Matthew Phillips 6-20/+114 2022-02-02[ci] collect statsGravatar FredKSchott 1-0/+1 2022-02-01[ci] yarn formatGravatar matthewp 2-12/+12 2022-02-01[ci] release (next) (#2492)astro@0.23.0-next.0@astrojs/test-static-build-pkg@0.0.2@astrojs/markdown-remark@0.6.1-next.0Gravatar github-actions[bot] 31-43/+93 2022-02-01[ci] collect statsGravatar FredKSchott 1-0/+1 2022-01-31update congratsbot format againGravatar Fred K. Schott 1-1/+1 2022-01-31update congratsbot againGravatar Fred K. Schott 1-1/+1 2022-01-31Remove SVG animation on GitHub/NPM (#2512)Gravatar Nate Moore 1-21/+0 2022-01-31[ci] yarn formatGravatar natemoo-re 2-4/+6 2022-01-31Add Shiki as an alternative to Prism (#2497)Gravatar Juan Martín Seery 26-9/+356 2022-01-31Deprecate unescaped HTML inside of expressions (#2489)Gravatar Nate Moore 9-31/+74