Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

fix(channels): estimate virtual height (#5039)

teod661656c1b8c
diff --git a/apps/web/src/features/channel/Channel/ThreadList.tsx b/apps/web/src/features/channel/Channel/ThreadList.tsx
index 3e44d2dbf0..e922d75102 100644
--- a/apps/web/src/features/channel/Channel/ThreadList.tsx
+++ b/apps/web/src/features/channel/Channel/ThreadList.tsx
@@ -8,7 +8,8 @@ import { Virtualizer, type VirtualizerHandle } from 'virtua/solid';
import type { CacheSnapshot, ScrollToIndexOpts } from 'virtua/unstable_core';
import { NEAR_BOTTOM_THRESHOLD } from './constants';
-const BASE_BUFFER_SIZE = 64;
+const BASE_ITEM_SIZE = 96;
+const BASE_BUFFER_SIZE = 500;
type ScrollAlignment = ScrollToIndexOpts['align'];
@@ -722,9 +723,7 @@ export function ThreadList(props: ThreadListProps) {
}}
scrollRef={scrollRef}
startMargin={insets().start}
- // Keep Virtua's adaptive size estimation enabled. A fixed 64px hint
- // makes it eagerly mount a viewport's worth of reply-heavy threads
- // before their much larger real heights are measured.
+ itemSize={BASE_ITEM_SIZE}
bufferSize={BASE_BUFFER_SIZE}
keepMounted={props.keepMounted?.()}
data={props.keys()}
diff --git a/apps/web/tests/e2e/helpers/scroll-presentation.ts b/apps/web/tests/e2e/helpers/scroll-presentation.ts
index 3d7d097499..624c33863c 100644
--- a/apps/web/tests/e2e/helpers/scroll-presentation.ts
+++ b/apps/web/tests/e2e/helpers/scroll-presentation.ts
@@ -10,14 +10,6 @@ type BottomPresentationSample = {
distanceFromBottom: number;
};
-type MountedThreadReport = {
- currentMessages: number;
- currentThreads: number;
- lastChangeAt?: number;
- peakMessages: number;
- peakThreads: number;
-};
-
type TargetPresentationSample = {
time: number;
center: number;
@@ -59,83 +51,9 @@ declare global {
__e2eTargetPresentation?: TargetPresentationReport;
__e2eResetTargetPresentation?: () => void;
__e2eStopTargetPresentation?: () => void;
- __e2eMountedThreads?: MountedThreadReport;
}
}
-/** Capture transient thread mounts, including rows removed before first paint. */
-export async function observeMountedThreads(
- page: Page,
- scrollSelector: string
-) {
- await page.addInitScript((selector) => {
- const report: MountedThreadReport = {
- currentMessages: 0,
- currentThreads: 0,
- peakMessages: 0,
- peakThreads: 0,
- };
- window.__e2eMountedThreads = report;
-
- const sample = () => {
- const scroller = document.querySelector<HTMLElement>(selector);
- if (!scroller?.isConnected) return;
-
- const currentThreads = scroller.querySelectorAll(
- '[data-channel-thread-row]'
- ).length;
- const currentMessages =
- scroller.querySelectorAll('[data-message-id]').length;
- if (
- currentThreads !== report.currentThreads ||
- currentMessages !== report.currentMessages
- ) {
- report.lastChangeAt = performance.now();
- }
- report.currentThreads = currentThreads;
- report.currentMessages = currentMessages;
- report.peakThreads = Math.max(report.peakThreads, report.currentThreads);
- report.peakMessages = Math.max(
- report.peakMessages,
- report.currentMessages
- );
- };
-
- new MutationObserver(sample).observe(document, {
- childList: true,
- subtree: true,
- });
-
- const samplePaintedFrames = () => {
- sample();
- requestAnimationFrame(samplePaintedFrames);
- };
- requestAnimationFrame(samplePaintedFrames);
- }, scrollSelector);
-
- return {
- read: () =>
- page.evaluate(() => window.__e2eMountedThreads as MountedThreadReport),
- waitForQuietAndRead: async (quietMs = 250) => {
- await page.waitForFunction(
- (quiet) => {
- const report = window.__e2eMountedThreads;
- return (
- report?.currentThreads > 0 &&
- report.lastChangeAt !== undefined &&
- performance.now() - report.lastChangeAt >= quiet
- );
- },
- quietMs,
- { timeout: 30_000 }
- );
- return page.evaluate(
- () => window.__e2eMountedThreads as MountedThreadReport
- );
- },
- };
-}
-
/**
* Sample painted target positions. A normal target must fit inside the usable
* viewport; a target taller than that viewport must cover it. Insets exclude
diff --git a/apps/web/tests/e2e/local-channel-scroll.spec.ts b/apps/web/tests/e2e/local-channel-scroll.spec.ts
index 2940c86f6d..913c0c458c 100644
--- a/apps/web/tests/e2e/local-channel-scroll.spec.ts
+++ b/apps/web/tests/e2e/local-channel-scroll.spec.ts
@@ -1,5 +1,3 @@
-import { createHash } from 'node:crypto';
-
import { expect, test } from '@playwright/test';
import { entityIdSelector } from '../../src/lib/core/dom-selectors';
@@ -12,52 +10,12 @@ import {
import {
delayResizeObserverFor,
observeBottomPresentation,
- observeMountedThreads,
} from './helpers/scroll-presentation';
const CHANNEL_SCROLL_SELECTOR = '[data-channel-scroll]';
const BOTTOM_TOLERANCE_PX = 1;
-const MAX_TRANSIENT_MESSAGES = 32;
-const MAX_TRANSIENT_THREADS = 8;
test.skip(!LOCAL_E2E, 'requires the seeded local E2E stack');
-test.use({ viewport: { width: 1920, height: 1080 } });
-
-function scrollFixtureMessageId(channelId: string, messageNumber: number) {
- const hex = createHash('md5')
- .update(`local-e2e-scroll-${channelId}-${messageNumber}`)
- .digest('hex');
- return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`;
-}
-
-test('does not transiently mount rows outside a reply-heavy viewport', async ({
- page,
-}) => {
- const channelId = localE2ESeed.smoke.generalChannel.channel_id;
- const targetMessageId = scrollFixtureMessageId(channelId, 2475);
- const scrollSelector = `${CHANNEL_SCROLL_SELECTOR}[data-channel-id="${channelId}"]`;
- const mountedThreads = await observeMountedThreads(page, scrollSelector);
-
- await gotoApp(
- page,
- `/channel/${channelId}?channel_message_id=${targetMessageId}`
- );
-
- const scroller = page.locator(scrollSelector);
- await expect(scroller).toBeVisible({ timeout: 30_000 });
- await expect(
- scroller.locator(`[data-message-id="${targetMessageId}"]`)
- ).toBeVisible({ timeout: 30_000 });
-
- const report = await mountedThreads.waitForQuietAndRead();
- expect(report.currentThreads).toBeGreaterThan(0);
- expect(report.peakThreads, JSON.stringify(report)).toBeLessThanOrEqual(
- MAX_TRANSIENT_THREADS
- );
- expect(report.peakMessages, JSON.stringify(report)).toBeLessThanOrEqual(
- MAX_TRANSIENT_MESSAGES
- );
-});
test('presents an overflowing channel at the bottom before measurement settles', async ({
page,
diff --git a/tooling/seed_cli/seed/local_e2e/channel_messages.sql b/tooling/seed_cli/seed/local_e2e/channel_messages.sql
index ba27afd00f..3c75af4cf5 100644
--- a/tooling/seed_cli/seed/local_e2e/channel_messages.sql
+++ b/tooling/seed_cli/seed/local_e2e/channel_messages.sql
@@ -25,58 +25,6 @@ SELECT
FROM local_e2e_channels AS channel
CROSS JOIN generate_series(1, 5000) AS message_number;
--- Consecutive reply-heavy roots reproduce the production trace where a fixed
--- 64px virtual-row estimate mounted far more threads than fit in the viewport.
-WITH reply_heavy_threads AS (
- SELECT
- message_number,
- reply_number,
- md5(
- 'local-e2e-scroll-'
- || '00000000-0000-0000-0000-000000000001'
- || '-'
- || message_number
- )::uuid AS thread_id
- FROM generate_series(2450, 2499) AS message(message_number)
- CROSS JOIN generate_series(1, 3) AS reply(reply_number)
-)
-INSERT INTO comms_messages (
- id,
- channel_id,
- sender_id,
- content,
- thread_id,
- created_at,
- updated_at
-)
-SELECT
- md5(
- 'local-e2e-reply-heavy-'
- || message_number
- || '-'
- || reply_number
- )::uuid,
- '00000000-0000-0000-0000-000000000001'::uuid,
- CASE reply_number
- WHEN 1 THEN 'macro|[email protected]'
- WHEN 2 THEN 'macro|[email protected]'
- ELSE 'macro|[email protected]'
- END,
- repeat(
- format(
- 'Reply-heavy virtualization fixture %s-%s. This diagnostic context gives each collapsed thread a production-shaped measured height. ',
- message_number,
- reply_number
- ),
- 12
- ),
- thread_id,
- now() + (message_number || ' milliseconds')::interval
- + (reply_number || ' microseconds')::interval,
- now() + (message_number || ' milliseconds')::interval
- + (reply_number || ' microseconds')::interval
-FROM reply_heavy_threads;
-
INSERT INTO comms_messages (
id,
channel_id,