Skip to content

Commit 4bcd8d3

Browse files
fix(painter): preserve cached SECTIONPAGES fallback
1 parent 0879729 commit 4bcd8d3

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
@@ -153,7 +153,10 @@ export const resolveRunText = (run: Run, context: FragmentRenderContext): string
153153
return context.totalPages ? String(context.totalPages) : (run.text ?? '');
154154
}
155155
if (runToken === 'sectionPageCount') {
156-
const sectionPageCount = context.sectionPageCount ?? context.totalPages ?? 1;
156+
const sectionPageCount = context.sectionPageCount;
157+
if (sectionPageCount == null) {
158+
return run.text ?? '';
159+
}
157160
if (run.pageNumberFieldFormat) {
158161
return formatPageNumberFieldValue(sectionPageCount, run.pageNumberFieldFormat);
159162
}

0 commit comments

Comments
 (0)