Skip to content

Commit c9b8acd

Browse files
fix(painter): preserve cached SECTIONPAGES fallback
1 parent 0c92406 commit c9b8acd

2 files changed

Lines changed: 10 additions & 1 deletion

File tree

packages/layout-engine/painters/dom/src/runs/text-run.test.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,12 @@ describe('resolveRunText', () => {
3737
expect(resolveRunText(run, { ...context, sectionPageCount: 7 })).toBe('7');
3838
});
3939

40+
it('preserves cached SECTIONPAGES text when section page count context is missing', () => {
41+
const run: TextRun = { text: '42', token: 'sectionPageCount', fontFamily: 'Arial', fontSize: 12 };
42+
43+
expect(resolveRunText(run, context)).toBe('42');
44+
});
45+
4046
it('formats SECTIONPAGES tokens with run-local page number format', () => {
4147
const run: TextRun = {
4248
text: '0',

packages/layout-engine/painters/dom/src/runs/text-run.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,10 @@ export const resolveRunText = (run: Run, context: FragmentRenderContext): string
146146
return context.totalPages ? String(context.totalPages) : (run.text ?? '');
147147
}
148148
if (runToken === 'sectionPageCount') {
149-
const sectionPageCount = context.sectionPageCount ?? context.totalPages ?? 1;
149+
const sectionPageCount = context.sectionPageCount;
150+
if (sectionPageCount == null) {
151+
return run.text ?? '';
152+
}
150153
if ('pageNumberFormat' in run && run.pageNumberFormat) {
151154
return formatPageNumber(sectionPageCount, run.pageNumberFormat);
152155
}

0 commit comments

Comments
 (0)