diff --git a/packages/layout/src/steps/resolveBookmarks.ts b/packages/layout/src/steps/resolveBookmarks.ts index 58c2fa97b..7e75a60d9 100644 --- a/packages/layout/src/steps/resolveBookmarks.ts +++ b/packages/layout/src/steps/resolveBookmarks.ts @@ -31,7 +31,7 @@ const resolveBookmarks = (node: DocumentNode) => { let parent = element.parent; - if (child.props && 'bookmark' in child.props) { + if (child.props && 'bookmark' in child.props && child.props.bookmark) { const bookmark = getBookmarkValue(child.props.bookmark); const ref = refs++; const newHierarchy = { ref, parent: parent?.ref, ...bookmark }; diff --git a/packages/layout/tests/steps/resolveBookmarks.test.ts b/packages/layout/tests/steps/resolveBookmarks.test.ts index 590e45d21..5eb33d211 100644 --- a/packages/layout/tests/steps/resolveBookmarks.test.ts +++ b/packages/layout/tests/steps/resolveBookmarks.test.ts @@ -18,7 +18,72 @@ describe('layout resolveBookmarks', () => { const result = resolveBookmarks(root); - expect(result).toEqual(root); + expect(result).toEqual({ + type: 'DOCUMENT', + props: {}, + children: [ + { + type: 'PAGE', + children: [{ type: 'VIEW', props: {} }], + }, + ], + }); + }); + + test('should keep nodes the same if an undefined bookmark passed', () => { + const root = { + type: 'DOCUMENT', + props: {}, + children: [ + { + type: 'PAGE', + props: { bookmark: undefined }, + children: [{ type: 'VIEW', props: {} }], + }, + ], + } as DocumentNode; + + const result = resolveBookmarks(root); + + expect(result).toEqual({ + type: 'DOCUMENT', + props: {}, + children: [ + { + type: 'PAGE', + props: { bookmark: undefined }, + children: [{ type: 'VIEW', props: {} }], + }, + ], + }); + }); + + test('should keep nodes the same if a null bookmark passed', () => { + const root = { + type: 'DOCUMENT', + props: {}, + children: [ + { + type: 'PAGE', + props: { bookmark: null }, + children: [{ type: 'VIEW', props: {} }], + }, + ], + } as DocumentNode; + + const result = resolveBookmarks(root); + + expect(result).toEqual({ + type: 'DOCUMENT', + props: {}, + children: [ + { + type: 'PAGE', + props: { bookmark: null }, + children: [{ type: 'VIEW', props: {} }], + }, + ], + }); }); test('should resolve bookmark in page node', () => {