Commit adf4ea6
authored
fix(layout-bridge): keep footnote fragments within the reserved band (SD-1680) (#2881)
* fix(layout-bridge): keep footnote fragments within the reserved band (SD-1680)
When multiple footnotes competed for space on a single page, footnote
fragments could render past the bottom page margin — sometimes 150+ pixels
into the footer area or off the page entirely. Caused by three interacting
issues in `computeFootnoteLayoutPlan` + the multi-pass reserve loop:
1. Placement used `maxReserve` (~the whole page) as the height ceiling, so
the plan happily placed more footnote content than the body layout had
actually reserved at the bottom.
2. The multi-pass stabilization loop could oscillate when reducing the
reserve shifted refs between pages, and exit with a `reserves` vector
that didn't match what the plan placed — leaving body layout and
footnote plan inconsistent.
3. The post-loop "reservesDiffer → relayout" branch could then reintroduce
the mismatch by laying out with one reserve vector while the final plan
operated on another.
Fixes:
- `computeFootnoteLayoutPlan`: when `baseReserve > 0`, cap `placeFootnote`'s
`availableHeight` to `baseReserve` (the band actually reserved by the
body layout), not `maxReserve`. Excess footnotes are pushed to the next
page via the existing `pendingByColumn` mechanism. Initial pass
(`baseReserve === 0`) still uses `maxReserve` to seed a meaningful
reserve for subsequent passes.
- Multi-pass loop: merge reserves element-wise with `max(prev, next)` each
pass. Reserves are monotonically non-decreasing, so the loop is
guaranteed to converge (bounded by `maxReserve` per page) and the old
`[247] ↔ [394]` oscillation can't recur.
- Post-loop: drop the `reservesDiffer → relayout` branch. With the
monotonic loop already converged and placement bounded by `reserves`,
`finalPlan`'s slices always fit within the body's reserved band. The
extra relayout was the mechanism that reintroduced inconsistency.
Visual validation (in-browser) on the 3 fixtures from the Linear issue:
- reporter-test.docx: max overflow 156px → 0px
- harvey-nvca.docx: overflow present → 0px
- torke-carlsbad.docx: overflow present → 0px
Tests:
- 2 new tests in footnoteBandOverflow.test.ts asserting the invariant
"every footnote fragment's bottom-Y ≤ page's physical bottom limit"
for both multi-footnote pressure and oversized-footnote cases.
- 1168 layout-bridge tests pass, 604 layout-engine tests pass,
1737 pm-adapter tests pass, 11385 super-editor tests pass.
Follow-up (Step 3, separate PR): footnote-aware body pagination — consult
footnote heights when deciding whether paragraph P fits on page N, rather
than reactively shrinking body via reserves. This would eliminate the
multi-pass loop entirely.
* fix(layout-bridge): drive footnote reserve from per-page demand (SD-1680)
Cap footnote placement at each page's measured demand (capped at maxReserve)
rather than the body's prior-pass reserve, and merge element-wise max across
oscillating reserve vectors before the post-loop relayout. Ensures every
page's reserve is large enough to hold its placed footnotes so fragments
cannot render past the bottom margin, and iterates the post-loop relayout
until the layout's reserve per page matches the final plan's demand.1 parent 781b8cd commit adf4ea6
2 files changed
Lines changed: 303 additions & 15 deletions
File tree
- packages/layout-engine/layout-bridge
- src
- test
Lines changed: 79 additions & 15 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1329 | 1329 | | |
1330 | 1330 | | |
1331 | 1331 | | |
| 1332 | + | |
| 1333 | + | |
| 1334 | + | |
| 1335 | + | |
| 1336 | + | |
| 1337 | + | |
| 1338 | + | |
| 1339 | + | |
| 1340 | + | |
| 1341 | + | |
| 1342 | + | |
| 1343 | + | |
| 1344 | + | |
| 1345 | + | |
| 1346 | + | |
| 1347 | + | |
| 1348 | + | |
| 1349 | + | |
| 1350 | + | |
| 1351 | + | |
| 1352 | + | |
| 1353 | + | |
| 1354 | + | |
| 1355 | + | |
| 1356 | + | |
| 1357 | + | |
| 1358 | + | |
| 1359 | + | |
1332 | 1360 | | |
1333 | 1361 | | |
1334 | 1362 | | |
| |||
1366 | 1394 | | |
1367 | 1395 | | |
1368 | 1396 | | |
1369 | | - | |
| 1397 | + | |
1370 | 1398 | | |
1371 | 1399 | | |
1372 | 1400 | | |
| |||
1375 | 1403 | | |
1376 | 1404 | | |
1377 | 1405 | | |
1378 | | - | |
| 1406 | + | |
1379 | 1407 | | |
1380 | 1408 | | |
1381 | 1409 | | |
| |||
1757 | 1785 | | |
1758 | 1786 | | |
1759 | 1787 | | |
1760 | | - | |
| 1788 | + | |
1761 | 1789 | | |
1762 | 1790 | | |
1763 | 1791 | | |
| |||
1773 | 1801 | | |
1774 | 1802 | | |
1775 | 1803 | | |
1776 | | - | |
1777 | | - | |
| 1804 | + | |
| 1805 | + | |
| 1806 | + | |
| 1807 | + | |
| 1808 | + | |
1778 | 1809 | | |
1779 | | - | |
| 1810 | + | |
| 1811 | + | |
| 1812 | + | |
| 1813 | + | |
| 1814 | + | |
| 1815 | + | |
| 1816 | + | |
| 1817 | + | |
| 1818 | + | |
| 1819 | + | |
| 1820 | + | |
| 1821 | + | |
| 1822 | + | |
| 1823 | + | |
| 1824 | + | |
| 1825 | + | |
| 1826 | + | |
| 1827 | + | |
1780 | 1828 | | |
1781 | 1829 | | |
1782 | | - | |
| 1830 | + | |
1783 | 1831 | | |
1784 | 1832 | | |
1785 | 1833 | | |
| |||
1804 | 1852 | | |
1805 | 1853 | | |
1806 | 1854 | | |
1807 | | - | |
1808 | 1855 | | |
1809 | | - | |
1810 | | - | |
1811 | | - | |
1812 | | - | |
1813 | | - | |
1814 | | - | |
1815 | | - | |
| 1856 | + | |
| 1857 | + | |
| 1858 | + | |
| 1859 | + | |
| 1860 | + | |
| 1861 | + | |
| 1862 | + | |
| 1863 | + | |
| 1864 | + | |
| 1865 | + | |
| 1866 | + | |
| 1867 | + | |
| 1868 | + | |
| 1869 | + | |
| 1870 | + | |
| 1871 | + | |
| 1872 | + | |
| 1873 | + | |
| 1874 | + | |
| 1875 | + | |
| 1876 | + | |
| 1877 | + | |
| 1878 | + | |
| 1879 | + | |
1816 | 1880 | | |
1817 | 1881 | | |
1818 | 1882 | | |
| |||
Lines changed: 224 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
0 commit comments