mirror of
https://github.com/block/buzz.git
synced 2026-08-18 06:50:31 +02:00
Desktop input latency regressed sharply for users on v0.5.9 and worsened on latest main: multi-second stalls when clicking back into the app, slow fresh boots, intermittent lockups, and scroll/mouse degradation. Reverting to `119a84897` (pre-0.5.9) was confirmed to resolve it, isolating the regression to that range. Profiling a live production renderer plus a commit-level audit of the range found three independent, additive causes — fixed here — plus a long-standing `get_channels` cost that made every remaining refetch expensive, also addressed here. ## 1. Focus-return refetch storm (`refetchOnWindowFocus`) #5490 wired TanStack's `focusManager` to app focus and flipped ~20 query sites to `refetchOnWindowFocus: true`. A focus return after >60s away fires them all within milliseconds — and a click into an unfocused window *is* a focus return, so the burst runs before the click is processed. That is the "click into the composer, wait 5 seconds" symptom, and it also explains why mouse input feels worse than keyboard (clicks arrive with focus transitions; typing happens while already focused). A 5-second `sample` of a live production renderer caught a single window activity-state transition consuming ~1.25s of main-thread time, dominated by `JSON.parse` in the focus listener's microtask drain. #5535 already established the fix pattern but applied it to only two families (channels, home-feed). This PR extends the same 5-minute `staleTime` discipline to the remaining families: pulse (×5), workflows (×4), agents (×4), forum (×2), presence, user-status, custom-emoji, channel-templates, and the persona catalog. Polling cadences and push-invalidation paths are untouched — interval refetches and `invalidateQueries` both bypass `staleTime`, so live-update behavior is unchanged. Each gated family exports its focus-refetch policy as an options object that the production hook spreads into `useQuery`, and a `focusRefetchPolicy.test.mjs` drives a `QueryObserver` with that same production object — locking the policy behaviorally (fresh focus return → 0 fetches; stale → refetch) and failing if a hook's `staleTime`/`refetchOnWindowFocus` wiring drifts. Four families deliberately keep tighter freshness, all surfaces where the 5-minute gate would suppress the only refresh path and none of which feed the app-wide storm: `repo-sync-status` keeps its fresh focus refetch (its inline comment documents the "committed in a terminal, switched back to the app" flow as intended); the workflow-runs list stale-gates at 10s because a remotely-started run has no push invalidation and its conditional 1s poll is off while the cache shows no active runs; the workflow list queries (`useChannelWorkflowsQuery` and the all-channels aggregate) stale-gate at 10s because they have no poll and no relay subscription, and mutation-driven invalidation only covers this renderer — remote workflow creates/edits/deletes surface only via focus refetch; and the managed-agent log stale-gates at one poll tick (30s) so returning to a live agent log refreshes immediately. Run approvals keep the 5-minute gate under `RUN_APPROVALS_FOCUS_STALE_TIME_MS` — their focused 10s poll already covers freshness. ## 2. Synchronous localStorage sweep on the boot/focus path #5453's stale-cache sweep synchronously `getItem` + `JSON.parse`s every whitelisted localStorage entry on the main thread (multi-MB on seasoned profiles), scheduled with a `requestIdleCallback` timeout of 1.5s that guaranteed it landed mid-boot, and re-armed on every hidden→visible transition — stacking it onto the exact moment the focus storm fires. #5454's `trimSelfProfileCaches()` additionally scanned every localStorage key on every `writeSelfProfileCache()` call (which fires per relay self-profile delivery at boot). Now: the first sweep waits `BOOT_SWEEP_FLOOR_MS` (30s) after startup, the scan is time-sliced across idle callbacks, and the visibility trigger is removed — boot-delayed plus hourly still covers the 14-day TTL contract. The sliced sweep re-checks staleness immediately before each removal (a key rewritten fresh mid-sweep survives), isolates per-key storage errors so one bad entry can't strand the rest of the snapshot, defers oversized values once rather than parsing them on a zero-budget slice, guarantees forward progress on timeout-fired callbacks, and cancels its scheduled slice when stopped. The profile trim keeps a lazily-initialized memoized key count so the common under-cap write is O(1); the full parse scan runs only when the count exceeds a cap, resyncs if external deletions made it stale, and a failed scan skips the trim instead of aborting the write. Sweep semantics (rules, TTLs, eviction) are unchanged, and tests cover the scheduling, slice-progress, error-isolation, defer-once, and trim short-circuit behaviors. ## 3. The macOS window was never opaque #5478's glass appearance is correctly opt-in at the CSS layer, but the compositor cost was baked in deeper than its native `on_webview_ready` transparency call: the main window is declared `"transparent": true` in `tauri.conf.json` (added for the original glass work in #1671), which makes tao call `NSWindow.setOpaque(false)` at creation and resolve every later `set_background_color(None)` to `clearColor` — and no runtime `setOpaque(true)` path exists through tauri, while wry's runtime background setter can only force the WKWebView's `drawsBackground` off, never back on. So "restore the platform default" was unreachable: every launch, glass or not, ran with a non-opaque NSWindow, defeating WindowServer's opaque-window compositing fast path and forcing full window compositing every frame — compounded by the existing `backdrop-blur` chrome overlapping the scrolling timeline. This matches the compositor-shaped symptoms (scroll and pointer input degrading first). The window is now created opaque (`"transparent": false`) and the NSWindow layer is never made transparent at runtime. Glass never needed a transparent window: behind-window `NSVisualEffectView` vibrancy renders inside opaque windows (this is how Finder and Notes draw vibrant sidebars); it only requires a transparent WKWebView canvas, which the `set_window_vibrancy` enable path already establishes at runtime (`macos-private-api` compiles that in independent of the window flag). Enabling glass installs the vibrancy layer and then makes only the webview canvas see-through; disabling clears the vibrancy layer — the canvas may stay non-drawing afterwards (wry's flag is one-way at runtime), which is harmless because glass-off CSS paints fully opaque above an always-opaque NSWindow. The boot-path first-frame backing writes touch only the NSWindow backing color and are therefore inert to glass state regardless of how they order against the `ThemeProvider`'s vibrancy call on a persisted-glass-on cold boot. Glass-off users (the default) get an end-to-end opaque window from boot for the first time. ## 4. `get_channels`: serial round-trips and a multi-MB payload on every refetch The stale gates in (1) cut refetch frequency; this cuts the cost of the refetches that legitimately remain (boot, and focus returns after more than 5 minutes away — previously still a multi-second stall). `get_channels` made ~8 fully serial relay round-trips (~3.2–3.6s at 1,100+ channels), then shipped the full `ChannelInfo` list — including every channel's member pubkeys — across IPC, where the renderer's `JSON.parse` of the multi-MB payload froze the main thread (the ~1.25s stall captured in the live sample). - **Concurrent stages**: the membership chain, the open-channel directory scan, and the hidden-DM snapshot run concurrently, as do the member-count and last-message queries that follow. The critical path drops from ~8 sequential round-trips to 2 phases. Filters, limits, pagination, and merge semantics are unchanged. - **Not-modified short-circuit**: the command now takes a client-supplied content hash (FNV-1a 64 over the channel list, canonicalized by id and excluding `last_message_at`) and omits the channel list from the response when nothing else changed. Last-message timestamps — which change on nearly every message anywhere — ship as a small separate map that the client overlays onto its cached list with reference preservation, so React Query's structural sharing also skips downstream re-renders. On a typical refocus the renderer parses kilobytes instead of megabytes. The hash is stored in the query cache itself, tying its lifecycle to the data it describes so a community switch can never leak a stale hash. The E2E mock bridge speaks the new payload shape — including the complete `last_messages` map the client treats as authoritative — and hash canonicalization plus overlay reference-preservation are unit-tested on both sides. --------- Signed-off-by: Will Pfleger <pfleger.will@gmail.com>
535 lines
17 KiB
TypeScript
535 lines
17 KiB
TypeScript
import { expect, test, type Browser, type Page } from "@playwright/test";
|
|
|
|
import {
|
|
installRelayBridge,
|
|
openChannelBrowser,
|
|
openCreateChannelDialog,
|
|
TEST_IDENTITIES,
|
|
} from "../helpers/bridge";
|
|
import { assertRelaySeeded } from "../helpers/seed";
|
|
|
|
const isCi = Boolean(process.env.CI);
|
|
const relaySeedHookTimeoutMs = isCi ? 90_000 : 30_000;
|
|
|
|
async function expectTimelineToContain(page: Page, text: string) {
|
|
await expect(page.getByTestId("message-timeline")).toContainText(text);
|
|
}
|
|
|
|
async function getTimelineMetrics(page: Page) {
|
|
return page.getByTestId("message-timeline").evaluate((element) => {
|
|
const timeline = element as HTMLDivElement;
|
|
|
|
const composer = document.querySelector<HTMLElement>(
|
|
'[data-testid="channel-composer-overlay"]',
|
|
);
|
|
const composerHeight = composer?.getBoundingClientRect().height ?? 0;
|
|
|
|
return {
|
|
clientHeight: timeline.clientHeight,
|
|
scrollHeight: timeline.scrollHeight,
|
|
scrollTop: timeline.scrollTop,
|
|
composerHeight,
|
|
// The virtualized timeline reserves a trailing spacer equal to the
|
|
// overlaid composer. Reaching the visual tail therefore leaves that
|
|
// spacer below the last row rather than setting the raw DOM distance to 0.
|
|
distanceFromBottom:
|
|
timeline.scrollHeight -
|
|
timeline.clientHeight -
|
|
timeline.scrollTop -
|
|
composerHeight,
|
|
};
|
|
});
|
|
}
|
|
|
|
async function seedTimelineHistory(
|
|
senderPage: Page,
|
|
channelName: string,
|
|
prefix: string,
|
|
) {
|
|
const messages = Array.from(
|
|
{ length: 24 },
|
|
(_, index) => `${prefix} seed ${index}`,
|
|
);
|
|
for (const content of messages) {
|
|
await sendChannelMessage(senderPage, { channelName, content });
|
|
}
|
|
const lastSeed = messages.at(-1);
|
|
if (!lastSeed) throw new Error("Timeline seed set is empty.");
|
|
return lastSeed;
|
|
}
|
|
|
|
async function createAndJoinSharedStream(
|
|
ownerPage: Page,
|
|
memberPage: Page,
|
|
channelName: string,
|
|
seed?: { prefix: string; minDistance?: number },
|
|
) {
|
|
await openCreateChannelDialog(ownerPage);
|
|
await ownerPage.getByTestId("create-channel-name").fill(channelName);
|
|
await ownerPage.getByTestId("create-channel-submit").click();
|
|
await expect(ownerPage.getByTestId("stream-list")).toContainText(channelName);
|
|
await expect(ownerPage.getByTestId("chat-title")).toHaveText(channelName);
|
|
await expect(ownerPage.getByTestId("message-input")).toBeEnabled();
|
|
|
|
const lastSeed = seed
|
|
? await seedTimelineHistory(ownerPage, channelName, seed.prefix)
|
|
: null;
|
|
|
|
await openChannelBrowser(memberPage);
|
|
await expect(memberPage.getByTestId("channel-browser-dialog")).toBeVisible();
|
|
await memberPage
|
|
.getByTestId(`browse-channel-${channelName}`)
|
|
.getByRole("button", { name: "Join" })
|
|
.click();
|
|
await expect(memberPage.getByTestId("chat-title")).toHaveText(channelName);
|
|
await expect(memberPage.getByTestId("stream-list")).toContainText(
|
|
channelName,
|
|
);
|
|
|
|
await expect(memberPage.getByTestId("message-input")).toBeEnabled();
|
|
|
|
if (lastSeed) {
|
|
await expectTimelineToContain(memberPage, lastSeed);
|
|
const metrics = await getTimelineMetrics(memberPage);
|
|
expect(metrics.scrollHeight).toBeGreaterThan(
|
|
metrics.clientHeight +
|
|
metrics.composerHeight +
|
|
(seed?.minDistance ?? 160),
|
|
);
|
|
}
|
|
}
|
|
|
|
async function sendChannelMessage(
|
|
page: Page,
|
|
{
|
|
channelName,
|
|
content,
|
|
mentionPubkeys,
|
|
}: {
|
|
channelName: string;
|
|
content: string;
|
|
mentionPubkeys?: string[];
|
|
},
|
|
) {
|
|
await page.waitForFunction(
|
|
() => {
|
|
const tauriWindow = window as Window & {
|
|
__TAURI_INTERNALS__?: { invoke?: unknown };
|
|
};
|
|
|
|
return typeof tauriWindow.__TAURI_INTERNALS__?.invoke === "function";
|
|
},
|
|
null,
|
|
{ timeout: 5_000 },
|
|
);
|
|
|
|
await page.evaluate(
|
|
async ({ channelName: targetChannelName, content, mentionPubkeys }) => {
|
|
const tauriWindow = window as Window & {
|
|
__TAURI_INTERNALS__?: {
|
|
invoke: (
|
|
command: string,
|
|
payload?: Record<string, unknown>,
|
|
) => Promise<unknown>;
|
|
};
|
|
};
|
|
|
|
const invoke = tauriWindow.__TAURI_INTERNALS__?.invoke;
|
|
if (!invoke) {
|
|
throw new Error("Tauri invoke bridge is unavailable.");
|
|
}
|
|
|
|
const payload = (await invoke("get_channels")) as {
|
|
channels: Array<{ id: string; name: string }> | null;
|
|
};
|
|
const channels = payload.channels ?? [];
|
|
const channel = channels.find(({ name }) => name === targetChannelName);
|
|
if (!channel) {
|
|
throw new Error(`Channel not found: ${targetChannelName}`);
|
|
}
|
|
|
|
await invoke("send_channel_message", {
|
|
channelId: channel.id,
|
|
content,
|
|
kind: null,
|
|
mediaTags: null,
|
|
mentionPubkeys: mentionPubkeys ?? null,
|
|
parentEventId: null,
|
|
});
|
|
},
|
|
{ channelName, content, mentionPubkeys },
|
|
);
|
|
}
|
|
|
|
async function scrollTimelineAwayFromBottom(page: Page, minDistance = 160) {
|
|
const timeline = page.getByTestId("message-timeline");
|
|
await timeline.hover();
|
|
|
|
for (let attempt = 0; attempt < 8; attempt += 1) {
|
|
await page.mouse.wheel(0, -800);
|
|
const metrics = await getTimelineMetrics(page);
|
|
if (metrics.distanceFromBottom > minDistance) {
|
|
// The DOM scroll position is now off the bottom, but the timeline's
|
|
// `onScroll` handler updates the React "away from bottom" anchor state
|
|
// asynchronously. If a new message lands before that commit, the stale
|
|
// at-bottom anchor swallows it and the unread counter never increments.
|
|
// The scroll-to-latest pill only mounts once that state has committed,
|
|
// so waiting for it guarantees the anchor is in the away-from-bottom
|
|
// branch before callers send the message they expect to be counted.
|
|
await expect(page.getByTestId("message-scroll-to-latest")).toBeVisible();
|
|
return metrics.distanceFromBottom;
|
|
}
|
|
}
|
|
|
|
throw new Error("Failed to scroll the timeline away from the bottom.");
|
|
}
|
|
|
|
test.beforeAll(async () => {
|
|
test.setTimeout(relaySeedHookTimeoutMs);
|
|
await assertRelaySeeded();
|
|
});
|
|
|
|
test("loads channels from the relay", async ({ page }) => {
|
|
await installRelayBridge(page, "tyler");
|
|
await page.goto("/");
|
|
|
|
await expect(page.getByTestId("stream-list")).toContainText("general");
|
|
await expect(page.getByTestId("stream-list")).toContainText("random");
|
|
await expect(page.getByTestId("forum-list")).toContainText("watercooler");
|
|
await expect(page.getByTestId("dm-list")).toContainText("alice-tyler");
|
|
});
|
|
|
|
test("loads the home feed from the relay", async ({ browser }) => {
|
|
const message = `Relay home mention ${Date.now()}`;
|
|
const targetContext = await browser.newContext();
|
|
const senderContext = await browser.newContext();
|
|
const page = await targetContext.newPage();
|
|
const senderPage = await senderContext.newPage();
|
|
|
|
try {
|
|
await installRelayBridge(page, "tyler");
|
|
await installRelayBridge(senderPage, "alice");
|
|
await page.goto("/");
|
|
await senderPage.goto("/");
|
|
|
|
await expect(page.getByTestId("home-inbox")).toBeVisible();
|
|
await expect(page.getByTestId("home-inbox-list")).toBeVisible();
|
|
|
|
await sendChannelMessage(senderPage, {
|
|
channelName: "general",
|
|
content: message,
|
|
mentionPubkeys: [TEST_IDENTITIES.tyler.pubkey],
|
|
});
|
|
|
|
await expect(page.getByTestId("home-inbox-list")).toContainText(message);
|
|
await expect(page.getByTestId("home-inbox-detail")).toBeVisible();
|
|
} finally {
|
|
await targetContext.close();
|
|
await senderContext.close();
|
|
}
|
|
});
|
|
|
|
test("shows sent inbox replies immediately in the inbox detail pane", async ({
|
|
browser,
|
|
}) => {
|
|
const message = `Relay inbox reply target ${Date.now()}`;
|
|
const reply = `Inbox reply ${Date.now()}`;
|
|
const targetContext = await browser.newContext();
|
|
const senderContext = await browser.newContext();
|
|
const page = await targetContext.newPage();
|
|
const senderPage = await senderContext.newPage();
|
|
|
|
try {
|
|
await installRelayBridge(page, "tyler");
|
|
await installRelayBridge(senderPage, "alice");
|
|
await page.goto("/");
|
|
await senderPage.goto("/");
|
|
|
|
await sendChannelMessage(senderPage, {
|
|
channelName: "general",
|
|
content: message,
|
|
mentionPubkeys: [TEST_IDENTITIES.tyler.pubkey],
|
|
});
|
|
|
|
await page.getByTestId("home-inbox-list").getByText(message).click();
|
|
await expect(page.getByTestId("home-inbox-detail")).toBeVisible();
|
|
await expect(page.getByTestId("message-input")).toBeEnabled();
|
|
|
|
await page.getByTestId("message-input").fill(reply);
|
|
await page.getByTestId("send-message").click();
|
|
|
|
await expect(page.getByTestId("home-inbox-detail")).toContainText(reply);
|
|
} finally {
|
|
await targetContext.close();
|
|
await senderContext.close();
|
|
}
|
|
});
|
|
|
|
test("creates a relay-backed stream", async ({ page }) => {
|
|
const channelName = `desktop-e2e-${Date.now()}`;
|
|
|
|
await installRelayBridge(page, "tyler");
|
|
await page.goto("/");
|
|
await openCreateChannelDialog(page);
|
|
await page.getByTestId("create-channel-name").fill(channelName);
|
|
await page
|
|
.getByTestId("create-channel-description")
|
|
.fill("Created from Playwright");
|
|
await page.getByTestId("create-channel-submit").click();
|
|
|
|
await expect(page.getByTestId("stream-list")).toContainText(channelName);
|
|
await expect(page.getByTestId("chat-title")).toHaveText(channelName);
|
|
});
|
|
|
|
test("sends a message through the real relay", async ({ page }) => {
|
|
const message = `Integration message ${Date.now()}`;
|
|
|
|
await installRelayBridge(page, "tyler");
|
|
await page.goto("/");
|
|
await page.getByTestId("channel-general").click();
|
|
await expect(page.getByTestId("chat-title")).toHaveText("general");
|
|
await page.getByTestId("message-input").fill(message);
|
|
await page.getByTestId("send-message").click();
|
|
|
|
await expectTimelineToContain(page, message);
|
|
});
|
|
|
|
test("delivers a message to a second browser context in real time", async ({
|
|
browser,
|
|
}: {
|
|
browser: Browser;
|
|
}) => {
|
|
const channelName = `realtime-shared-${Date.now()}`;
|
|
const contextOne = await browser.newContext();
|
|
const contextTwo = await browser.newContext();
|
|
const pageOne = await contextOne.newPage();
|
|
const pageTwo = await contextTwo.newPage();
|
|
const message = `Realtime message ${Date.now()}`;
|
|
|
|
try {
|
|
await installRelayBridge(pageOne, "tyler");
|
|
await installRelayBridge(pageTwo, "alice");
|
|
|
|
await pageOne.goto("/");
|
|
await pageTwo.goto("/");
|
|
await createAndJoinSharedStream(pageOne, pageTwo, channelName);
|
|
|
|
await pageOne.getByTestId("message-input").fill(message);
|
|
await pageOne.getByTestId("send-message").click();
|
|
|
|
await expectTimelineToContain(pageTwo, message);
|
|
} finally {
|
|
await contextOne.close();
|
|
await contextTwo.close();
|
|
}
|
|
});
|
|
|
|
test("stays pinned to the latest message when new messages arrive at the bottom", async ({
|
|
browser,
|
|
}: {
|
|
browser: Browser;
|
|
}) => {
|
|
test.slow();
|
|
|
|
const channelName = `pinned-bottom-${Date.now()}`;
|
|
const contextOne = await browser.newContext();
|
|
const contextTwo = await browser.newContext();
|
|
const pageOne = await contextOne.newPage();
|
|
const pageTwo = await contextTwo.newPage();
|
|
const prefix = `Pinned scroll ${Date.now()}`;
|
|
const incomingMessage = `${prefix} incoming`;
|
|
|
|
try {
|
|
await installRelayBridge(pageOne, "tyler");
|
|
await installRelayBridge(pageTwo, "alice");
|
|
|
|
await pageOne.goto("/");
|
|
await pageTwo.goto("/");
|
|
await createAndJoinSharedStream(pageOne, pageTwo, channelName, { prefix });
|
|
await expect
|
|
.poll(async () => (await getTimelineMetrics(pageTwo)).distanceFromBottom)
|
|
.toBeLessThan(8);
|
|
|
|
await sendChannelMessage(pageOne, {
|
|
channelName,
|
|
content: incomingMessage,
|
|
});
|
|
|
|
await expectTimelineToContain(pageTwo, incomingMessage);
|
|
await expect
|
|
.poll(async () => (await getTimelineMetrics(pageTwo)).distanceFromBottom)
|
|
.toBeLessThan(8);
|
|
await expect(pageTwo.getByTestId("message-scroll-to-latest")).toHaveCount(
|
|
0,
|
|
);
|
|
} finally {
|
|
await contextOne.close();
|
|
await contextTwo.close();
|
|
}
|
|
});
|
|
|
|
test("stays pinned after you send a message and a remote reply arrives right after", async ({
|
|
browser,
|
|
}: {
|
|
browser: Browser;
|
|
}) => {
|
|
test.slow();
|
|
|
|
const channelName = `reply-shared-${Date.now()}`;
|
|
const contextOne = await browser.newContext();
|
|
const contextTwo = await browser.newContext();
|
|
const pageOne = await contextOne.newPage();
|
|
const pageTwo = await contextTwo.newPage();
|
|
const prefix = `Reply after send ${Date.now()}`;
|
|
const localMessage = `${prefix} local`;
|
|
const incomingMessage = `${prefix} incoming`;
|
|
|
|
try {
|
|
await installRelayBridge(pageOne, "tyler");
|
|
await installRelayBridge(pageTwo, "alice");
|
|
|
|
await pageOne.goto("/");
|
|
await pageTwo.goto("/");
|
|
await createAndJoinSharedStream(pageOne, pageTwo, channelName, { prefix });
|
|
await expect
|
|
.poll(async () => (await getTimelineMetrics(pageTwo)).distanceFromBottom)
|
|
.toBeLessThan(8);
|
|
|
|
await pageTwo.getByTestId("message-input").fill(localMessage);
|
|
await pageTwo.getByTestId("send-message").click();
|
|
await expectTimelineToContain(pageTwo, localMessage);
|
|
|
|
await sendChannelMessage(pageOne, {
|
|
channelName,
|
|
content: incomingMessage,
|
|
});
|
|
|
|
await expectTimelineToContain(pageTwo, incomingMessage);
|
|
await expect
|
|
.poll(async () => (await getTimelineMetrics(pageTwo)).distanceFromBottom)
|
|
.toBeLessThan(8);
|
|
await expect(pageTwo.getByTestId("message-scroll-to-latest")).toHaveCount(
|
|
0,
|
|
);
|
|
} finally {
|
|
await contextOne.close();
|
|
await contextTwo.close();
|
|
}
|
|
});
|
|
|
|
test("keeps bottom-pinned scrolling after the composer grows", async ({
|
|
browser,
|
|
}: {
|
|
browser: Browser;
|
|
}) => {
|
|
test.slow();
|
|
|
|
const channelName = `composer-shared-${Date.now()}`;
|
|
const contextOne = await browser.newContext();
|
|
const contextTwo = await browser.newContext();
|
|
const pageOne = await contextOne.newPage();
|
|
const pageTwo = await contextTwo.newPage();
|
|
const prefix = `Composer pinned ${Date.now()}`;
|
|
const incomingMessage = `${prefix} incoming`;
|
|
const receiverInput = pageTwo.getByTestId("message-input");
|
|
|
|
try {
|
|
await installRelayBridge(pageOne, "tyler");
|
|
await installRelayBridge(pageTwo, "alice");
|
|
|
|
await pageOne.goto("/");
|
|
await pageTwo.goto("/");
|
|
await createAndJoinSharedStream(pageOne, pageTwo, channelName, { prefix });
|
|
await expect
|
|
.poll(async () => (await getTimelineMetrics(pageTwo)).distanceFromBottom)
|
|
.toBeLessThan(8);
|
|
|
|
await receiverInput.fill("Composer pinned line one");
|
|
await receiverInput.press("Enter");
|
|
await receiverInput.type("Composer pinned line two");
|
|
await receiverInput.press("Enter");
|
|
await receiverInput.type("Composer pinned line three");
|
|
await receiverInput.press("Enter");
|
|
await receiverInput.type("Composer pinned line four");
|
|
|
|
await expect
|
|
.poll(async () => (await getTimelineMetrics(pageTwo)).distanceFromBottom)
|
|
.toBeLessThan(8);
|
|
|
|
await sendChannelMessage(pageOne, {
|
|
channelName,
|
|
content: incomingMessage,
|
|
});
|
|
|
|
await expectTimelineToContain(pageTwo, incomingMessage);
|
|
await expect
|
|
.poll(async () => (await getTimelineMetrics(pageTwo)).distanceFromBottom)
|
|
.toBeLessThan(8);
|
|
await expect(pageTwo.getByTestId("message-scroll-to-latest")).toHaveCount(
|
|
0,
|
|
);
|
|
} finally {
|
|
await contextOne.close();
|
|
await contextTwo.close();
|
|
}
|
|
});
|
|
|
|
test("keeps scroll position when new messages arrive above the fold", async ({
|
|
browser,
|
|
}: {
|
|
browser: Browser;
|
|
}) => {
|
|
test.slow();
|
|
|
|
const channelName = `scroll-shared-${Date.now()}`;
|
|
const contextOne = await browser.newContext();
|
|
const contextTwo = await browser.newContext();
|
|
const pageOne = await contextOne.newPage();
|
|
const pageTwo = await contextTwo.newPage();
|
|
const prefix = `Scroll behavior ${Date.now()}`;
|
|
const incomingMessage = `${prefix} incoming`;
|
|
|
|
try {
|
|
await installRelayBridge(pageOne, "tyler");
|
|
await installRelayBridge(pageTwo, "alice");
|
|
|
|
await pageOne.goto("/");
|
|
await pageTwo.goto("/");
|
|
const minAwayDistance = 80;
|
|
await createAndJoinSharedStream(pageOne, pageTwo, channelName, {
|
|
prefix,
|
|
minDistance: 480,
|
|
});
|
|
await expect
|
|
.poll(async () => (await getTimelineMetrics(pageTwo)).distanceFromBottom)
|
|
.toBeLessThan(8);
|
|
|
|
const distanceBeforeDelivery = await scrollTimelineAwayFromBottom(
|
|
pageTwo,
|
|
minAwayDistance,
|
|
);
|
|
|
|
await sendChannelMessage(pageOne, {
|
|
channelName,
|
|
content: incomingMessage,
|
|
});
|
|
|
|
await expect(pageTwo.getByTestId("message-scroll-to-latest")).toContainText(
|
|
"1 new message",
|
|
);
|
|
await expect
|
|
.poll(async () => (await getTimelineMetrics(pageTwo)).distanceFromBottom)
|
|
.toBeGreaterThanOrEqual(distanceBeforeDelivery - 8);
|
|
|
|
await pageTwo.getByTestId("message-scroll-to-latest").click();
|
|
|
|
await expectTimelineToContain(pageTwo, incomingMessage);
|
|
await expect
|
|
.poll(async () => (await getTimelineMetrics(pageTwo)).distanceFromBottom)
|
|
.toBeLessThan(8);
|
|
} finally {
|
|
await contextOne.close();
|
|
await contextTwo.close();
|
|
}
|
|
});
|