Skip to content

Commit c0ca4f8

Browse files
committed
🤖 fix: simulate user scroll to disable auto-scroll in storybook
1 parent da7df6d commit c0ca4f8

File tree

1 file changed

+27
-4
lines changed

1 file changed

+27
-4
lines changed

src/browser/stories/App.chat.stories.tsx

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -491,11 +491,34 @@ export const AutoCompactWarning: AppStory = {
491491
canvas.getByText(/access token expires in 15 minutes/);
492492
});
493493

494-
// Wait a bit for auto-scroll to settle, then scroll up
495-
await new Promise((r) => setTimeout(r, 100));
496-
const messageWindow = canvasElement.querySelector('[data-testid="message-window"]');
494+
// Wait for initial auto-scroll and all ResizeObserver callbacks to complete
495+
await new Promise((r) => setTimeout(r, 500));
496+
497+
const messageWindow = canvasElement.querySelector(
498+
'[data-testid="message-window"]'
499+
) as HTMLElement | null;
497500
if (messageWindow) {
498-
messageWindow.scrollTop = messageWindow.scrollHeight - messageWindow.clientHeight - 150;
501+
// Simulate user scroll interaction multiple times to ensure auto-scroll is disabled.
502+
// The useAutoScroll hook only processes scroll as "user-initiated" if it happens
503+
// within 100ms of a wheel/touch event. We need to:
504+
// 1. Mark user interaction via wheel event
505+
// 2. Scroll up (which disables auto-scroll)
506+
// 3. Wait and repeat to ensure the state sticks
507+
for (let i = 0; i < 3; i++) {
508+
messageWindow.dispatchEvent(new WheelEvent("wheel", { bubbles: true, deltaY: -100 }));
509+
// Scroll to show ~200px of content above the input area
510+
const targetScroll = Math.max(0, messageWindow.scrollHeight - messageWindow.clientHeight - 200);
511+
messageWindow.scrollTop = targetScroll;
512+
messageWindow.dispatchEvent(new Event("scroll", { bubbles: true }));
513+
await new Promise((r) => setTimeout(r, 50));
514+
}
515+
516+
// Final wait to let any pending ResizeObserver callbacks fire and see disabled auto-scroll
517+
await new Promise((r) => setTimeout(r, 200));
518+
519+
// Set final scroll position
520+
const finalScroll = Math.max(0, messageWindow.scrollHeight - messageWindow.clientHeight - 200);
521+
messageWindow.scrollTop = finalScroll;
499522
}
500523
},
501524
parameters: {

0 commit comments

Comments
 (0)