Skip to content

Commit d03d53b

Browse files
fix(contracts): ignore later refs for fallback resolution
1 parent 8a085a1 commit d03d53b

2 files changed

Lines changed: 30 additions & 4 deletions

File tree

packages/layout-engine/contracts/src/header-footer-inheritance.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,16 @@ export function resolveInheritedHeaderFooterRefWithType({
5151
const fromSection = resolveVariantRef(sectionIds, variantType);
5252
if (fromSection) return fromSection;
5353

54-
const hasSectionAwareRefs =
55-
sectionMap != null &&
56-
sectionMap.size > 0 &&
57-
(sectionMap.has(sectionIndex) || (identifier.sectionCount ?? 0) > sectionIndex);
54+
let hasPriorSectionRefs = false;
55+
if (sectionMap) {
56+
for (const index of sectionMap.keys()) {
57+
if (index < sectionIndex) {
58+
hasPriorSectionRefs = true;
59+
break;
60+
}
61+
}
62+
}
63+
const hasSectionAwareRefs = sectionMap != null && (sectionMap.has(sectionIndex) || hasPriorSectionRefs);
5864
if (hasSectionAwareRefs) {
5965
for (let index = sectionIndex - 1; index >= 0; index -= 1) {
6066
const inherited = resolveVariantRef(sectionMap.get(index), variantType);

packages/layout-engine/layout-bridge/test/headerFooterUtils.test.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -977,5 +977,25 @@ describe('headerFooterUtils', () => {
977977
expect(resolved?.type).toBe('default');
978978
expect(resolved?.contentId).toBe('converter-default');
979979
});
980+
981+
it('uses converter fallback refs when only later sections define refs', () => {
982+
const identifier = buildMultiSectionIdentifier(
983+
[{ sectionIndex: 0 }, { sectionIndex: 1, headerRefs: { default: 'section-1-default' } }],
984+
undefined,
985+
{ headerIds: { default: 'converter-default' } },
986+
);
987+
const layout: Layout = {
988+
pageSize: { w: 600, h: 800 },
989+
pages: [{ number: 1, fragments: [], sectionIndex: 0 }],
990+
headerFooter: {
991+
default: { pages: [{ number: 1, fragments: [] }] },
992+
},
993+
};
994+
995+
const resolved = resolveHeaderFooterForPageAndSection(layout, 0, identifier, { kind: 'header' });
996+
997+
expect(resolved?.type).toBe('default');
998+
expect(resolved?.contentId).toBe('converter-default');
999+
});
9801000
});
9811001
});

0 commit comments

Comments
 (0)