diff --git a/apps/mail/components/create/email-composer.tsx b/apps/mail/components/create/email-composer.tsx index 6985b27ff0..559d53f631 100644 --- a/apps/mail/components/create/email-composer.tsx +++ b/apps/mail/components/create/email-composer.tsx @@ -107,8 +107,7 @@ export function EmailComposer({ const [isComposeOpen, setIsComposeOpen] = useQueryState('isComposeOpen'); const { data: emailData } = useThread(threadId ?? null); const { data: session } = useSession(); - const [urlDraftId] = useQueryState('draftId'); - const [draftId, setDraftId] = useState(urlDraftId ?? null); + const [draftId, setDraftId] = useQueryState('draftId'); const [aiGeneratedMessage, setAiGeneratedMessage] = useState(null); const [aiIsLoading, setAiIsLoading] = useState(false); const [isGeneratingSubject, setIsGeneratingSubject] = useState(false); @@ -341,24 +340,6 @@ export function EmailComposer({ } }; - // It needs to be done this way so that react doesn't catch on to the state change - // and we can still refresh to get the latest draft for the reply. - const setDraftIdQueryParam = (draftId: string | null) => { - const url = new URL(window.location.href); - - // mutate only one key - draftId == null ? url.searchParams.delete('draftId') : url.searchParams.set('draftId', draftId); - - // keep Next's internal state intact and update its mirrors - const nextState = { - ...window.history.state, // preserves __NA / _N etc. - as: url.pathname + url.search, - url: url.pathname + url.search, - }; - setDraftId(draftId); - window.history.replaceState(nextState, '', url); - }; - const saveDraft = async () => { const values = getValues(); @@ -383,7 +364,7 @@ export function EmailComposer({ const response = await createDraft(draftData); if (response?.id && response.id !== draftId) { - setDraftIdQueryParam(response.id); + setDraftId(response.id); } } catch (error) { console.error('Error saving draft:', error); @@ -403,12 +384,6 @@ export function EmailComposer({ setIsGeneratingSubject(false); }; - useEffect(() => { - if (urlDraftId !== draftId) { - setDraftId(urlDraftId ?? null); - } - }, [urlDraftId]); - useEffect(() => { if (!hasUnsavedChanges) return; diff --git a/apps/mail/components/mail/reply-composer.tsx b/apps/mail/components/mail/reply-composer.tsx index 1c1cc06fcf..18e1281390 100644 --- a/apps/mail/components/mail/reply-composer.tsx +++ b/apps/mail/components/mail/reply-composer.tsx @@ -202,11 +202,6 @@ export default function ReplyCompose({ messageId }: ReplyComposeProps) { if (!mode || !emailData) return null; - if (draftId && isDraftLoading) { - // wait for the draft if requesting one - return null; - } - return (