Skip to content

The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:

GDGT-3141 [Flaky Test]: should render saved top level blocks (#80614)

Kamil Mielnik5f8ff144924f
diff --git a/e2e/test/scenarios/documents/comments.cy.spec.ts b/e2e/test/scenarios/documents/comments.cy.spec.ts
index 4c5318cf0d0..8ddfc2c4a4f 100644
--- a/e2e/test/scenarios/documents/comments.cy.spec.ts
+++ b/e2e/test/scenarios/documents/comments.cy.spec.ts
@@ -1381,23 +1381,30 @@ describe("document comments", () => {
cy.realType("> blockquote");
cy.realPress([META_KEY, "Enter"]);
+ Comments.getAllComments().should("have.length", 1);
Comments.getNewThreadInput().type("1. ol");
cy.realPress("Enter");
cy.realType("two");
cy.realPress([META_KEY, "Enter"]);
+ Comments.getAllComments().should("have.length", 2);
Comments.getNewThreadInput().type("- ul");
cy.realPress("Enter");
cy.realType("b");
cy.realPress([META_KEY, "Enter"]);
+ Comments.getAllComments().should("have.length", 3);
Comments.getNewThreadInput().type("```");
cy.realPress("Enter");
cy.realType("code");
cy.realPress([META_KEY, "Enter"]);
+ Comments.getAllComments().should("have.length", 4);
+ cy.intercept("GET", "/api/document/*").as("reloadedDocument");
+ cy.intercept("GET", "/api/comment?*").as("reloadedComments");
cy.reload();
+ cy.wait(["@reloadedDocument", "@reloadedComments"]);
H.getBlockquote("blockquote", Comments.getSidebar()).should("be.visible");
H.getOrderedList("ol", Comments.getSidebar()).should("be.visible");
diff --git a/frontend/src/metabase/comments/components/CommentEditor/CommentEditor.tsx b/frontend/src/metabase/comments/components/CommentEditor/CommentEditor.tsx
index b48000ac75e..3ac99fa74e7 100644
--- a/frontend/src/metabase/comments/components/CommentEditor/CommentEditor.tsx
+++ b/frontend/src/metabase/comments/components/CommentEditor/CommentEditor.tsx
@@ -8,7 +8,13 @@ import {
useEditor,
} from "@tiptap/react";
import cx from "classnames";
-import { type KeyboardEventHandler, useEffect, useMemo, useState } from "react";
+import {
+ type KeyboardEventHandler,
+ useEffect,
+ useMemo,
+ useRef,
+ useState,
+} from "react";
import { t } from "ttag";
import CS from "metabase/css/core/index.css";
@@ -68,6 +74,7 @@ export const CommentEditor = ({
}: Props) => {
const siteUrl = useSelector((state) => getSetting(state, "site-url"));
const [content, setContent] = useState<string | null>(null);
+ const initialAutoFocusRef = useRef(autoFocus);
const extensions = useMemo(
() =>
@@ -121,7 +128,8 @@ export const CommentEditor = ({
{
extensions,
content: initialContent || "",
- autofocus: autoFocus,
+ // do not recreate the editor when autoFocus changes to prevent clearing its contents
+ autofocus: initialAutoFocusRef.current,
editable: !readonly,
immediatelyRender: true,
onUpdate: ({ editor }) => {
@@ -139,7 +147,7 @@ export const CommentEditor = ({
}
},
},
- [readonly, autoFocus],
+ [readonly],
);
useEffect(() => {