share: speed up share loads (#16165)

This commit is contained in:
Shoubhit Dash
2026-03-06 18:19:15 +05:30
committed by GitHub
parent eeeb21ff86
commit 1d9dcd2a27
7 changed files with 167 additions and 145 deletions

View File

@@ -44,6 +44,19 @@ function sanitize(html: string) {
return DOMPurify.sanitize(html, config)
}
function escape(text: string) {
return text
.replace(/&/g, "&")
.replace(/</g, "&lt;")
.replace(/>/g, "&gt;")
.replace(/\"/g, "&quot;")
.replace(/'/g, "&#39;")
}
function fallback(markdown: string) {
return escape(markdown).replace(/\r\n?/g, "\n").replace(/\n/g, "<br>")
}
type CopyLabels = {
copy: string
copied: string
@@ -237,7 +250,7 @@ export function Markdown(
const [html] = createResource(
() => local.text,
async (markdown) => {
if (isServer) return ""
if (isServer) return fallback(markdown)
const hash = checksum(markdown)
const key = local.cacheKey ?? hash
@@ -255,7 +268,7 @@ export function Markdown(
if (key && hash) touch(key, { hash, html: safe })
return safe
},
{ initialValue: "" },
{ initialValue: isServer ? fallback(local.text) : "" },
)
let copySetupTimer: ReturnType<typeof setTimeout> | undefined