Skip to content

Commit

Permalink
fix(portable-text-editor): don't memoize isEmpty, lookup directly in …
Browse files Browse the repository at this point in the history
…decorator fn.
  • Loading branch information
skogsmaskin authored and rexxars committed Sep 23, 2022
1 parent f7a817d commit fb9fbe2
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions packages/@sanity/portable-text-editor/src/editor/Editable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {usePortableTextEditor} from './hooks/usePortableTextEditor'
import {PortableTextEditor} from './PortableTextEditor'
import {createWithEditableAPI, createWithHotkeys, createWithInsertData} from './plugins'
import {useForwardedRef} from './hooks/useForwardedRef'
import {usePortableTextEditorValue} from './hooks/usePortableTextEditorValue'

const debug = debugWithName('component:Editable')

Expand Down Expand Up @@ -103,11 +104,6 @@ export const PortableTextEditable = forwardRef(function PortableTextEditable(
slateInstance: slateEditor,
} = portableTextEditor

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

// React/UI-spesific plugins
const withInsertData = useMemo(
() => createWithInsertData(change$, portableTextFeatures, keyGenerator),
Expand Down Expand Up @@ -326,7 +322,7 @@ export const PortableTextEditable = forwardRef(function PortableTextEditable(
}, [portableTextEditor, scrollSelectionIntoView])

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

// The editor
const slateEditable = useMemo(
Expand Down

0 comments on commit fb9fbe2

Please sign in to comment.