perf(ui): skip pacing for static markdown
This commit is contained in:
@@ -230,6 +230,16 @@ function createPacedValue(getValue: () => string, live?: () => boolean) {
|
||||
return value
|
||||
}
|
||||
|
||||
function PacedMarkdown(props: { text: () => string; cacheKey: string; streaming: () => boolean }) {
|
||||
const value = createPacedValue(props.text, props.streaming)
|
||||
|
||||
return (
|
||||
<Show when={value()}>
|
||||
<Markdown text={value()} cacheKey={props.cacheKey} streaming={props.streaming()} />
|
||||
</Show>
|
||||
)
|
||||
}
|
||||
|
||||
function relativizeProjectPath(path: string, directory?: string) {
|
||||
if (!path) return ""
|
||||
if (!directory) return path
|
||||
@@ -1373,8 +1383,7 @@ PART_MAPPING["text"] = function TextPartDisplay(props) {
|
||||
const streaming = createMemo(
|
||||
() => props.message.role === "assistant" && typeof (props.message as AssistantMessage).time.completed !== "number",
|
||||
)
|
||||
const displayText = () => (part().text ?? "").trim()
|
||||
const throttledText = createPacedValue(displayText, streaming)
|
||||
const text = () => (part().text ?? "").trim()
|
||||
const isLastTextPart = createMemo(() => {
|
||||
const last = (data.store.part?.[props.message.id] ?? [])
|
||||
.filter((item): item is TextPart => item?.type === "text" && !!item.text?.trim())
|
||||
@@ -1390,7 +1399,7 @@ PART_MAPPING["text"] = function TextPartDisplay(props) {
|
||||
const [copied, setCopied] = createSignal(false)
|
||||
|
||||
const handleCopy = async () => {
|
||||
const content = displayText()
|
||||
const content = text()
|
||||
if (!content) return
|
||||
await navigator.clipboard.writeText(content)
|
||||
setCopied(true)
|
||||
@@ -1398,10 +1407,12 @@ PART_MAPPING["text"] = function TextPartDisplay(props) {
|
||||
}
|
||||
|
||||
return (
|
||||
<Show when={throttledText()}>
|
||||
<Show when={text()}>
|
||||
<div data-component="text-part">
|
||||
<div data-slot="text-part-body">
|
||||
<Markdown text={throttledText()} cacheKey={part().id} streaming={streaming()} />
|
||||
<Show when={streaming()} fallback={<Markdown text={text()} cacheKey={part().id} streaming={false} />}>
|
||||
<PacedMarkdown text={text} cacheKey={part().id} streaming={streaming} />
|
||||
</Show>
|
||||
</div>
|
||||
<Show when={showCopy()}>
|
||||
<div data-slot="text-part-copy-wrapper" data-interrupted={interrupted() ? "" : undefined}>
|
||||
@@ -1437,12 +1448,13 @@ PART_MAPPING["reasoning"] = function ReasoningPartDisplay(props) {
|
||||
() => props.message.role === "assistant" && typeof (props.message as AssistantMessage).time.completed !== "number",
|
||||
)
|
||||
const text = () => part().text.trim()
|
||||
const throttledText = createPacedValue(text, streaming)
|
||||
|
||||
return (
|
||||
<Show when={throttledText()}>
|
||||
<Show when={text()}>
|
||||
<div data-component="reasoning-part">
|
||||
<Markdown text={throttledText()} cacheKey={part().id} streaming={streaming()} />
|
||||
<Show when={streaming()} fallback={<Markdown text={text()} cacheKey={part().id} streaming={false} />}>
|
||||
<PacedMarkdown text={text} cacheKey={part().id} streaming={streaming} />
|
||||
</Show>
|
||||
</div>
|
||||
</Show>
|
||||
)
|
||||
|
||||
@@ -343,14 +343,12 @@ export function SessionTurn(
|
||||
})
|
||||
const assistantDerived = createMemo(() => {
|
||||
let visible = 0
|
||||
let tail: "text" | "other" | undefined
|
||||
let reason: string | undefined
|
||||
const show = showReasoningSummaries()
|
||||
for (const message of assistantMessages()) {
|
||||
for (const part of list(data.store.part?.[message.id], emptyParts)) {
|
||||
if (partState(part, show) === "visible") {
|
||||
visible++
|
||||
tail = part.type === "text" ? "text" : "other"
|
||||
}
|
||||
if (part.type === "reasoning" && part.text) {
|
||||
const h = heading(part.text)
|
||||
@@ -358,10 +356,9 @@ export function SessionTurn(
|
||||
}
|
||||
}
|
||||
}
|
||||
return { visible, tail, reason }
|
||||
return { visible, reason }
|
||||
})
|
||||
const assistantVisible = createMemo(() => assistantDerived().visible)
|
||||
const assistantTailVisible = createMemo(() => assistantDerived().tail)
|
||||
const reasoningHeading = createMemo(() => assistantDerived().reason)
|
||||
const showThinking = createMemo(() => {
|
||||
if (!working() || !!error()) return false
|
||||
|
||||
Reference in New Issue
Block a user