@@ -5,8 +5,6 @@ import {
55 createLowlight,
66 type Element,
77 type ElementContent,
8- type HighlightStream,
9- type StreamUpdate,
108 } from "lextide";
119
1210 const lowlight = createLowlight(all);
@@ -99,7 +97,6 @@ interface SyntaxHighlightState {
9997 children: HighlightNode[];
10098 lastContent: string;
10199 lastNode: ContainerNode | null;
102- stream: HighlightStream;
103100 theme: ResolvedSyntaxHighlightTheme;
104101 }
105102
@@ -447,62 +444,20 @@ function findState(
447444 }
448445 }
449446
450- let best: SyntaxHighlightState | undefined;
451- let bestLength = -1;
452-
453- for (let i = states.length - 1; i >= 0; i--) {
454- const state = requiredAt(states, i, "syntax highlight state");
455- if (!content.startsWith(state.lastContent)) {
456- continue;
457- }
458- if (state.lastContent.length > bestLength) {
459- best = state;
460- bestLength = state.lastContent.length;
461- }
462- }
463-
464- return best;
465-}
466-
467-function createStream(language: string): HighlightStream {
468- return lowlight.stream(language, { allowRecalls: true });
447+ return undefined;
469448 }
470449
471450 function createState(
472- language: string,
473451 theme: ResolvedSyntaxHighlightTheme,
474452 ): SyntaxHighlightState {
475453 return {
476454 children: [],
477455 lastContent: "",
478456 lastNode: null,
479- stream: createStream(language),
480457 theme,
481458 };
482459 }
483460
484-function applyStreamUpdate(
485- children: HighlightNode[],
486- update: StreamUpdate,
487-): void {
488- const nextLength = Math.max(0, children.length - update.recall);
489- children.length = nextLength;
490- children.push(...update.stable, ...update.unstable);
491-}
492-
493-function resetState(
494- state: SyntaxHighlightState,
495- language: string,
496- content: string,
497-): void {
498- state.children = [];
499- state.stream = createStream(language);
500-
501- if (content.length > 0) {
502- applyStreamUpdate(state.children, state.stream.write(content));
503- }
504-}
505-
506461 function pushRun(
507462 line: HighlightRun[],
508463 content: string,
@@ -604,15 +559,7 @@ function updateState(
604559 return;
605560 }
606561
607- if (!content.startsWith(state.lastContent)) {
608- resetState(state, language, content);
609- } else {
610- const chunk = content.slice(state.lastContent.length);
611- if (chunk.length > 0) {
612- applyStreamUpdate(state.children, state.stream.write(chunk));
613- }
614- }
615-
562+ state.children = lowlight.highlight(language, content).children;
616563 state.lastContent = content;
617564 state.lastNode = null;
618565 }
@@ -658,10 +605,9 @@ function renderHighlightedState(state: SyntaxHighlightState): ContainerNode {
658605 /**
659606 * Render syntax-highlighted code as cel-tui primitives.
660607 *
661- * Uses lextide synchronously at the component boundary while keeping a
662- * streaming parser state per language/theme cache entry. Append-only updates
663- * apply lextide's recall/stable/unstable deltas, while non-append edits reset
664- * the stream and replay the full snippet.
608+ * Re-highlights the full snippet whenever the content changes so the final
609+ * output stays deterministic regardless of how streamed chunks were split.
610+ * Repeated renders with identical content reuse the cached rendered tree.
665611 *
666612 * Unknown languages render as plain text. The default theme is terminal-friendly
667613 * and maps lextide's emitted highlight.js classes onto cel's ANSI palette slots
@@ -684,7 +630,7 @@ export function SyntaxHighlight(
684630 }
685631
686632 const key = stateKey(language, theme);
687- const state = findState(key, content) ?? createState(language, theme);
633+ const state = findState(key, content) ?? createState(theme);
688634 updateState(state, language, content);
689635 touchState(key, state);
690636 return renderHighlightedState(state);