File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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 ) ;
Original file line number Diff line number Diff 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} ) ;
You can’t perform that action at this time.
0 commit comments