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(channels): keep PR mentions from suspending the composer (#8194)

Peter Chinmanacb2cec8d83c
diff --git a/apps/web/src/lib/core/component/LexicalMarkdown/component/decorator/PullRequestMention.suspense.test.tsx b/apps/web/src/lib/core/component/LexicalMarkdown/component/decorator/PullRequestMention.suspense.test.tsx
new file mode 100644
index 0000000000..966d40c765
--- /dev/null
+++ b/apps/web/src/lib/core/component/LexicalMarkdown/component/decorator/PullRequestMention.suspense.test.tsx
@@ -0,0 +1,159 @@
+import { githubLinkStatusQueryOptions } from '@queries/auth/github-link';
+import type { authServiceClient } from '@service-auth/client';
+import { cleanup, render, screen } from '@solidjs/testing-library';
+import { QueryClient, QueryClientProvider } from '@tanstack/solid-query';
+import { err, ok } from 'neverthrow';
+import { createSignal, Show, Suspense } from 'solid-js';
+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
+
+const { checkGithubLinkStatus } = vi.hoisted(() => ({
+ checkGithubLinkStatus:
+ vi.fn<typeof authServiceClient.checkGithubLinkStatus>(),
+}));
+
+vi.mock('@service-auth/client', () => ({
+ authServiceClient: { checkGithubLinkStatus },
+}));
+vi.mock('@queries/soup/normalized-cache', () => ({
+ invalidateAllSoup: vi.fn(),
+}));
+
+let client: QueryClient;
+vi.mock('@queries/client', () => ({
+ get queryClient() {
+ return client;
+ },
+}));
+
+vi.mock('@components/app/split-layout/layout', () => ({
+ useSplitLayout: () => ({ openWithSplit: vi.fn() }),
+}));
+vi.mock('@core/util/url', () => ({ openExternalUrl: vi.fn() }));
+// PR details stay unresolved so this exercises the stored label independently
+// of the real GitHub connection-status query and its retry lifecycle.
+vi.mock('@queries/storage/pr-mention', () => ({
+ usePrMentionQuery: () => ({ isSuccess: false }),
+ usePullRequestByGithubKeyQuery: () => ({ isSuccess: false }),
+}));
+vi.mock('../../plugins', () => ({ autoRegister: vi.fn() }));
+vi.mock('../../context/LexicalWrapperContext', async () => ({
+ LexicalWrapperContext: (await import('solid-js')).createContext(),
+}));
+
+import { PullRequestMention } from './PullRequestMention';
+
+beforeEach(() => {
+ checkGithubLinkStatus.mockReset();
+ client = new QueryClient({
+ defaultOptions: { queries: { retry: false } },
+ });
+});
+
+afterEach(() => {
+ cleanup();
+ client.clear();
+});
+
+describe('PR mention connection-status suspense', () => {
+ it.each(['linked', 'unlinked', 'error'] as const)(
+ 'keeps the composer and message visible during a retry that ends %s',
+ async (outcome) => {
+ checkGithubLinkStatus.mockResolvedValueOnce(
+ err([{ code: 'HTTP_ERROR', message: 'Connection status unavailable' }])
+ );
+ await expect(
+ client.fetchQuery(githubLinkStatusQueryOptions())
+ ).rejects.toThrow();
+
+ const retry =
+ Promise.withResolvers<
+ Awaited<ReturnType<typeof authServiceClient.checkGithubLinkStatus>>
+ >();
+ checkGithubLinkStatus.mockReturnValueOnce(retry.promise);
+ const [inserted, setInserted] = createSignal(false);
+ const suspended = vi.fn();
+ function HiddenSurface() {
+ suspended();
+ return <span>Hidden surface</span>;
+ }
+
+ render(() => (
+ <QueryClientProvider client={client}>
+ <Suspense fallback={<HiddenSurface />}>
+ <div contentEditable role="textbox" aria-label="Composer">
+ Draft text
+ <Show when={inserted()}>
+ <PullRequestMention
+ id="pr-1"
+ url="https://github.com/macro-inc/macro/pull/7956"
+ label="macro-inc/macro#7956"
+ key="draft"
+ theme={{}}
+ />
+ </Show>
+ </div>
+ </Suspense>
+ <Suspense fallback={<HiddenSurface />}>
+ <Show when={inserted()}>
+ <div data-testid="message">
+ Sent message
+ <PullRequestMention
+ id="pr-1"
+ url="https://github.com/macro-inc/macro/pull/7956"
+ label="macro-inc/macro#7956"
+ key="sent"
+ theme={{}}
+ />
+ </div>
+ </Show>
+ </Suspense>
+ </QueryClientProvider>
+ ));
+ const composer = screen.getByRole('textbox');
+ composer.focus();
+ setInserted(true);
+
+ expect(checkGithubLinkStatus).toHaveBeenCalledTimes(2);
+ expect(screen.getByRole('textbox')).toBe(composer);
+ expect(document.activeElement).toBe(composer);
+ expect(screen.getByTestId('message').textContent).toContain(
+ 'macro-inc/macro#7956'
+ );
+ expect(suspended).not.toHaveBeenCalled();
+
+ const response =
+ outcome === 'linked'
+ ? ok({
+ github_user_id: '123',
+ github_username: 'macro-user',
+ reauthentication_required: false,
+ })
+ : err([
+ {
+ code: outcome === 'unlinked' ? 'NOT_FOUND' : 'HTTP_ERROR',
+ message: 'Connection status unavailable',
+ } as const,
+ ]);
+ const settled = client.fetchQuery(githubLinkStatusQueryOptions());
+ retry.resolve(response);
+ if (outcome === 'error') {
+ await expect(settled).rejects.toThrow();
+ } else {
+ await settled;
+ }
+ // Solid Query delivers observer updates through a queued resource refetch.
+ await new Promise<void>((resolve) => queueMicrotask(resolve));
+
+ expect(screen.getByRole('textbox')).toBe(composer);
+ expect(screen.getByTestId('message')).toBeDefined();
+ expect(suspended).not.toHaveBeenCalled();
+ expect(composer.querySelector('[data-pr-mention]') !== null).toBe(
+ outcome !== 'unlinked'
+ );
+ expect(
+ screen.getByTestId('message').querySelector('[data-pr-mention]') !==
+ null
+ ).toBe(outcome !== 'unlinked');
+ }
+ );
+});
diff --git a/apps/web/src/lib/core/component/LexicalMarkdown/component/decorator/PullRequestMention.test.tsx b/apps/web/src/lib/core/component/LexicalMarkdown/component/decorator/PullRequestMention.test.tsx
index f45e3bc5d9..e3cb79d8cf 100644
--- a/apps/web/src/lib/core/component/LexicalMarkdown/component/decorator/PullRequestMention.test.tsx
+++ b/apps/web/src/lib/core/component/LexicalMarkdown/component/decorator/PullRequestMention.test.tsx
@@ -80,8 +80,8 @@ const githubKeyQuery = {
},
};
const githubLinkStatusQuery = {
- get isFetched() {
- return true;
+ get isPending() {
+ return false;
},
get data() {
return { status: githubLinkStatus() };
diff --git a/apps/web/src/lib/core/component/LexicalMarkdown/component/decorator/PullRequestMention.tsx b/apps/web/src/lib/core/component/LexicalMarkdown/component/decorator/PullRequestMention.tsx
index 196f6c31ec..a2e82804af 100644
--- a/apps/web/src/lib/core/component/LexicalMarkdown/component/decorator/PullRequestMention.tsx
+++ b/apps/web/src/lib/core/component/LexicalMarkdown/component/decorator/PullRequestMention.tsx
@@ -24,6 +24,7 @@ import ChatCircle from '@phosphor/chat-circle.svg';
import GitMerge from '@phosphor/git-merge.svg';
import GitPullRequest from '@phosphor/git-pull-request.svg';
import { useGithubLinkStatusQuery } from '@queries/auth/github-link';
+import { queryReadyGate } from '@queries/gate';
import {
usePrMentionQuery,
usePullRequestByGithubKeyQuery,
@@ -554,7 +555,6 @@ export function PullRequestMention(props: PullRequestMentionDecoratorProps) {
const githubLinkQuery = useGithubLinkStatusQuery({
enabled: () => !lexicalWrapper?.skipPreviewFetch,
});
- const isGithubLinked = () => githubLinkQuery.data?.status === 'linked';
const isSelectedAsNode = () => {
const sel = selection();
@@ -571,7 +571,13 @@ export function PullRequestMention(props: PullRequestMentionDecoratorProps) {
// When GitHub is not linked, render as a plain link instead of the fancy mention UI
const shouldRenderAsPlainLink = () => {
if (lexicalWrapper?.skipPreviewFetch) return false;
- return !!(githubLinkQuery.isFetched && !isGithubLinked() && props.url);
+ // A failed query is still "fetched" while its next mount retries it.
+ // Reading its pending data would suspend the surrounding composer/message.
+ return !!(
+ props.url &&
+ queryReadyGate(githubLinkQuery) &&
+ githubLinkQuery.data.status !== 'linked'
+ );
};
const open = (e: MouseEvent | KeyboardEvent | null) => {
diff --git a/docs/agent-guide/channels.md b/docs/agent-guide/channels.md
index 6ce3259038..5a577d9983 100644
--- a/docs/agent-guide/channels.md
+++ b/docs/agent-guide/channels.md
@@ -599,6 +599,11 @@ On a cold channel open, verify that delayed bot/agent mention requests leave the
messages and composer visible. Expand a thread while its replies are still
loading: existing preview replies should remain visible until the full list
arrives. Repeat after reopening the channel to cover both cold and cached data.
+For PR mentions, also fail a GitHub connection-status request, then paste a
+mention while the retry is held pending. The composer must stay visible and
+focused, and messages containing PR mentions must render immediately. Resolve
+the retry as linked, unlinked, or failed: none should hide the surrounding UI;
+only a confirmed unlinked/reauthentication status changes the chip to a link.
Scrolling a collapsed thread into view must keep its timeline preview unchanged,
without fetching or revealing the full reply list. Cached replies from a previous
expansion must not enlarge that preview either. Explicit expansion, replying,