Skip to content

Beautiful, AI-native markdown IDE and LLM wiki

PRD-10084 Keep frozen table headers pinned after a window resize (#7876)

Andrew Mikofalvy3634ffe888ab
diff --git a/.changeset/frozen-table-header-after-resize.md b/.changeset/frozen-table-header-after-resize.md
new file mode 100644
index 000000000..b401580d7
--- /dev/null
+++ b/.changeset/frozen-table-header-after-resize.md
@@ -0,0 +1,5 @@
+---
+'@inkeep/open-knowledge': patch
+---
+
+A table's frozen header row no longer sticks partway down the page after the window is resized.
diff --git a/packages/app/src/editor/extensions/frozen-table-headers.test.ts b/packages/app/src/editor/extensions/frozen-table-headers.test.ts
index 2c851113b..a6a955372 100644
--- a/packages/app/src/editor/extensions/frozen-table-headers.test.ts
+++ b/packages/app/src/editor/extensions/frozen-table-headers.test.ts
@@ -137,6 +137,12 @@ describe('buildShiftKeyframes', () => {
});
});
+function stubCssPercent(): void {
+ (globalThis as { CSS?: unknown }).CSS = {
+ percent: (value: number) => ({ value, unit: 'percent' }),
+ };
+}
+
describe('anchorScrollDrivenStartTime (deletion guard, not browser-rung coverage)', () => {
const realCss = (globalThis as { CSS?: unknown }).CSS;
@@ -145,10 +151,6 @@ describe('anchorScrollDrivenStartTime (deletion guard, not browser-rung coverage
vi.restoreAllMocks();
});
- function stubCssPercent(): void {
- (globalThis as { CSS?: unknown }).CSS = { percent: (value: number) => ({ percent: value }) };
- }
-
it('anchors the replacement at zero progress so it is not left play-pending', () => {
stubCssPercent();
let assigned: unknown;
@@ -160,7 +162,7 @@ describe('anchorScrollDrivenStartTime (deletion guard, not browser-rung coverage
anchorScrollDrivenStartTime(animation);
- expect(assigned).toEqual({ percent: 0 });
+ expect(assigned).toEqual({ value: 0, unit: 'percent' });
});
it('contains a rejected assignment and reports it once rather than per animation', () => {
@@ -188,7 +190,7 @@ describe('applyViewTimelineFreeze (every animation it creates is anchored)', ()
});
it('anchors all three tracks, not only the transform', () => {
- (globalThis as { CSS?: unknown }).CSS = { percent: (value: number) => ({ percent: value }) };
+ stubCssPercent();
const anchored: unknown[] = [];
const cell = {
cellIndex: 0,
@@ -208,11 +210,15 @@ describe('applyViewTimelineFreeze (every animation it creates is anchored)', ()
timelineLength: 2_000,
});
- expect(anchored).toEqual([{ percent: 0 }, { percent: 0 }, { percent: 0 }]);
+ expect(anchored).toEqual([
+ { value: 0, unit: 'percent' },
+ { value: 0, unit: 'percent' },
+ { value: 0, unit: 'percent' },
+ ]);
});
it('keeps its animations when the table only moves in the viewport', () => {
- (globalThis as { CSS?: unknown }).CSS = { percent: (value: number) => ({ percent: value }) };
+ stubCssPercent();
let created = 0;
const cell = {
animate: () => {
@@ -232,4 +238,30 @@ describe('applyViewTimelineFreeze (every animation it creates is anchored)', ()
expect(created).toBe(3);
});
+
+ it('re-anchors an animation whose start time slipped while its freeze is unchanged', () => {
+ stubCssPercent();
+ const animations: { startTime: unknown }[] = [];
+ const cell = {
+ animate: () => {
+ const animation = { startTime: null as unknown, cancel: () => {} };
+ animations.push(animation);
+ return animation as unknown as Animation;
+ },
+ } as unknown as HTMLTableCellElement;
+ const timeline = {} as AnimationTimeline;
+ const freeze = computeWrapperFreeze(1200, 1016, 1208, 1000, 40, 700);
+ if (!freeze) throw new Error('expected a freeze');
+
+ applyViewTimelineFreeze(cell, timeline, freeze);
+ for (const animation of animations) animation.startTime = { value: 7.5, unit: 'percent' };
+ applyViewTimelineFreeze(cell, timeline, freeze);
+
+ expect(animations).toHaveLength(3);
+ expect(animations.map((animation) => animation.startTime)).toEqual([
+ { value: 0, unit: 'percent' },
+ { value: 0, unit: 'percent' },
+ { value: 0, unit: 'percent' },
+ ]);
+ });
});
diff --git a/packages/app/src/editor/extensions/frozen-table-headers.ts b/packages/app/src/editor/extensions/frozen-table-headers.ts
index 06e9a92a7..be8c423e8 100644
--- a/packages/app/src/editor/extensions/frozen-table-headers.ts
+++ b/packages/app/src/editor/extensions/frozen-table-headers.ts
@@ -180,7 +180,12 @@ export function applyViewTimelineFreeze(
): void {
const key = `vt|${range.startOffset}|${range.maxShift}|${timelineLength}`;
const prev = appliedFreezes.get(cell);
- if (prev?.key === key && prev.timeline === timeline) return;
+ if (prev?.key === key && prev.timeline === timeline) {
+ for (const animation of prev.animations) {
+ if (!anchoredAtTimelineStart(animation)) anchorScrollDrivenStartTime(animation);
+ }
+ return;
+ }
if (prev) for (const animation of prev.animations) animation.cancel();
const base: ScrollDrivenAnimationOptions = { timeline, fill: 'both', easing: 'linear' };
@@ -195,6 +200,11 @@ export function applyViewTimelineFreeze(
appliedFreezes.set(cell, { key, timeline, animations });
}
+function anchoredAtTimelineStart(animation: Animation): boolean {
+ const start: unknown = animation.startTime;
+ return typeof start === 'object' && start !== null && 'value' in start && start.value === 0;
+}
+
let scrollDrivenStartTimeRejectionWarned = false;
export function anchorScrollDrivenStartTime(animation: Animation): void {
diff --git a/packages/app/tests/stress/frozen-table-headers.e2e.ts b/packages/app/tests/stress/frozen-table-headers.e2e.ts
index d0752d37e..d3e776b3b 100644
--- a/packages/app/tests/stress/frozen-table-headers.e2e.ts
+++ b/packages/app/tests/stress/frozen-table-headers.e2e.ts
@@ -84,6 +84,49 @@ ${Array.from({ length: 12 }, (_, i) => `| R${i + 1} | Agent markdown write path
${Array.from({ length: 28 }, (_, i) => `Appendix paragraph ${i + 1} below the table so the document keeps scrolling.`).join('\n\n')}
`;
+const TRACKER_WORDS = [
+ 'status',
+ 'owner',
+ 'cloud',
+ 'editor',
+ 'shipped',
+ 'blocked',
+ 'review',
+ 'tracker',
+ 'launch',
+ 'sidebar',
+];
+const trackerWords = (count: number, seed: number) =>
+ Array.from({ length: count }, (_, i) => TRACKER_WORDS[(i * 7 + seed) % 10]).join(' ');
+const trackerTable = (seed: number) =>
+ [
+ '| Col 1 | Col 2 | Col 3 | Col 4 | Col 5 |',
+ '| --- | --- | --- | --- | --- |',
+ ...Array.from(
+ { length: 20 },
+ (_, r) =>
+ `| Item ${seed}-${r} | ${[1, 2, 3, 4].map((c) => trackerWords(4 + ((r + c) % 4), r + c)).join(' | ')} |`,
+ ),
+ ].join('\n');
+const trackerParagraphs = (count: number, seed: number) =>
+ Array.from({ length: count }, (_, i) => `${trackerWords(30, i + seed)}.`).join('\n\n');
+const TWO_TABLE_TRACKER_MARKDOWN = `# Tracker
+
+${trackerParagraphs(6, 1)}
+
+## A
+
+${trackerTable(1)}
+
+${trackerParagraphs(8, 2)}
+
+## B
+
+${trackerTable(2)}
+
+${trackerParagraphs(8, 3)}
+`;
+
const SCROLL_SELECTOR = '[data-testid="editor-scroll-container"]';
const TOOLBAR_HEIGHT = 56;
@@ -478,6 +521,67 @@ test('a document height change keeps the frozen header on its existing animation
expect(sameAnimations).toBe(true);
});
+test('a window resize round trip leaves an on-screen frozen header pinned under the toolbar', async ({
+ page,
+ api,
+ workerServer,
+}, testInfo) => {
+ await page.setViewportSize({ width: 1512, height: 656 });
+ await api.seedDocs([{ name: 'frozen-hdr-resize', markdown: TWO_TABLE_TRACKER_MARKDOWN }]);
+ await page.goto(`${workerServer.baseURL}/#/frozen-hdr-resize`);
+ await waitForActiveProviderSynced(page);
+ await page.locator('table').first().waitFor({ state: 'visible' });
+ await waitForQuiescence(page, SCROLL_SELECTOR);
+ const readSecondTable = (scroll: boolean) =>
+ page.evaluate(
+ ({ sel, toolbarHeight, scroll }) =>
+ new Promise<{ shiftPx: number; pinErrorPx: number }>((resolve) => {
+ const scrollEl = document.querySelector(sel) as HTMLElement;
+ const table = document.querySelectorAll<HTMLTableElement>(
+ '.ProseMirror .tableWrapper > table',
+ )[1];
+ if (scroll)
+ scrollEl.scrollTo({
+ top:
+ scrollEl.scrollTop +
+ table.getBoundingClientRect().top -
+ scrollEl.getBoundingClientRect().top -
+ toolbarHeight +
+ 300,
+ behavior: 'instant' as ScrollBehavior,
+ });
+ const started = performance.now();
+ const tick = (): void => {
+ const cell = table.tBodies[0].rows[0].cells[0];
+ const transform = getComputedStyle(cell).transform;
+ const shiftPx = transform === 'none' ? 0 : new DOMMatrixReadOnly(transform).m42;
+ const expectedTop = scrollEl.getBoundingClientRect().top + toolbarHeight;
+ const pinErrorPx = Math.abs(cell.getBoundingClientRect().top - expectedTop);
+ if (pinErrorPx < 2 || performance.now() - started > 3_000) {
+ resolve({ shiftPx, pinErrorPx });
+ return;
+ }
+ requestAnimationFrame(tick);
+ };
+ requestAnimationFrame(tick);
+ }),
+ { sel: SCROLL_SELECTOR, toolbarHeight: TOOLBAR_HEIGHT, scroll },
+ );
+ const before = await readSecondTable(true);
+ expect(before.shiftPx).toBeGreaterThan(0.5);
+ expect(before.pinErrorPx).toBeLessThan(2);
+
+ await page.setViewportSize({ width: 1000, height: 656 });
+ await waitForQuiescence(page, SCROLL_SELECTOR);
+ await page.setViewportSize({ width: 1512, height: 656 });
+ await waitForQuiescence(page, SCROLL_SELECTOR);
+
+ const after = await readSecondTable(false);
+ await page.screenshot({ path: testInfo.outputPath('after-resize.png') });
+ expect(after.shiftPx).toBeGreaterThan(0.5);
+ expect(after.pinErrorPx).toBeLessThan(2);
+});
+
test('a browser that rejects ViewTimeline construction still pins the header', async ({
page,
api,