Skip to content

Commit 0f368c1

Browse files
committed
fix clear
1 parent 11564ce commit 0f368c1

File tree

2 files changed

+10
-23
lines changed

2 files changed

+10
-23
lines changed

packages/browser-repl/src/components/shell-output.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,12 @@ export const ShellOutput = ({
1818
const listRef: VirtualListRef = useRef();
1919

2020
useEffect(() => {
21-
listRef.current?.resetAfterIndex(0);
22-
listRef.current?.scrollToItem(output.length - 1, 'end');
21+
const lastIndex = output.length - 1;
22+
listRef.current?.resetAfterIndex(lastIndex);
23+
const timeout = setTimeout(() => {
24+
listRef.current?.scrollToItem(lastIndex, 'end');
25+
}, 100);
26+
return () => clearTimeout(timeout);
2327
}, [output]);
2428

2529
return (

packages/browser-repl/src/components/shell.tsx

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import {
1414
fontFamilies,
1515
useDarkMode,
1616
cx,
17-
rafraf,
1817
} from '@mongodb-js/compass-components';
1918
import type {
2019
Runtime,
@@ -434,14 +433,6 @@ const _Shell: ForwardRefRenderFunction<EditorRef | null, ShellProps> = (
434433
editorRef.current = editor;
435434
}, []);
436435

437-
const scrollToBottom = useCallback(() => {
438-
if (!shellInputContainerRef.current) {
439-
return;
440-
}
441-
442-
shellInputContainerRef.current.scrollIntoView();
443-
}, [shellInputContainerRef]);
444-
445436
const onShellClicked = useCallback(
446437
(event: React.MouseEvent): void => {
447438
// Focus on input when clicking the shell background (not clicking output).
@@ -473,14 +464,6 @@ const _Shell: ForwardRefRenderFunction<EditorRef | null, ShellProps> = (
473464
}
474465
}, [onInput, updateShellPrompt]);
475466

476-
useEffect(() => {
477-
rafraf(() => {
478-
// Scroll to the bottom every time we render so the input/output will be
479-
// in view.
480-
scrollToBottom();
481-
});
482-
});
483-
484467
const listInnerContainerRef = useRef<HTMLDivElement | null>(null);
485468
const setInnerContainerRef = useCallback((ref: HTMLDivElement) => {
486469
listInnerContainerRef.current = ref;
@@ -494,7 +477,7 @@ const _Shell: ForwardRefRenderFunction<EditorRef | null, ShellProps> = (
494477
return;
495478
}
496479
const observer = new ResizeObserver(([list]) => {
497-
rafraf(() => {
480+
requestAnimationFrame(() => {
498481
setVirtualListInnerHeight(list.contentRect.height);
499482
});
500483
});
@@ -508,8 +491,8 @@ const _Shell: ForwardRefRenderFunction<EditorRef | null, ShellProps> = (
508491
if (!shellInputContainerRef.current) {
509492
return;
510493
}
511-
const observer = new ResizeObserver(([list]) => {
512-
setInputEditorHeight(list.contentRect.height);
494+
const observer = new ResizeObserver(([input]) => {
495+
setInputEditorHeight(input.contentRect.height);
513496
});
514497
observer.observe(shellInputContainerRef.current);
515498
return () => {
@@ -540,7 +523,7 @@ const _Shell: ForwardRefRenderFunction<EditorRef | null, ShellProps> = (
540523
// container, we will set it to the height of the container minus
541524
// the height of the input editor.
542525
height: `min(calc(100% - ${inputEditorHeight}px), ${Math.max(
543-
virtualListInnerHeight,
526+
(output ?? []).length > 0 ? virtualListInnerHeight : 1,
544527
1
545528
)}px)`,
546529
}}

0 commit comments

Comments
 (0)