Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
96 changes: 45 additions & 51 deletions packages/layout-engine/layout-bridge/src/incrementalLayout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1638,7 +1638,8 @@ export async function incrementalLayout(

// Pass 2: recompute assignment and reserves for the updated pagination.
({ columns: pageColumns, idsByColumn } = resolveFootnoteAssignments(layout));
({ measuresById } = await measureFootnoteBlocks(collectFootnoteIdsByColumn(idsByColumn)));
let blocks;
({ blocks, measuresById } = await measureFootnoteBlocks(collectFootnoteIdsByColumn(idsByColumn)));
plan = computeFootnoteLayoutPlan(layout, idsByColumn, measuresById, reserves, pageColumns);
reserves = plan.reserves;

Expand All @@ -1651,62 +1652,55 @@ export async function incrementalLayout(
remeasureParagraph: (block: FlowBlock, maxWidth: number, firstLineIndent?: number) =>
remeasureParagraph(block as ParagraphBlock, maxWidth, firstLineIndent),
});
let { columns: finalPageColumns, idsByColumn: finalIdsByColumn } = resolveFootnoteAssignments(layout);
let { blocks: finalBlocks, measuresById: finalMeasuresById } = await measureFootnoteBlocks(
collectFootnoteIdsByColumn(finalIdsByColumn),
);
let finalPlan = computeFootnoteLayoutPlan(
layout,
finalIdsByColumn,
finalMeasuresById,
reserves,
finalPageColumns,
);
const finalReserves = finalPlan.reserves;
let reservesAppliedToLayout = reserves;
const reservesDiffer =
finalReserves.length !== reserves.length ||
finalReserves.some((h, i) => (reserves[i] ?? 0) !== h) ||
reserves.some((h, i) => (finalReserves[i] ?? 0) !== h);
if (reservesDiffer) {
layout = layoutDocument(currentBlocks, currentMeasures, {
...options,
footnoteReservedByPageIndex: finalReserves,
headerContentHeights,
footerContentHeights,
remeasureParagraph: (block: FlowBlock, maxWidth: number, firstLineIndent?: number) =>
remeasureParagraph(block as ParagraphBlock, maxWidth, firstLineIndent),
});
reservesAppliedToLayout = finalReserves;
({ columns: finalPageColumns, idsByColumn: finalIdsByColumn } = resolveFootnoteAssignments(layout));
({ blocks: finalBlocks, measuresById: finalMeasuresById } = await measureFootnoteBlocks(
collectFootnoteIdsByColumn(finalIdsByColumn),
));
finalPlan = computeFootnoteLayoutPlan(
layout,
finalIdsByColumn,
finalMeasuresById,
reservesAppliedToLayout,
finalPageColumns,
);
}
// let { columns: finalPageColumns, idsByColumn: finalIdsByColumn } = resolveFootnoteAssignments(layout);
// let { blocks: finalBlocks, measuresById: finalMeasuresById } = await measureFootnoteBlocks(
// collectFootnoteIdsByColumn(finalIdsByColumn),
// );
// let finalPlan = computeFootnoteLayoutPlan(
// layout,
// finalIdsByColumn,
// finalMeasuresById,
// reserves,
// finalPageColumns,
// );
// const finalReserves = finalPlan.reserves;
// let reservesAppliedToLayout = reserves;
// const reservesDiffer =
// finalReserves.length !== reserves.length ||
// finalReserves.some((h, i) => (reserves[i] ?? 0) !== h) ||
// reserves.some((h, i) => (finalReserves[i] ?? 0) !== h);
// if (reservesDiffer) {
// layout = layoutDocument(currentBlocks, currentMeasures, {
// ...options,
// footnoteReservedByPageIndex: finalReserves,
// headerContentHeights,
// footerContentHeights,
// remeasureParagraph: (block: FlowBlock, maxWidth: number, firstLineIndent?: number) =>
// remeasureParagraph(block as ParagraphBlock, maxWidth, firstLineIndent),
// });
// reservesAppliedToLayout = finalReserves;
// ({ columns: finalPageColumns, idsByColumn: finalIdsByColumn } = resolveFootnoteAssignments(layout));
// ({ blocks: finalBlocks, measuresById: finalMeasuresById } = await measureFootnoteBlocks(
// collectFootnoteIdsByColumn(finalIdsByColumn),
// ));
// finalPlan = computeFootnoteLayoutPlan(
// layout,
// finalIdsByColumn,
// finalMeasuresById,
// reservesAppliedToLayout,
// finalPageColumns,
// );
// }
const blockById = new Map<string, FlowBlock>();
finalBlocks.forEach((block) => {
blocks.forEach((block) => {
blockById.set(block.id, block);
});
const injected = injectFragments(
layout,
finalPlan,
finalMeasuresById,
reservesAppliedToLayout,
blockById,
finalPageColumns,
);
const injected = injectFragments(layout, plan, measuresById, reserves, blockById, pageColumns);
Comment on lines 1694 to +1698

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Recompute footnote assignments after final relayout

After the final layoutDocument(...) call applies the updated reserves, this code still injects fragments using plan, pageColumns, and measuresById that were computed before that relayout. If pass‑2 reserves change pagination (e.g., a footnote pushes content to the next page), the assignments and plan are stale and injectFragments can place footnotes on the wrong pages or overlap content. The previous logic re‑resolved assignments/measures against the post‑relayout layout to avoid this; consider recomputing those inputs after the final relayout when pagination can change.

Useful? React with 👍 / 👎.


const alignedBlocks: FlowBlock[] = [];
const alignedMeasures: Measure[] = [];
finalBlocks.forEach((block) => {
const measure = finalMeasuresById.get(block.id);
blocks.forEach((block) => {
const measure = measuresById.get(block.id);
if (!measure) return;
alignedBlocks.push(block);
alignedMeasures.push(measure);
Expand Down
Loading