From 10167b27e6a2c46074e19c3b54d0ed589b005270 Mon Sep 17 00:00:00 2001 From: Per-Kristian Nordnes Date: Thu, 4 Aug 2022 23:54:35 +0200 Subject: [PATCH] fix(portable-text-editor): add default value when there are no previous value. --- .../src/editor/plugins/createWithPatches.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/packages/@sanity/portable-text-editor/src/editor/plugins/createWithPatches.ts b/packages/@sanity/portable-text-editor/src/editor/plugins/createWithPatches.ts index 87e8e181306..c3301701284 100644 --- a/packages/@sanity/portable-text-editor/src/editor/plugins/createWithPatches.ts +++ b/packages/@sanity/portable-text-editor/src/editor/plugins/createWithPatches.ts @@ -171,12 +171,14 @@ export function createWithPatches( } if (editorWasEmpty && operation.type !== 'set_selection') { + patches.push(setIfMissing([], [])) patches.push( - setIfMissing([], []), insert( [ fromSlateValue( - previousChildren, + previousChildren.length === 0 + ? [editor.createPlaceholderBlock()] + : previousChildren, portableTextFeatures.types.block.name, KEY_TO_VALUE_ELEMENT.get(editor) )[0], @@ -186,6 +188,7 @@ export function createWithPatches( ) ) } + switch (operation.type) { case 'insert_text': patches = [...patches, ...insertTextPatch(editor, operation, previousChildren)]