From 9565cbda73cf0cc26b8b371ea7c632500fbaf3f8 Mon Sep 17 00:00:00 2001 From: Per-Kristian Nordnes Date: Fri, 12 Aug 2022 09:38:54 +0200 Subject: [PATCH] refactor(portable-text-editor): simplify equality test --- .../src/editor/PortableTextEditor.tsx | 26 +++++-------------- 1 file changed, 7 insertions(+), 19 deletions(-) diff --git a/packages/@sanity/portable-text-editor/src/editor/PortableTextEditor.tsx b/packages/@sanity/portable-text-editor/src/editor/PortableTextEditor.tsx index 5ef09ff705e..8d9cefd96e7 100644 --- a/packages/@sanity/portable-text-editor/src/editor/PortableTextEditor.tsx +++ b/packages/@sanity/portable-text-editor/src/editor/PortableTextEditor.tsx @@ -329,25 +329,13 @@ export class PortableTextEditor extends React.Component< } const isEqualToValue = !(this.props.value || []).some((blk, index) => { - if (this.slateInstance.isTextBlock(blk)) { - const compareBlock = toSlateValue( - [blk], - {portableTextFeatures: this.portableTextFeatures}, - KEY_TO_SLATE_ELEMENT.get(this.slateInstance) - )[0] - if (!isEqual(compareBlock, this.slateInstance.children[index])) { - return true - } - } else { - const slateBlock = this.slateInstance.children[index] - if ( - !slateBlock || - (slateBlock && - 'value' in slateBlock && - !isEqual(blk, {_key: slateBlock._key, _type: slateBlock._type, ...slateBlock.value})) - ) { - return true - } + const compareBlock = toSlateValue( + [blk], + {portableTextFeatures: this.portableTextFeatures}, + KEY_TO_SLATE_ELEMENT.get(this.slateInstance) + )[0] + if (!isEqual(compareBlock, this.slateInstance.children[index])) { + return true } return false })