Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

fix(md): stop draft comment flashing when dismissed by clicking outside (#6863)

gbirmanb626052d8165
diff --git a/apps/web/src/lib/core/comments/MinimizedThreads.tsx b/apps/web/src/lib/core/comments/MinimizedThreads.tsx
index 7bed7db8d7..b5a9285f95 100644
--- a/apps/web/src/lib/core/comments/MinimizedThreads.tsx
+++ b/apps/web/src/lib/core/comments/MinimizedThreads.tsx
@@ -122,7 +122,14 @@ export function MinimizedThread(props: {
document's scroll and clipping like the badge it opens from. */}
<Popover
open={expanded()}
- onOpenChange={setExpanded}
+ onOpenChange={(open) => {
+ setExpanded(open);
+ // Discard a dismissed draft in the same tick; waiting for the
+ // editor's selection change paints its badge and highlight a frame.
+ // A thread activated by the same press keeps its selection.
+ if (!open && props.comment.isNew && props.isActive)
+ setActiveThread(null);
+ }}
anchorRef={badge}
placement="left-start"
gutter={4}
diff --git a/apps/web/src/lib/core/comments/Thread.test.tsx b/apps/web/src/lib/core/comments/Thread.test.tsx
index 0db1dc7175..900952ee85 100644
--- a/apps/web/src/lib/core/comments/Thread.test.tsx
+++ b/apps/web/src/lib/core/comments/Thread.test.tsx
@@ -278,6 +278,47 @@ describe('anchored comment links', () => {
);
});
+ it.each([
+ [true, 'discards a draft as soon as a press outside dismisses it'],
+ [false, 'keeps a thread the dismissing press activated'],
+ ])('%#: %s', async (isActive) => {
+ const setActiveThread = vi.fn();
+ const view = render(() => (
+ <CommentsContext.Provider
+ value={{
+ documentId: 'document',
+ documentType: 'md',
+ canComment: () => true,
+ isDocumentOwner: () => true,
+ highlightedCommentId: () => null,
+ setActiveThread,
+ setThreadHeight: () => {},
+ getCommentById: () => undefined,
+ ownedComment: () => false,
+ inComment: true,
+ commentOperations: noopCommentOperations,
+ messageOperations: { createComment: async () => null },
+ }}
+ >
+ <MinimizedThread
+ comment={{ ...comment, isNew: true }}
+ layout={{ calculatedYPos: 0 }}
+ isActive={isActive}
+ />
+ </CommentsContext.Provider>
+ ));
+ await new Promise((resolve) => setTimeout(resolve));
+ fireEvent.pointerDown(document.body);
+ await waitFor(() =>
+ expect(
+ view.container.ownerDocument
+ .querySelector('[data-comment-thread]')!
+ .parentElement!.hasAttribute('data-expanded')
+ ).toBe(false)
+ );
+ expect(setActiveThread.mock.calls).toEqual(isActive ? [[null]] : []);
+ });
+
it.each(['md', 'task', 'snippet', 'skill', 'pdf'] as const)(
'copies legacy %s root and reply links without a block provider',
async (documentType) => {