Skip to content

Commit

Permalink
fix: toc not responsive in dev mode
Browse files Browse the repository at this point in the history
Signed-off-by: Innei <i@innei.in>
  • Loading branch information
Innei committed Sep 4, 2024
1 parent 35da266 commit ee1894c
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/renderer/src/components/ui/markdown/Markdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,15 @@ export const HTML = <A extends keyof JSX.IntrinsicElements = "div">(
) => {
const { children, renderInlineStyle, as = "div", accessory, ...rest } = props
const [remarkOptions, setRemarkOptions] = useState({ renderInlineStyle })
const [shouldForceReMountKey, setShouldForceReMountKey] = useState(0)

useEffect(() => {
setRemarkOptions({ renderInlineStyle })
setRemarkOptions((options) => {
if (renderInlineStyle === options.renderInlineStyle) return options

setShouldForceReMountKey((key) => key + 1)
return { ...options, renderInlineStyle }
})
}, [renderInlineStyle])

const [refElement, setRefElement] = useState<HTMLElement | null>(null)
Expand All @@ -67,7 +73,7 @@ export const HTML = <A extends keyof JSX.IntrinsicElements = "div">(
return (
<MarkdownRenderContainerRefContext.Provider value={refElement}>
{createElement(as, { ...rest, ref: setRefElement }, markdownElement)}
{accessory && <Fragment key={children}>{accessory}</Fragment>}
{accessory && <Fragment key={shouldForceReMountKey}>{accessory}</Fragment>}
</MarkdownRenderContainerRefContext.Provider>
)
}

0 comments on commit ee1894c

Please sign in to comment.