mirror of
https://github.com/sst/opencode.git
synced 2025-07-08 00:25:00 +00:00
docs: share handle slow loading pages
This commit is contained in:
parent
5a0910ea79
commit
3e2a0c7281
2 changed files with 959 additions and 991 deletions
|
@ -1,8 +1,6 @@
|
||||||
import {
|
import {
|
||||||
type JSX,
|
type JSX,
|
||||||
onCleanup,
|
|
||||||
splitProps,
|
splitProps,
|
||||||
createEffect,
|
|
||||||
createResource,
|
createResource,
|
||||||
} from "solid-js"
|
} from "solid-js"
|
||||||
import { codeToHtml } from "shiki"
|
import { codeToHtml } from "shiki"
|
||||||
|
@ -12,15 +10,15 @@ import { transformerNotationDiff } from "@shikijs/transformers"
|
||||||
interface CodeBlockProps extends JSX.HTMLAttributes<HTMLDivElement> {
|
interface CodeBlockProps extends JSX.HTMLAttributes<HTMLDivElement> {
|
||||||
code: string
|
code: string
|
||||||
lang?: string
|
lang?: string
|
||||||
onRendered?: () => void
|
|
||||||
}
|
}
|
||||||
function CodeBlock(props: CodeBlockProps) {
|
function CodeBlock(props: CodeBlockProps) {
|
||||||
const [local, rest] = splitProps(props, ["code", "lang", "onRendered"])
|
const [local, rest] = splitProps(props, ["code", "lang"])
|
||||||
let containerRef!: HTMLDivElement
|
|
||||||
|
|
||||||
const [html] = createResource(
|
const [html] = createResource(
|
||||||
() => [local.code, local.lang],
|
() => [local.code, local.lang],
|
||||||
async ([code, lang]) => {
|
async ([code, lang]) => {
|
||||||
|
// TODO: For testing delays
|
||||||
|
// await new Promise((resolve) => setTimeout(resolve, 3000))
|
||||||
return (await codeToHtml(code || "", {
|
return (await codeToHtml(code || "", {
|
||||||
lang: lang || "text",
|
lang: lang || "text",
|
||||||
themes: {
|
themes: {
|
||||||
|
@ -32,25 +30,7 @@ function CodeBlock(props: CodeBlockProps) {
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
onCleanup(() => {
|
return <div innerHTML={html()} class={styles.codeblock} {...rest}></div >
|
||||||
if (containerRef) containerRef.innerHTML = ""
|
|
||||||
})
|
|
||||||
|
|
||||||
createEffect(() => {
|
|
||||||
if (html() && containerRef) {
|
|
||||||
containerRef.innerHTML = html() as string
|
|
||||||
|
|
||||||
local.onRendered?.()
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
return (
|
|
||||||
<>
|
|
||||||
{html() ? (
|
|
||||||
<div ref={containerRef} class={styles.codeblock} {...rest}></div>
|
|
||||||
) : null}
|
|
||||||
</>
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export default CodeBlock
|
export default CodeBlock
|
||||||
|
|
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue