Skip to content

Commit 82075ec

Browse files
committed
fix: add comments and test
1 parent ca014f7 commit 82075ec

3 files changed

Lines changed: 78 additions & 0 deletions

File tree

packages/layout-engine/layout-bridge/src/cache.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,9 @@ const hashRuns = (block: FlowBlock): string => {
142142

143143
for (const cellBlock of cellBlocks) {
144144
if (cellBlock?.kind === 'table') {
145+
// Intentional split with renderer.ts: cache.ts hashes nested tables only,
146+
// while renderer.ts also hashes non-paragraph cell blocks. Keep both
147+
// in sync when adjusting nested-block invalidation behavior.
145148
// Nested tables inside table cells must contribute to the parent
146149
// table cache key, otherwise edits can be missed until a later
147150
// broader invalidation.

packages/layout-engine/layout-bridge/test/cache.test.ts

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,78 @@ describe('MeasureCache', () => {
334334
expect(cache.get(table2, 800, 600)).toEqual({ totalHeight: 120 });
335335
});
336336

337+
it('invalidates when nested table content changes inside a cell block', () => {
338+
const nestedTable = (id: string, text: string): TableBlock => ({
339+
kind: 'table',
340+
id,
341+
rows: [
342+
{
343+
id: `${id}-row-0`,
344+
cells: [
345+
{
346+
id: `${id}-cell-0-0`,
347+
blocks: [
348+
{
349+
kind: 'paragraph',
350+
id: `${id}-para-0`,
351+
runs: [{ text, fontFamily: 'Arial', fontSize: 12 }],
352+
},
353+
],
354+
},
355+
],
356+
},
357+
],
358+
});
359+
360+
const parentTable1: TableBlock = {
361+
kind: 'table',
362+
id: 'parent-table',
363+
rows: [
364+
{
365+
id: 'parent-row-0',
366+
cells: [
367+
{
368+
id: 'parent-cell-0-0',
369+
blocks: [
370+
{
371+
kind: 'paragraph',
372+
id: 'parent-cell-0-0-para',
373+
runs: [{ text: 'Host', fontFamily: 'Arial', fontSize: 12 }],
374+
},
375+
nestedTable('nested-table', 'Nested A'),
376+
],
377+
},
378+
],
379+
},
380+
],
381+
};
382+
383+
const parentTable2: TableBlock = {
384+
...parentTable1,
385+
rows: [
386+
{
387+
...parentTable1.rows[0],
388+
cells: [
389+
{
390+
...parentTable1.rows[0].cells[0],
391+
blocks: [
392+
{
393+
kind: 'paragraph',
394+
id: 'parent-cell-0-0-para',
395+
runs: [{ text: 'Host', fontFamily: 'Arial', fontSize: 12 }],
396+
},
397+
nestedTable('nested-table', 'Nested B'),
398+
],
399+
},
400+
],
401+
},
402+
],
403+
};
404+
405+
cache.set(parentTable1, 800, 600, { totalHeight: 130 });
406+
expect(cache.get(parentTable2, 800, 600)).toBeUndefined();
407+
});
408+
337409
it('handles legacy single paragraph cells', () => {
338410
const table1 = tableBlock(
339411
'table-1',

packages/layout-engine/painters/dom/src/renderer.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7413,6 +7413,9 @@ const deriveBlockVersion = (block: FlowBlock): string => {
74137413
hash = hashNumber(hash, getRunNumberProp(run, 'baselineShift'));
74147414
}
74157415
} else if (cellBlock?.kind) {
7416+
// Keep this broader than layout-bridge cache.ts on purpose:
7417+
// renderer hashes any non-paragraph cell block, while cache.ts hashes
7418+
// nested tables only. If you tighten one side, review the other.
74167419
// Include nested non-paragraph blocks (notably nested tables inside
74177420
// table cells) so edits there invalidate this parent table version.
74187421
hash = hashString(hash, deriveBlockVersion(cellBlock as FlowBlock));

0 commit comments

Comments
 (0)