Skip to content

Commit 60160e2

Browse files
committed
refactor(JSafeHtml): use createVNode
This allows us to directly insert the HTML without adding any extra DOM element Sources: * https://discord.com/channels/325477692906536972/568037134968160256/1254047268441690182 * https://discord.com/channels/325477692906536972/568037134968160256/1254210953415753738 createVnode is internally used by createStaticVNode: https://github.com/vuejs/core/blob/edf263847eddc910f4d2de68287d84b8c66c3860/packages/runtime-core/src/vnode.ts#L742 However, it requires a 2nd parameter, which is the number of nodes we want to insert, which is unknown/not trivial to calculate at runtime. According to the comment in the function, that's only needed for hydration (SSR), so it should be safe for us as we're SPA only. Here's a playground: https://play.vuejs.org/#__PROD__eNp9UsFu2zAM/RVBGFAH9Zxs3S6eHaAbCqw9dEUz7GRgVW06divLgkRnGQL/eym5dhyg6E0i3yMfyXfgl1pHuw54zBObm1ojs4CdXmeqbnRrkB2YrYSU7b97KEOWt43uEArWs9K0DTsj7tmEvdmIEn5iI1+T0XKKuCYEzFTeKotUp1MIhqWz6sFqkSnqfu0yOyGDYMHS9QiNKNLB+XnIPq1Wq8W3sVLl2qWTsFfSQ/K4/nA4ofbJ8nH9QC2S5TApzUgfhEZLgUA/xpLjBLEvvKRwspxheMjRUuey3kZPtlW0uINjZtwpqCWYXxprUpbxmPmMy/kRb3wMTQfhGM8ryJ/fiD/ZvYtl/M6ApWVAxqccCrMFHNJXm1vY03tKNm3RSUK/k7wH28rOaRxg3ztVkOwZzqu99iet1fa3vdojKDsO5YQ6ZO/xGafD/nhn9KPci+iL52Wqpy2eOGNmPynUNiUaVZmbcIMC65wMaIAO8ee2LSBk1YkNyRJEcAcvRQ7szrTaDjrcKWNm0dA4hCIFo3uO905ZoB0jHojeRVUwaxeMEmhfUNYKipB5RuTKL0IS+Qz/41mM9c6mmTqOWqsKTI2XiMZSx1JICx4Cez8nFRadnMmi5MyutLa/OzDuFLSxi+hrtPoopK5E9Jn3L3UsSes= Signed-off-by: Fernando Fernández <[email protected]>
1 parent 6cf9bbd commit 60160e2

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

frontend/src/components/lib/JSafeHtml.vue

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
<script lang="ts">
2-
import { h } from 'vue';
2+
import { Static, createVNode, h } from 'vue';
33
import { sanitizeHtml } from '@/utils/html';
44
55
interface Props {
66
html: string;
77
markdown?: boolean;
88
}
99
10-
const JSafeHtml = (props: Props) => h('j-safe-html', { innerHTML: sanitizeHtml(props.html, props.markdown) });
10+
const JSafeHtml = (props: Props) => h(
11+
createVNode(Static, undefined, sanitizeHtml(props.html, Boolean(props.markdown))),
12+
{ key: props.html }
13+
);
1114
1215
JSafeHtml.inheritAttrs = false;
1316

0 commit comments

Comments
 (0)