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(email): Draft scroll bug (#1378)

Evan Hutnik224f8ef2ac46
diff --git a/js/app/packages/block-email/component/BaseInput.tsx b/js/app/packages/block-email/component/BaseInput.tsx
index c6d79be823..0534cd3a16 100644
--- a/js/app/packages/block-email/component/BaseInput.tsx
+++ b/js/app/packages/block-email/component/BaseInput.tsx
@@ -98,7 +98,11 @@ import {
} from '../util/prepareEmailBody';
import { convertEmailRecipientToContactInfo } from '../util/recipientConversion';
import { getReplyTypeFromDraft } from '../util/replyType';
-import { type EmailRecipient, useEmailContext } from './EmailContext';
+import {
+ type EmailRecipient,
+ markThreadDraftSaved,
+ useEmailContext,
+} from './EmailContext';
import { getOrInitEmailFormContext } from './EmailFormContext';
import {
useRemoveDraftAttachmentMutation,
@@ -392,7 +396,10 @@ export function BaseInput(props: {
const deleteDraftMutation = useDeleteDraftMutation();
function refetchThreadMessages() {
- ctx.query.refetch();
+ const threadId = ctx.thread()?.db_id;
+ if (threadId) {
+ markThreadDraftSaved(threadId);
+ }
}
// Attach side-effect handlers on mount; they replay against current state
diff --git a/js/app/packages/block-email/component/EmailContext.tsx b/js/app/packages/block-email/component/EmailContext.tsx
index 7bb43ed2f9..b33e25641e 100644
--- a/js/app/packages/block-email/component/EmailContext.tsx
+++ b/js/app/packages/block-email/component/EmailContext.tsx
@@ -25,6 +25,8 @@ import {
useArchiveThreadMutation,
useThreadQuery,
} from '@queries/email/thread';
+import { emailKeys } from '@queries/email/keys';
+import { queryClient } from '@queries/client';
import type {
APIThread,
ContactInfo,
@@ -38,12 +40,25 @@ import {
createMemo,
createSignal,
type FlowProps,
+ onCleanup,
Suspense,
untrack,
useContext,
} from 'solid-js';
import { createStore } from 'solid-js/store';
+/**
+ * Tracks thread IDs that had a draft saved since the last query fetch.
+ * When the EmailProvider unmounts, threads in this set have their query
+ * cache cleared so the next visit fetches fresh data (with the draft).
+ * This avoids touching the active query during draft save, which would
+ * trigger Suspense DOM detach and reset scroll position.
+ */
+const draftSavedThreadIds = new Set<string>();
+export function markThreadDraftSaved(threadId: string) {
+ draftSavedThreadIds.add(threadId);
+}
+
export type EmailRecipient = WithCustomUserInput<'user' | 'contact'>;
export type EmailContextValues = {
@@ -431,6 +446,21 @@ export function EmailProvider(props: FlowProps<{ threadID: string }>) {
});
};
+ // When the provider unmounts (user navigates away), clear the thread query
+ // cache if a draft was saved during this session. This ensures the next visit
+ // fetches fresh data from the server (which includes the saved draft).
+ // We can't invalidate/refetch while mounted because any query state change
+ // triggers SolidQuery's createClientSubscriber → Resource.refetch() → Suspense
+ // DOM detach, which resets scroll position.
+ onCleanup(() => {
+ if (draftSavedThreadIds.has(props.threadID)) {
+ draftSavedThreadIds.delete(props.threadID);
+ queryClient.removeQueries({
+ queryKey: emailKeys.threadMessages(props.threadID).queryKey,
+ });
+ }
+ });
+
return (
<Suspense>
<EmailContext.Provider