Skip to content

Commit

Permalink
fix(portable-text-editor): fix potential re-rendering issue
Browse files Browse the repository at this point in the history
  • Loading branch information
skogsmaskin authored and rexxars committed Sep 23, 2022
1 parent 96771df commit f542cd2
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions packages/@sanity/portable-text-editor/src/editor/Editable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -320,8 +320,13 @@ export const PortableTextEditable = forwardRef(function PortableTextEditable(
}
}, [portableTextEditor, scrollSelectionIntoView])

const isEmpty = useMemo(
() => isEqualToEmptyEditor(slateEditor.children, portableTextFeatures),
[portableTextFeatures, slateEditor.children]
)

const decorate = useCallback(() => {
if (isEqualToEmptyEditor(slateEditor.children, portableTextFeatures)) {
if (isEmpty) {
return [
{
anchor: {
Expand All @@ -337,7 +342,7 @@ export const PortableTextEditable = forwardRef(function PortableTextEditable(
]
}
return EMPTY_DECORATORS
}, [portableTextFeatures, slateEditor.children])
}, [isEmpty])

// The editor
const slateEditable = useMemo(
Expand Down

0 comments on commit f542cd2

Please sign in to comment.