From 72cf687d494aad11fc2e679031b09852a4403afe Mon Sep 17 00:00:00 2001 From: Alessio Gravili Date: Thu, 21 Nov 2024 17:57:08 -0700 Subject: [PATCH] fix(richtext-lexical): error when changing block collapsed state in rare cases --- .../src/features/blocks/client/component/index.tsx | 2 +- packages/richtext-lexical/src/utilities/buildInitialState.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/richtext-lexical/src/features/blocks/client/component/index.tsx b/packages/richtext-lexical/src/features/blocks/client/component/index.tsx index f91e922b8e0..fda48f9dd21 100644 --- a/packages/richtext-lexical/src/features/blocks/client/component/index.tsx +++ b/packages/richtext-lexical/src/features/blocks/client/component/index.tsx @@ -259,7 +259,7 @@ export const BlockComponent: React.FC = (props) => { (changedCollapsed: boolean) => { void getDocPreferences().then((currentDocPreferences) => { const currentFieldPreferences = - currentDocPreferences?.fields[parentLexicalRichTextField.name] + currentDocPreferences?.fields?.[parentLexicalRichTextField.name] const collapsedArray = currentFieldPreferences?.collapsed diff --git a/packages/richtext-lexical/src/utilities/buildInitialState.ts b/packages/richtext-lexical/src/utilities/buildInitialState.ts index 72e856b160e..66a529f9564 100644 --- a/packages/richtext-lexical/src/utilities/buildInitialState.ts +++ b/packages/richtext-lexical/src/utilities/buildInitialState.ts @@ -88,7 +88,7 @@ export async function buildInitialState({ initialState[id].formState = formStateResult if (node.type === 'block') { - const currentFieldPreferences = context.preferences?.fields[context.field.name] + const currentFieldPreferences = context.preferences?.fields?.[context.field.name] const collapsedArray = currentFieldPreferences?.collapsed if (collapsedArray && collapsedArray.includes(id)) { initialState[id].collapsed = true