From 08148832bd7e27938d7b80ab8210f510162d10cc Mon Sep 17 00:00:00 2001 From: Jonathan Bredo Date: Wed, 1 Jul 2026 03:45:18 +0200 Subject: [PATCH] Enhance serialization with optional chaining and checks Added optional chaining to safely check for class presence and attribute setting. Improved handling of nesting level attribute assignment. --- .../exporters/html/util/serializeBlocksExternalHTML.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/core/src/api/exporters/html/util/serializeBlocksExternalHTML.ts b/packages/core/src/api/exporters/html/util/serializeBlocksExternalHTML.ts index 064a9af6b5..a3245fa5ba 100644 --- a/packages/core/src/api/exporters/html/util/serializeBlocksExternalHTML.ts +++ b/packages/core/src/api/exporters/html/util/serializeBlocksExternalHTML.ts @@ -227,7 +227,8 @@ function serializeBlock< const elementFragment = doc.createDocumentFragment(); - if ((ret.dom as HTMLElement).classList.contains("bn-block-content")) { + // Needs optional chaining for handling
    lists export + if ((ret.dom as HTMLElement).classList?.contains("bn-block-content")) { const blockContentDataAttributes = [ ...attrs, ...Array.from((ret.dom as HTMLElement).attributes), @@ -242,13 +243,12 @@ function serializeBlock< attr.name !== "data-editable", ); - // ret.dom = ret.dom.firstChild! as any; for (const attr of blockContentDataAttributes) { (ret.dom.firstChild! as HTMLElement).setAttribute(attr.name, attr.value); } addAttributesAndRemoveClasses(ret.dom.firstChild! as HTMLElement); - if (nestingLevel > 0) { + if (nestingLevel > 0 && typeof (ret.dom.firstChild as HTMLElement)?.setAttribute === 'function') { (ret.dom.firstChild! as HTMLElement).setAttribute( "data-nesting-level", nestingLevel.toString(), @@ -257,7 +257,7 @@ function serializeBlock< elementFragment.append(...Array.from(ret.dom.childNodes)); } else { elementFragment.append(ret.dom); - if (nestingLevel > 0) { + if (nestingLevel > 0 && typeof (ret.dom as HTMLElement).setAttribute === 'function') { (ret.dom as HTMLElement).setAttribute( "data-nesting-level", nestingLevel.toString(),