1- import { forwardRef , memo , useCallback , useEffect , useState } from 'react' ;
1+ import { forwardRef , memo , useCallback , useEffect , useLayoutEffect , useState } from 'react' ;
22import { useTranslation } from 'react-i18next' ;
33import { Element } from 'slate' ;
44import { useReadOnly , useSlate } from 'slate-react' ;
@@ -12,12 +12,14 @@ export const Outline = memo(
1212 const [ root , setRoot ] = useState < HeadingNode [ ] > ( [ ] ) ;
1313 const { t } = useTranslation ( ) ;
1414 const readOnly = useReadOnly ( ) || editor . isElementReadOnly ( node as unknown as Element ) ;
15+ const [ isReady , setIsReady ] = useState ( false ) ;
1516
1617 useEffect ( ( ) => {
18+ if ( ! isReady ) return ;
1719 const root = nestHeadings ( extractHeadings ( editor , node . data . depth || 6 ) ) ;
1820
1921 setRoot ( root ) ;
20- } , [ editor , node . data . depth , editor . children ] ) ;
22+ } , [ editor , node . data . depth , editor . children , isReady ] ) ;
2123
2224 const jumpToHeading = useCallback ( ( heading : HeadingNode ) => {
2325 const id = `heading-${ heading . blockId } ` ;
@@ -62,6 +64,12 @@ export const Outline = memo(
6264 [ jumpToHeading ]
6365 ) ;
6466
67+ useLayoutEffect ( ( ) => {
68+ setTimeout ( ( ) => {
69+ setIsReady ( true ) ;
70+ } , 1000 ) ;
71+ } , [ ] ) ;
72+
6573 return (
6674 < div
6775 { ...attributes }
@@ -72,7 +80,7 @@ export const Outline = memo(
7280 < div className = { 'absolute left-0 top-0 select-none caret-transparent' } > { children } </ div >
7381 < div contentEditable = { false } className = { `flex w-full select-none flex-col` } >
7482 < div className = { 'text-md my-2 font-bold' } > { t ( 'document.outlineBlock.placeholder' ) } </ div >
75- { root . map ( renderHeading ) }
83+ { isReady && root . map ( renderHeading ) }
7684 </ div >
7785 </ div >
7886 ) ;
0 commit comments