From 19a8cab58598af8b8c4c6d5df4241565f925e454 Mon Sep 17 00:00:00 2001 From: Luccas Correa Date: Thu, 12 Mar 2026 14:14:37 -0300 Subject: [PATCH] fix(super-editor): guard against style definition nodes without elements --- .../get-default-style-definition.js | 2 ++ .../get-default-style-definition.test.js | 22 +++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/packages/super-editor/src/core/super-converter/docx-helpers/get-default-style-definition.js b/packages/super-editor/src/core/super-converter/docx-helpers/get-default-style-definition.js index eca2f54d7..2a388a4d5 100644 --- a/packages/super-editor/src/core/super-converter/docx-helpers/get-default-style-definition.js +++ b/packages/super-editor/src/core/super-converter/docx-helpers/get-default-style-definition.js @@ -24,6 +24,8 @@ export const getDefaultStyleDefinition = (defaultStyleId, docx) => { const firstMatch = elementsWithId[0]; if (!firstMatch) return result; + if (!firstMatch.elements) return result; + const qFormat = elementsWithId.find((el) => { const qFormat = el.elements.find((innerEl) => innerEl.name === 'w:qFormat'); return qFormat; diff --git a/packages/super-editor/src/core/super-converter/docx-helpers/get-default-style-definition.test.js b/packages/super-editor/src/core/super-converter/docx-helpers/get-default-style-definition.test.js index ec4e91340..6d9bb8e61 100644 --- a/packages/super-editor/src/core/super-converter/docx-helpers/get-default-style-definition.test.js +++ b/packages/super-editor/src/core/super-converter/docx-helpers/get-default-style-definition.test.js @@ -38,6 +38,28 @@ describe('getDefaultStyleDefinition', () => { expect(res).toEqual({ lineSpaceBefore: null, lineSpaceAfter: null }); }); + it('returns minimal object when matching style has no elements', () => { + const docx = { + 'word/styles.xml': { + elements: [ + { + elements: [ + { + name: 'w:style', + attributes: { 'w:styleId': 'Heading1' }, + }, + ], + }, + ], + }, + }; + + const res = getDefaultStyleDefinition('Heading1', docx); + + expect(res).toEqual({ lineSpaceBefore: null, lineSpaceAfter: null }); + expect(parseMarks).not.toHaveBeenCalled(); + }); + it('parses style definition with spacing, indent, flags, and marks', () => { const docx = { 'word/styles.xml': {