Skip to content

Beautiful, AI-native markdown IDE and LLM wiki

Stop Ask AI composer resizes from restyling the whole document (PRD-9388) (#6437)

Andrew Mikofalvy3184073c4b85
diff --git a/.changeset/composer-inset-scoped-restyle.md b/.changeset/composer-inset-scoped-restyle.md
new file mode 100644
index 000000000..d34158a2a
--- /dev/null
+++ b/.changeset/composer-inset-scoped-restyle.md
@@ -0,0 +1,5 @@
+---
+"@inkeep/open-knowledge": patch
+---
+
+Opening or closing the agents panel, and typing a long question in the Ask AI box, are now faster on large documents.
diff --git a/packages/app/src/components/BottomComposer.dom.test.tsx b/packages/app/src/components/BottomComposer.dom.test.tsx
index ffee68e05..7b046f3e2 100644
--- a/packages/app/src/components/BottomComposer.dom.test.tsx
+++ b/packages/app/src/components/BottomComposer.dom.test.tsx
@@ -2127,3 +2127,45 @@ describe('what the Ask AI @ picker is told to list first', () => {
expect(JSON.parse(handed ?? 'null')).toEqual({ currentDocName: null, recentPaths: [] });
});
});
+
+describe('BottomComposer (composer inset publication)', () => {
+ test('publishes its height to the inset surfaces without restyling the document root', async () => {
+ const { ASK_COMPOSER_HEIGHT_VAR, publishedAskComposerHeightPx } = await import(
+ '@/editor/ask-composer-inset'
+ );
+ const scroller = document.createElement('div');
+ scroller.className = 'editor-doc-scroll';
+ document.body.append(scroller);
+ try {
+ const { unmount } = await renderComposer();
+ const published = publishedAskComposerHeightPx();
+ expect(published).toBeGreaterThan(0);
+ expect(
+ document.documentElement.style.getPropertyValue(ASK_COMPOSER_HEIGHT_VAR),
+ 'an inline custom property on <html> changes the style of every element in the ' +
+ 'document, so each composer resize restyled the whole open document',
+ ).toBe('');
+ expect(getComputedStyle(scroller).getPropertyValue(ASK_COMPOSER_HEIGHT_VAR)).toBe(
+ `${published}px`,
+ );
+ unmount();
+ expect(publishedAskComposerHeightPx()).toBe(0);
+ expect(getComputedStyle(scroller).getPropertyValue(ASK_COMPOSER_HEIGHT_VAR)).toBe('');
+ } finally {
+ scroller.remove();
+ }
+ });
+
+ test('dismissing a live composer withdraws the inset it published', async () => {
+ const { publishedAskComposerHeightPx } = await import('@/editor/ask-composer-inset');
+ const { BottomComposer } = await import('./BottomComposer');
+ const { rerender } = await renderComposer();
+ expect(publishedAskComposerHeightPx()).toBeGreaterThan(0);
+ rerender(<BottomComposer docName="notes" surface="wysiwyg" dismissed />);
+ expect(
+ publishedAskComposerHeightPx(),
+ 'a dismissed card that keeps its published height leaves the document padded for a ' +
+ 'composer that is no longer there',
+ ).toBe(0);
+ });
+});
diff --git a/packages/app/src/components/BottomComposer.tsx b/packages/app/src/components/BottomComposer.tsx
index 91b8a6bb8..11c75c60a 100644
--- a/packages/app/src/components/BottomComposer.tsx
+++ b/packages/app/src/components/BottomComposer.tsx
@@ -44,6 +44,7 @@ import { RotatingComposerPlaceholder } from '@/components/RotatingComposerPlaceh
import { AGENT_CONNECTIONS_SECTION_LABEL } from '@/components/settings/settings-section-labels';
import { Button } from '@/components/ui/button';
import { Spinner } from '@/components/ui/spinner';
+import { publishAskComposerHeight } from '@/editor/ask-composer-inset';
import {
type ComposerAttachmentDropPolicy,
ComposerMentionInput,
@@ -184,7 +185,6 @@ export function BottomComposer({
useEffect(() => {
if (folderMode || docName == null) return;
- const root = document.documentElement;
const followBottom = () => {
clampRef.current?.();
if (isScrollRestoreSuppressed(docName)) return;
@@ -234,17 +234,13 @@ export function BottomComposer({
const card = cardRef.current;
if (dismissed || !card) {
followBottom();
- root.style.removeProperty('--ask-composer-height');
return () => {
clampRef.current?.();
};
}
const apply = () => {
followBottom();
- root.style.setProperty(
- '--ask-composer-height',
- `${card.offsetHeight + ASK_COMPOSER_HEIGHT_RESERVE_PX}px`,
- );
+ publishAskComposerHeight(card.offsetHeight + ASK_COMPOSER_HEIGHT_RESERVE_PX);
};
apply();
const observer = new ResizeObserver(apply);
@@ -252,7 +248,7 @@ export function BottomComposer({
return () => {
observer.disconnect();
followBottom();
- root.style.removeProperty('--ask-composer-height');
+ publishAskComposerHeight(null);
};
}, [dismissed, docName, folderMode]);
diff --git a/packages/app/src/editor/ask-composer-inset.ts b/packages/app/src/editor/ask-composer-inset.ts
new file mode 100644
index 000000000..bc5fe8232
--- /dev/null
+++ b/packages/app/src/editor/ask-composer-inset.ts
@@ -0,0 +1,36 @@
+import {
+ CONFLICT_SCROLLPORT_SELECTOR,
+ DOCUMENT_SCROLL_HOST_SELECTOR,
+ FULL_PAGE_CM_HOST_SELECTORS,
+} from './document-scrollports';
+
+export const ASK_COMPOSER_HEIGHT_VAR = '--ask-composer-height';
+
+export const ASK_COMPOSER_INSET_SELECTORS = [
+ DOCUMENT_SCROLL_HOST_SELECTOR,
+ `${DOCUMENT_SCROLL_HOST_SELECTOR} :is(.ProseMirror, .cm-content)`,
+ FULL_PAGE_CM_HOST_SELECTORS.mermaidDocEditor,
+ `${FULL_PAGE_CM_HOST_SELECTORS.sourceEditor} .cm-content`,
+ `${FULL_PAGE_CM_HOST_SELECTORS.textDocEditor} .cm-content`,
+ CONFLICT_SCROLLPORT_SELECTOR,
+ `${CONFLICT_SCROLLPORT_SELECTOR} diffs-container`,
+] as const;
+
+let publishedPx: number | null = null;
+let insetStyle: HTMLStyleElement | null = null;
+
+export function publishAskComposerHeight(px: number | null): void {
+ if (px === publishedPx) return;
+ publishedPx = px;
+ if (px === null) {
+ insetStyle?.remove();
+ insetStyle = null;
+ return;
+ }
+ insetStyle ??= document.head.appendChild(document.createElement('style'));
+ insetStyle.textContent = `${ASK_COMPOSER_INSET_SELECTORS.join(', ')} { ${ASK_COMPOSER_HEIGHT_VAR}: ${px}px; }`;
+}
+
+export function publishedAskComposerHeightPx(): number {
+ return publishedPx ?? 0;
+}
diff --git a/packages/app/src/editor/extensions/trailing-affordance.ts b/packages/app/src/editor/extensions/trailing-affordance.ts
index a510c7e0e..d62e383e0 100644
--- a/packages/app/src/editor/extensions/trailing-affordance.ts
+++ b/packages/app/src/editor/extensions/trailing-affordance.ts
@@ -9,9 +9,9 @@ import { Extension } from '@tiptap/core';
import type { Node as PmNode } from '@tiptap/pm/model';
import { Plugin, PluginKey } from '@tiptap/pm/state';
import { Decoration, DecorationSet, type EditorView } from '@tiptap/pm/view';
+import { ASK_COMPOSER_HEIGHT_VAR } from '../ask-composer-inset.ts';
import { OPT_OUT_ATTR } from '../clipboard/index.ts';
import { insertParagraphAt } from '../selection/place-caret.ts';
-import { ASK_COMPOSER_HEIGHT_VAR } from '../utils/editor-visible-region.ts';
import { GUTTER_PLUS_SVG } from './gutter-plus-icon.ts';
export const OK_TRAILING_AFFORDANCE_CLASS = 'ok-trailing-affordance';
diff --git a/packages/app/src/editor/utils/editor-visible-region.dom.test.tsx b/packages/app/src/editor/utils/editor-visible-region.dom.test.tsx
index be9a0724d..8c2ba3047 100644
--- a/packages/app/src/editor/utils/editor-visible-region.dom.test.tsx
+++ b/packages/app/src/editor/utils/editor-visible-region.dom.test.tsx
@@ -1,6 +1,7 @@
import { cleanup, render } from '@testing-library/react';
import type { Editor } from '@tiptap/react';
import { afterEach, describe, expect, test } from 'vitest';
+import { publishAskComposerHeight } from '../ask-composer-inset';
import { TOOLBAR_HEIGHT } from '../extensions/frozen-table-headers';
import {
deriveEditorClipOptions,
@@ -26,7 +27,7 @@ function preMountEditor(): Editor {
afterEach(() => {
cleanup();
- document.documentElement.style.removeProperty('--ask-composer-height');
+ publishAskComposerHeight(null);
document.documentElement.style.removeProperty('--conflict-footer-height');
});
@@ -40,7 +41,7 @@ describe('deriveEditorClipOptions', () => {
test('bottom inset tracks the published composer height', () => {
const { editor } = renderEditorInScroller();
- document.documentElement.style.setProperty('--ask-composer-height', '236px');
+ publishAskComposerHeight(236);
expect(deriveEditorClipOptions(editor)().padding.bottom).toBe(236);
});
@@ -52,7 +53,7 @@ describe('deriveEditorClipOptions', () => {
test('composer and conflict-footer overlays stack into one bottom inset', () => {
const { editor } = renderEditorInScroller();
- document.documentElement.style.setProperty('--ask-composer-height', '236px');
+ publishAskComposerHeight(236);
document.documentElement.style.setProperty('--conflict-footer-height', '48px');
expect(deriveEditorClipOptions(editor)().padding.bottom).toBe(284);
});
@@ -61,15 +62,15 @@ describe('deriveEditorClipOptions', () => {
const { editor } = renderEditorInScroller();
const derive = deriveEditorClipOptions(editor);
expect(derive().padding.bottom).toBe(0);
- document.documentElement.style.setProperty('--ask-composer-height', '180px');
+ publishAskComposerHeight(180);
expect(derive().padding.bottom).toBe(180);
- document.documentElement.style.removeProperty('--ask-composer-height');
+ publishAskComposerHeight(null);
expect(derive().padding.bottom).toBe(0);
});
test('malformed overlay value reads as no inset', () => {
const { editor } = renderEditorInScroller();
- document.documentElement.style.setProperty('--ask-composer-height', 'auto');
+ document.documentElement.style.setProperty('--conflict-footer-height', 'auto');
expect(deriveEditorClipOptions(editor)().padding.bottom).toBe(0);
});
@@ -107,7 +108,7 @@ describe('deriveEditorShiftOptions', () => {
test('uncompensated insets match the clip region exactly', () => {
const { editor } = renderEditorInScroller();
- document.documentElement.style.setProperty('--ask-composer-height', `${COMPOSER_HEIGHT_PX}px`);
+ publishAskComposerHeight(COMPOSER_HEIGHT_PX);
document.documentElement.style.setProperty(
'--conflict-footer-height',
`${CONFLICT_FOOTER_HEIGHT_PX}px`,
@@ -124,10 +125,7 @@ describe('deriveEditorShiftOptions', () => {
'a %s placement absorbs a pending anchor gap by tightening the top inset',
(placement) => {
const { editor } = renderEditorInScroller();
- document.documentElement.style.setProperty(
- '--ask-composer-height',
- `${COMPOSER_HEIGHT_PX}px`,
- );
+ publishAskComposerHeight(COMPOSER_HEIGHT_PX);
const options = deriveEditorShiftOptions(editor, {
pendingOffsetPx: PENDING_OFFSET_PX,
})({ placement });
@@ -140,10 +138,7 @@ describe('deriveEditorShiftOptions', () => {
'a %s placement mirrors the compensation',
(placement) => {
const { editor } = renderEditorInScroller();
- document.documentElement.style.setProperty(
- '--ask-composer-height',
- `${COMPOSER_HEIGHT_PX}px`,
- );
+ publishAskComposerHeight(COMPOSER_HEIGHT_PX);
const options = deriveEditorShiftOptions(editor, {
pendingOffsetPx: PENDING_OFFSET_PX,
})({ placement });
@@ -156,10 +151,7 @@ describe('deriveEditorShiftOptions', () => {
'a %s placement needs no compensation — the pending gap is horizontal there',
(placement) => {
const { editor } = renderEditorInScroller();
- document.documentElement.style.setProperty(
- '--ask-composer-height',
- `${COMPOSER_HEIGHT_PX}px`,
- );
+ publishAskComposerHeight(COMPOSER_HEIGHT_PX);
const options = deriveEditorShiftOptions(editor, {
pendingOffsetPx: PENDING_OFFSET_PX,
})({ placement });
@@ -277,7 +269,7 @@ function stubRect(el: HTMLElement, top: number, bottom: number): void {
describe('editorVisibleBand', () => {
test('keeps both insets for a pre-mount editor', () => {
- document.documentElement.style.setProperty('--ask-composer-height', `${COMPOSER_HEIGHT_PX}px`);
+ publishAskComposerHeight(COMPOSER_HEIGHT_PX);
const band = editorVisibleBand(preMountEditor());
expect(band.top).toBe(TOOLBAR_HEIGHT);
expect(band.bottom).toBe(window.innerHeight - COMPOSER_HEIGHT_PX);
@@ -286,7 +278,7 @@ describe('editorVisibleBand', () => {
test('insets the container box by the toolbar and composer bands', () => {
const { editor, scroller } = renderEditorInScroller();
stubRect(scroller, 0, 800);
- document.documentElement.style.setProperty('--ask-composer-height', `${COMPOSER_HEIGHT_PX}px`);
+ publishAskComposerHeight(COMPOSER_HEIGHT_PX);
const band = editorVisibleBand(editor);
expect(band.top).toBe(TOOLBAR_HEIGHT);
expect(band.bottom).toBe(800 - COMPOSER_HEIGHT_PX);
@@ -295,7 +287,7 @@ describe('editorVisibleBand', () => {
test('collapses rather than inverting when the insets exceed the pane', () => {
const { editor, scroller } = renderEditorInScroller();
stubRect(scroller, 0, 200);
- document.documentElement.style.setProperty('--ask-composer-height', `${COMPOSER_HEIGHT_PX}px`);
+ publishAskComposerHeight(COMPOSER_HEIGHT_PX);
document.documentElement.style.setProperty(
'--conflict-footer-height',
`${CONFLICT_FOOTER_HEIGHT_PX}px`,
diff --git a/packages/app/src/editor/utils/editor-visible-region.ts b/packages/app/src/editor/utils/editor-visible-region.ts
index 1a52c55f1..dd403a78e 100644
--- a/packages/app/src/editor/utils/editor-visible-region.ts
+++ b/packages/app/src/editor/utils/editor-visible-region.ts
@@ -1,5 +1,6 @@
import type { DetectOverflowOptions, MiddlewareState, ShiftOptions } from '@floating-ui/dom';
import type { Editor } from '@tiptap/react';
+import { publishedAskComposerHeightPx } from '@/editor/ask-composer-inset';
import { DOCUMENT_SCROLL_HOST_SELECTOR } from '@/editor/document-scrollports';
import { editorToolbarOverlapPx } from '@/lib/editor-toolbar-overlap';
import { getEditorView } from './get-editor-view';
@@ -40,9 +41,7 @@ export function deriveEditorClipOptions(editor: Editor): () => EditorClipOptions
const boundary = resolveRegionBoundary(editor);
const padding = {
top: editorToolbarOverlapPx(),
- bottom:
- readRootInlinePxVar(ASK_COMPOSER_HEIGHT_VAR) +
- readRootInlinePxVar('--conflict-footer-height'),
+ bottom: publishedAskComposerHeightPx() + readRootInlinePxVar('--conflict-footer-height'),
};
return boundary ? { boundary, padding } : { padding };
};
@@ -110,8 +109,6 @@ export function editorRegionWidthPx(editor: Editor): number | null {
return Math.max(0, boundary.getBoundingClientRect().width - PANE_GUTTER_PX * 2);
}
-export const ASK_COMPOSER_HEIGHT_VAR = '--ask-composer-height';
-
function readRootInlinePxVar(name: string): number {
const value = Number.parseFloat(document.documentElement.style.getPropertyValue(name));
return Number.isFinite(value) ? value : 0;
diff --git a/packages/app/src/globals.composer-inset-cascade.test.ts b/packages/app/src/globals.composer-inset-cascade.test.ts
index 9a023a05c..b0561bebf 100644
--- a/packages/app/src/globals.composer-inset-cascade.test.ts
+++ b/packages/app/src/globals.composer-inset-cascade.test.ts
@@ -1,6 +1,7 @@
import { readdirSync, readFileSync } from 'node:fs';
import { join, relative, sep } from 'node:path';
import { describe, expect, test } from 'vitest';
+import { ASK_COMPOSER_INSET_SELECTORS } from './editor/ask-composer-inset';
import {
CONFLICT_SCROLLPORT_SELECTOR,
DOCUMENT_SCROLL_HOST_SELECTOR,
@@ -25,10 +26,7 @@ const INSET_VAR = '--ask-composer-height';
const INSET_VALUE = `var(${INSET_VAR}`;
-const INSET_VAR_ALLOWED_OUTSIDE_GLOBALS_CSS = [
- 'components/BottomComposer.tsx',
- 'editor/utils/editor-visible-region.ts',
-] as const;
+const INSET_VAR_ALLOWED_OUTSIDE_GLOBALS_CSS = ['editor/ask-composer-inset.ts'] as const;
type InsetKind = 'content' | 'host';
@@ -178,6 +176,35 @@ describe('full-page CodeMirror surfaces reserve the Ask AI composer height', ()
).toEqual([...new Set(COMPOSER_INSET_RULES.map((rule) => rule.prelude))].toSorted());
});
+ test('the composer publishes its height onto every globals.css rule that reads it', () => {
+ expect(
+ [...ASK_COMPOSER_INSET_SELECTORS].toSorted(),
+ '`--ask-composer-height` is registered non-inherited, so an element only sees the ' +
+ 'composer height when the published rule selects that element itself. A globals.css ' +
+ 'rule missing from `ASK_COMPOSER_INSET_SELECTORS` reads the 0px initial value and its ' +
+ 'surface reserves no room under the composer; a selector with no rule left reading it ' +
+ 'restyles elements for nothing on every composer resize',
+ ).toEqual(insetBearingSelectors(css));
+ });
+
+ test('the inset variable is registered as a non-inherited property', () => {
+ const registration = collectBlocks(css).find(
+ (block) => block.prelude === `@property ${INSET_VAR}`,
+ );
+ expect(
+ registration,
+ `globals.css no longer registers \`${INSET_VAR}\` with \`@property\`. Unregistered, the ` +
+ 'variable inherits, so the rule publishing it on `.editor-doc-scroll` changes the style ' +
+ 'of every element in the open document on each composer resize',
+ ).toBeDefined();
+ expect(
+ registration?.declarations,
+ `the \`@property ${INSET_VAR}\` registration no longer says \`inherits: false\`. An ` +
+ 'inherited variable published on `.editor-doc-scroll` restyles the whole open document ' +
+ 'on each composer resize; non-inherited, it restyles only the elements the rule selects',
+ ).toMatch(/inherits\s*:\s*false/);
+ });
+
test('every scrollport the composer re-clamps compensates a real inset rule', () => {
expect(
[...new Set(COMPOSER_INSET_RULES.map((rule) => rule.scrollport))].toSorted(),
diff --git a/packages/app/src/globals.css b/packages/app/src/globals.css
index 311501ff7..3fb0b0627 100644
--- a/packages/app/src/globals.css
+++ b/packages/app/src/globals.css
@@ -1114,13 +1114,18 @@
grid-column: content;
}
+@property --ask-composer-height {
+ syntax: "<length>";
+ initial-value: 0px;
+ inherits: false;
+}
+
/* The floating Ask AI composer reserves scroll room at the bottom of the doc by
padding the editor CONTENT (.ProseMirror / .cm-content) — padding the scroll
container alone creates no overflow because the content's own min-height fills
it. The inset tracks the live composer via `--ask-composer-height` (card height
- + gap, published by BottomComposer); the var is the single source of truth and
- is absent when the composer is collapsed or hidden, so the padding collapses to
- 0 and the space is reclaimed — no class to fall out of sync. Scoped inside
+ + gap, published by BottomComposer); the var resolves to 0px when the composer is
+ collapsed or hidden, so the space is reclaimed — no class to fall out of sync. Scoped inside
`.editor-doc-scroll` so the floating composer's own ProseMirror (a sibling of
the scroll container) is never padded. */
.editor-doc-scroll {
@@ -1283,8 +1288,7 @@
block's own `margin-bottom` collapses THROUGH a parent with no bottom
padding: with `padding-bottom: 0` those two edges are the same pixel and
the band is exactly 0px tall. That is the state a document is in whenever
- the Ask composer is unmounted, because `BottomComposer` REMOVES
- `--ask-composer-height` rather than setting it to zero. With the composer
+ the Ask composer is unmounted. With the composer
mounted the scroller rule above does supply padding, but the composer
floats over precisely that band, so the only room ever left to click was
whatever `margin-bottom` the final block happened to carry. The old
diff --git a/packages/app/tests/stress/composer-growth-eof-reveal.e2e.ts b/packages/app/tests/stress/composer-growth-eof-reveal.e2e.ts
index dad99b577..88f29b30c 100644
--- a/packages/app/tests/stress/composer-growth-eof-reveal.e2e.ts
+++ b/packages/app/tests/stress/composer-growth-eof-reveal.e2e.ts
@@ -2,6 +2,7 @@ import { randomUUID } from 'node:crypto';
import { writeFileSync } from 'node:fs';
import { join } from 'node:path';
import type { Page } from '@playwright/test';
+import { DOCUMENT_SCROLL_HOST_SELECTOR } from '../../src/editor/document-scrollports';
import { expect, test, toggleMode } from './_helpers';
const COMPOSER_CARD = '[data-testid="bottom-composer"] > div';
@@ -77,11 +78,13 @@ function describeTransition(surface: Surface, before: Geometry, after: Geometry)
}
async function readComposerHeight(page: Page): Promise<number> {
- return page.evaluate(() =>
- Number.parseFloat(
- getComputedStyle(document.documentElement).getPropertyValue('--ask-composer-height') || '0',
- ),
- );
+ return page.evaluate((scrollHostSelector) => {
+ const scrollHost = document.querySelector(scrollHostSelector);
+ if (!scrollHost) return 0;
+ return Number.parseFloat(
+ getComputedStyle(scrollHost).getPropertyValue('--ask-composer-height') || '0',
+ );
+ }, DOCUMENT_SCROLL_HOST_SELECTOR);
}
async function readLineBottom(page: Page, lineSelector: string): Promise<number> {
@@ -97,7 +100,7 @@ async function readLineBottom(page: Page, lineSelector: string): Promise<number>
async function readGeometry(page: Page, surface: Surface): Promise<Geometry> {
return page.evaluate(
- ([cardSelector, lineSelector, scrollportSelector]) => {
+ ([cardSelector, lineSelector, scrollportSelector, scrollHostSelector]) => {
const card = document.querySelector(cardSelector);
if (!(card instanceof HTMLElement))
throw new Error('the Ask AI composer card is not painted');
@@ -110,18 +113,24 @@ async function readGeometry(page: Page, surface: Surface): Promise<Geometry> {
);
const last = painted.at(-1);
if (!last) throw new Error(`no painted line matched ${lineSelector}`);
+ const scrollHost = document.querySelector(scrollHostSelector);
+ if (!scrollHost) throw new Error(`no scroll host matched ${scrollHostSelector}`);
return {
cardTop: card.getBoundingClientRect().top,
lineBottom: last.getBoundingClientRect().bottom,
composerHeight: Number.parseFloat(
- getComputedStyle(document.documentElement).getPropertyValue('--ask-composer-height') ||
- '0',
+ getComputedStyle(scrollHost).getPropertyValue('--ask-composer-height') || '0',
),
scrollTop: scrollport.scrollTop,
scrollMax: scrollport.scrollHeight - scrollport.clientHeight,
};
},
- [COMPOSER_CARD, surface.lineSelector, surface.scrollportSelector] as const,
+ [
+ COMPOSER_CARD,
+ surface.lineSelector,
+ surface.scrollportSelector,
+ DOCUMENT_SCROLL_HOST_SELECTOR,
+ ] as const,
);
}
diff --git a/packages/app/tests/stress/composer-open-caret-reveal.e2e.ts b/packages/app/tests/stress/composer-open-caret-reveal.e2e.ts
index cc80f59be..376ffabb3 100644
--- a/packages/app/tests/stress/composer-open-caret-reveal.e2e.ts
+++ b/packages/app/tests/stress/composer-open-caret-reveal.e2e.ts
@@ -4,6 +4,7 @@ import { join } from 'node:path';
import type { Page } from '@playwright/test';
import { CARET_REVEAL_GAP_PX } from '../../src/editor/caret-reveal';
import {
+ DOCUMENT_SCROLL_HOST_SELECTOR,
FULL_PAGE_CM_HOST_SELECTORS,
FULL_PAGE_CM_SCROLLPORTS,
type FullPageCmHost,
@@ -111,11 +112,13 @@ const occlusionClearanceOf = (result: CaseResult): number =>
occlusionTopOf(result) - result.after.bottom;
async function readComposerHeight(page: Page): Promise<number> {
- return page.evaluate(() =>
- Number.parseFloat(
- getComputedStyle(document.documentElement).getPropertyValue('--ask-composer-height') || '0',
- ),
- );
+ return page.evaluate((scrollHostSelector) => {
+ const scrollHost = document.querySelector(scrollHostSelector);
+ if (!scrollHost) return 0;
+ return Number.parseFloat(
+ getComputedStyle(scrollHost).getPropertyValue('--ask-composer-height') || '0',
+ );
+ }, DOCUMENT_SCROLL_HOST_SELECTOR);
}
async function readCardTop(page: Page): Promise<number> {
diff --git a/packages/app/tests/stress/selection-surface-pane-clip.e2e.ts b/packages/app/tests/stress/selection-surface-pane-clip.e2e.ts
index 4d9dd8524..608350128 100644
--- a/packages/app/tests/stress/selection-surface-pane-clip.e2e.ts
+++ b/packages/app/tests/stress/selection-surface-pane-clip.e2e.ts
@@ -60,12 +60,13 @@ async function readFloatingSurfaceGeometry(page: Page, selector: string): Promis
throw new Error(`missing chrome: scroller=${!!scroller} toolbar=${!!toolbar}`);
}
const scrollerBox = scroller.getBoundingClientRect();
- const readRootPx = (name: string): number => {
- const value = Number.parseFloat(document.documentElement.style.getPropertyValue(name));
- return Number.isFinite(value) ? value : 0;
+ const readPx = (value: string): number => {
+ const parsed = Number.parseFloat(value);
+ return Number.isFinite(parsed) ? parsed : 0;
};
const overlayBandPx =
- readRootPx('--ask-composer-height') + readRootPx('--conflict-footer-height');
+ readPx(getComputedStyle(scroller).getPropertyValue('--ask-composer-height')) +
+ readPx(document.documentElement.style.getPropertyValue('--conflict-footer-height'));
const regionTop = toolbar.getBoundingClientRect().bottom;
const regionBottom = scrollerBox.bottom - overlayBandPx;
const region = {
@@ -527,12 +528,13 @@ async function parkSelectionBottomAtRegionFloor(page: Page, inset: number): Prom
);
if (!editor) throw new Error('parkSelectionBottomAtRegionFloor: no active editor');
if (!scroller) throw new Error('parkSelectionBottomAtRegionFloor: no painted scrollport');
- const readRootPx = (name: string): number => {
- const value = Number.parseFloat(document.documentElement.style.getPropertyValue(name));
- return Number.isFinite(value) ? value : 0;
+ const readPx = (value: string): number => {
+ const parsed = Number.parseFloat(value);
+ return Number.isFinite(parsed) ? parsed : 0;
};
const overlayBandPx =
- readRootPx('--ask-composer-height') + readRootPx('--conflict-footer-height');
+ readPx(getComputedStyle(scroller).getPropertyValue('--ask-composer-height')) +
+ readPx(document.documentElement.style.getPropertyValue('--conflict-footer-height'));
const regionBottom = scroller.getBoundingClientRect().bottom - overlayBandPx;
const { to } = editor.state.selection;
const selectionBottom = editor.view.coordsAtPos(to, -1).bottom;
diff --git a/packages/app/tests/stress/text-doc-composer-inset.e2e.ts b/packages/app/tests/stress/text-doc-composer-inset.e2e.ts
index 95657e552..6784bab7d 100644
--- a/packages/app/tests/stress/text-doc-composer-inset.e2e.ts
+++ b/packages/app/tests/stress/text-doc-composer-inset.e2e.ts
@@ -33,13 +33,13 @@ test.describe('editable text doc reserves the Ask AI composer height', () => {
await expect
.poll(
() =>
- page.evaluate(() =>
- Number.parseFloat(
- getComputedStyle(document.documentElement).getPropertyValue(
- '--ask-composer-height',
- ) || '0',
- ),
- ),
+ page.evaluate((contentSel) => {
+ const content = document.querySelector(contentSel);
+ if (!content) return 0;
+ return Number.parseFloat(
+ getComputedStyle(content).getPropertyValue('--ask-composer-height') || '0',
+ );
+ }, CM_CONTENT),
{
message:
'the composer never published --ask-composer-height, so every assertion below would ' +
@@ -56,7 +56,7 @@ test.describe('editable text doc reserves the Ask AI composer height', () => {
const content = document.querySelector(contentSel);
if (!(content instanceof HTMLElement)) throw new Error('no painted .cm-content');
const composerHeight = Number.parseFloat(
- getComputedStyle(document.documentElement).getPropertyValue('--ask-composer-height'),
+ getComputedStyle(content).getPropertyValue('--ask-composer-height'),
);
return Number.parseFloat(getComputedStyle(content).paddingBottom) - composerHeight;
}, CM_CONTENT),