@@ -860,6 +860,7 @@ const mermaidColorsFromTheme = (theme: Theme) => ({
860860
861861const useDecorateContext = (
862862 currentTheme : Theme ,
863+ deferCodeLineNumberSync : boolean ,
863864 onPreviewLoopback ?: ( url : string ) => void ,
864865) : DecorateContext => {
865866 const { t } = useI18n ( ) ;
@@ -895,8 +896,8 @@ const useDecorateContext = (
895896 return { } ;
896897 }
897898 } ) ;
898- return { labels, codeBlockLineWrap, onToggleCodeBlockLineWrap : toggleCodeBlockLineWrap , renderMermaid, onPreviewLoopback } ;
899- } , [ currentTheme , labels , codeBlockLineWrap , toggleCodeBlockLineWrap , onPreviewLoopback ] ) ;
899+ return { labels, codeBlockLineWrap, deferCodeLineNumberSync , onToggleCodeBlockLineWrap : toggleCodeBlockLineWrap , renderMermaid, onPreviewLoopback } ;
900+ } , [ currentTheme , labels , codeBlockLineWrap , deferCodeLineNumberSync , toggleCodeBlockLineWrap , onPreviewLoopback ] ) ;
900901} ;
901902
902903// Runs the async render pipeline into the container and keeps a stable
@@ -984,7 +985,9 @@ const useMorphdomMarkdown = ({
984985 existing [ i ] ?. remove ( ) ;
985986 }
986987
987- scheduleMarkdownCodeLineNumberSync ( target ) ;
988+ if ( ! ctx . deferCodeLineNumberSync ) {
989+ scheduleMarkdownCodeLineNumberSync ( target ) ;
990+ }
988991 } ) ;
989992
990993 return ( ) => {
@@ -1012,8 +1015,9 @@ const useMorphdomMarkdown = ({
10121015 const container = containerRef . current ;
10131016 const target = container ?. querySelector < HTMLElement > ( '[data-markdown-content]' ) ?? container ;
10141017 if ( ! target ) return ;
1018+ if ( ctx . deferCodeLineNumberSync ) return ;
10151019 applyMarkdownCodeBlockWrapState ( target , ctx . codeBlockLineWrap , ctx . labels ) ;
1016- } , [ containerRef , ctx . codeBlockLineWrap , ctx . labels ] ) ;
1020+ } , [ containerRef , ctx . codeBlockLineWrap , ctx . deferCodeLineNumberSync , ctx . labels ] ) ;
10171021
10181022 React . useEffect ( ( ) => {
10191023 const container = containerRef . current ;
@@ -1081,7 +1085,7 @@ const MarkdownRendererImpl: React.FC<MarkdownRendererProps> = ({
10811085 useExternalLinkInteractions ( { containerRef } ) ;
10821086
10831087 const syntaxVars = React . useMemo ( ( ) => getMarkdownSyntaxVars ( currentTheme ) , [ currentTheme ] ) ;
1084- const ctx = useDecorateContext ( currentTheme , effectiveDirectory ? handlePreviewLoopback : undefined ) ;
1088+ const ctx = useDecorateContext ( currentTheme , live , effectiveDirectory ? handlePreviewLoopback : undefined ) ;
10851089 const cacheKey = `markdown-${ part ?. id ? `part-${ part . id } ` : `message-${ messageId } ` } ` ;
10861090
10871091 useMorphdomMarkdown ( { containerRef, text : pacedText , streaming : live , cacheKey, syntaxVars, ctx } ) ;
@@ -1164,7 +1168,7 @@ const SimpleMarkdownRendererImpl: React.FC<{
11641168 useExternalLinkInteractions ( { containerRef, enabled : ! disableLinkSafety } ) ;
11651169
11661170 const syntaxVars = React . useMemo ( ( ) => getMarkdownSyntaxVars ( currentTheme ) , [ currentTheme ] ) ;
1167- const ctx = useDecorateContext ( currentTheme ) ;
1171+ const ctx = useDecorateContext ( currentTheme , false ) ;
11681172
11691173 useMorphdomMarkdown ( {
11701174 containerRef,
0 commit comments