Skip to content

Commit f53315a

Browse files
committed
fix(web): keep the timeline still when the resting composer expands
1 parent c14f601 commit f53315a

1 file changed

Lines changed: 25 additions & 9 deletions

File tree

‎apps/web/src/components/ComposerPromptEditorTiptap.tsx‎

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -725,6 +725,19 @@ function ComposerPromptEditorTiptapInner(props: ComposerPromptEditorProps) {
725725
);
726726
}, []);
727727

728+
const editorAttributes = useMemo(
729+
() => ({
730+
class: cn(
731+
"composer-tiptap block max-h-50 min-h-17.5 w-full overflow-y-auto whitespace-pre-wrap wrap-break-word bg-transparent leading-relaxed text-foreground focus:outline-none",
732+
className,
733+
),
734+
"data-testid": "composer-editor",
735+
"data-composer-rich-text": richText ? "true" : "false",
736+
"aria-placeholder": placeholder,
737+
}),
738+
[className, placeholder, richText],
739+
);
740+
728741
const editor = useEditor(
729742
{
730743
extensions: [
@@ -787,15 +800,7 @@ function ComposerPromptEditorTiptapInner(props: ComposerPromptEditorProps) {
787800
),
788801
editable: !disabled,
789802
editorProps: {
790-
attributes: {
791-
class: cn(
792-
"composer-tiptap block max-h-50 min-h-17.5 w-full overflow-y-auto whitespace-pre-wrap wrap-break-word bg-transparent leading-relaxed text-foreground focus:outline-none",
793-
className,
794-
),
795-
"data-testid": "composer-editor",
796-
"data-composer-rich-text": richText ? "true" : "false",
797-
"aria-placeholder": placeholder,
798-
},
803+
attributes: editorAttributes,
799804
handleKeyDown: (view, event) => {
800805
if (
801806
isMacPlatform(navigator.platform) &&
@@ -995,6 +1000,17 @@ function ComposerPromptEditorTiptapInner(props: ComposerPromptEditorProps) {
9951000
editorHolder.current = editor;
9961001
}, [editor]);
9971002

1003+
// Tiptap forwards option changes to the view from a passive effect, so a
1004+
// class change here would reach the ProseMirror element one tick after
1005+
// React commits. The chat composer measures its resting and expanded
1006+
// geometry in layout effects that run first, and it clamps the prompt
1007+
// through `className`, so the attributes are pushed to the view here for
1008+
// those measurements to see the layout they are about to reserve for.
1009+
useLayoutEffect(() => {
1010+
if (!editor?.isInitialized) return;
1011+
editor.view.setProps({ attributes: editorAttributes });
1012+
}, [editor, editorAttributes]);
1013+
9981014
const readSnapshot = useCallback(() => {
9991015
const snapshot = snapshotRef.current;
10001016
if (!editor) return snapshot;

0 commit comments

Comments
 (0)