44 * Displays document heading structure as a tree.
55 */
66
7- import { useState , useMemo , useRef } from "react" ;
7+ import { useState , useDeferredValue , useMemo , useRef } from "react" ;
88import { ChevronRight , ChevronDown } from "lucide-react" ;
99import { emit } from "@tauri-apps/api/event" ;
1010import { useUIStore } from "@/stores/uiStore" ;
@@ -93,16 +93,17 @@ const MAX_OUTLINE_ITEMS = 100; // Limit total visible items
9393
9494export function OutlineView ( ) {
9595 const content = useDocumentContent ( ) ;
96+ const deferredContent = useDeferredValue ( content ) ;
9697 const activeHeadingIndex = useUIStore ( ( state ) => state . activeHeadingLine ) ;
9798
9899 // Check if document is too large (used after hooks)
99- const isTooLarge = content . length > MAX_CONTENT_FOR_OUTLINE ;
100+ const isTooLarge = deferredContent . length > MAX_CONTENT_FOR_OUTLINE ;
100101
101102 // Create a stable key based only on heading lines.
102103 // This prevents re-extraction when typing in non-heading content.
103104 const headingLinesKey = useMemo (
104- ( ) => ( isTooLarge ? "" : getHeadingLinesKey ( content ) ) ,
105- [ content , isTooLarge ]
105+ ( ) => ( isTooLarge ? "" : getHeadingLinesKey ( deferredContent ) ) ,
106+ [ deferredContent , isTooLarge ]
106107 ) ;
107108
108109 // Cache previous headings to maintain referential stability
@@ -116,12 +117,12 @@ export function OutlineView() {
116117 return prevHeadingsRef . current ;
117118 }
118119 perfStart ( "OutlineView:extractHeadings" ) ;
119- const newHeadings = extractHeadings ( content ) ;
120+ const newHeadings = extractHeadings ( deferredContent ) ;
120121 perfEnd ( "OutlineView:extractHeadings" , { count : newHeadings . length } ) ;
121122 prevHeadingsRef . current = newHeadings ;
122123 prevKeyRef . current = headingLinesKey ;
123124 return newHeadings ;
124- } , [ headingLinesKey , content , isTooLarge ] ) ;
125+ } , [ headingLinesKey , deferredContent , isTooLarge ] ) ;
125126
126127 const tree = useMemo ( ( ) => {
127128 if ( isTooLarge ) return [ ] ;
0 commit comments