From f9e6458287528f6cb309440c0526ed8fd4dbdf31 Mon Sep 17 00:00:00 2001 From: Alex Patterson Date: Fri, 16 Oct 2026 13:40:15 -0400 Subject: [PATCH] feat(portable-text): support interactive SVG/JS htmlBlocks in Astro draft preview and Sanity Studio --- apps/sanity/components/HTMLPreview.tsx | 38 +++++++++++++++---- .../src/components/portable-text/PtHtml.astro | 15 ++++---- 2 files changed, 38 insertions(+), 15 deletions(-) diff --git a/apps/sanity/components/HTMLPreview.tsx b/apps/sanity/components/HTMLPreview.tsx index 5d5f0f131..3e408d84f 100644 --- a/apps/sanity/components/HTMLPreview.tsx +++ b/apps/sanity/components/HTMLPreview.tsx @@ -1,13 +1,37 @@ -import React from "react"; -// TODO: Add stronger typing -const HTMLPreview = (props: any) => { +import React, { useEffect, useRef } from "react"; + +const STEGA_REGEX = /[\u200B-\u200F\u202A-\u202E\u2060-\u206F\uFEFF]|\uDB40[\uDC20-\uDC7F]/g; + +interface HTMLPreviewProps { + html?: string; +} + +const HTMLPreview = (props: HTMLPreviewProps) => { const { html } = props; - if (!html) { + const containerRef = useRef(null); + const cleanHtml = typeof html === "string" ? html.replace(STEGA_REGEX, "") : ""; + + useEffect(() => { + const container = containerRef.current; + if (!container || !cleanHtml) return; + + // Re-execute any inline