Skip to content

Emails: Add button to send emails synchronously. - #88

Draft
isabellalam12 wants to merge 1 commit into
08-24-emails-remove-defaultsfrom
08-24-emails-add-sync-button
Draft

Emails: Add button to send emails synchronously.#88
isabellalam12 wants to merge 1 commit into
08-24-emails-remove-defaultsfrom
08-24-emails-add-sync-button

Conversation

@isabellalam12

Copy link
Copy Markdown
Member

No description provided.

This was referenced Aug 26, 2026

isabellalam12 commented Aug 26, 2026

Copy link
Copy Markdown
Member Author

Warning

This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
Learn more

This stack of pull requests is managed by Graphite. Learn more about stacking.

@isabellalam12
isabellalam12 force-pushed the 08-24-emails-add-sync-button branch 2 times, most recently from 5aea21b to a6da2c8 Compare August 26, 2026 17:55
@isabellalam12
isabellalam12 force-pushed the 08-24-emails-remove-defaults branch from 67fb00b to 89ca9db Compare August 26, 2026 17:55
@isabellalam12
isabellalam12 force-pushed the 08-24-emails-add-sync-button branch from a6da2c8 to 76bf469 Compare August 26, 2026 19:11
@isabellalam12
isabellalam12 force-pushed the 08-24-emails-remove-defaults branch 3 times, most recently from 9d0d65f to 8f76576 Compare August 26, 2026 19:27
@isabellalam12
isabellalam12 force-pushed the 08-24-emails-add-sync-button branch from 76bf469 to cd00456 Compare August 26, 2026 19:27
Comment on lines +29 to +47
useEffect(() => {
// Find template subject and body from request.templateId
if (!request?.templateId) {
setTemplate(null);
return;
}

const loadTemplate = async () => {
try {
const templates = await listTemplates();
const found = templates.find((t) => t.id === request.templateId);
setTemplate(found ?? null);
} catch {
setTemplate(null);
}
};

void loadTemplate();
}, [request?.templateId]);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Critical Race Condition: If the user rapidly changes templates, multiple loadTemplate() calls will be in flight simultaneously and may resolve out of order, causing the wrong template to be set.

Scenario:

  1. User selects Template A → starts loading
  2. User quickly switches to Template B → starts loading
  3. Template B finishes loading → sets template to B
  4. Template A finishes loading → sets template to A (WRONG!)
  5. User clicks send → emails sent with Template A's subject/body instead of B

Fix: Add cleanup to ignore stale results:

useEffect(() => {
  if (!request?.templateId) {
    setTemplate(null);
    return;
  }

  let cancelled = false;

  const loadTemplate = async () => {
    try {
      const templates = await listTemplates();
      const found = templates.find((t) => t.id === request.templateId);
      if (!cancelled) {
        setTemplate(found ?? null);
      }
    } catch {
      if (!cancelled) {
        setTemplate(null);
      }
    }
  };

  void loadTemplate();

  return () => {
    cancelled = true;
  };
}, [request?.templateId]);
Suggested change
useEffect(() => {
// Find template subject and body from request.templateId
if (!request?.templateId) {
setTemplate(null);
return;
}
const loadTemplate = async () => {
try {
const templates = await listTemplates();
const found = templates.find((t) => t.id === request.templateId);
setTemplate(found ?? null);
} catch {
setTemplate(null);
}
};
void loadTemplate();
}, [request?.templateId]);
useEffect(() => {
// Find template subject and body from request.templateId
if (!request?.templateId) {
setTemplate(null);
return;
}
let cancelled = false;
const loadTemplate = async () => {
try {
const templates = await listTemplates();
const found = templates.find((t) => t.id === request.templateId);
if (!cancelled) {
setTemplate(found ?? null);
}
} catch {
if (!cancelled) {
setTemplate(null);
}
}
};
void loadTemplate();
return () => {
cancelled = true;
};
}, [request?.templateId]);

Spotted by Graphite

Fix in Graphite


Is this helpful? React 👍 or 👎 to let us know.

@isabellalam12
isabellalam12 force-pushed the 08-24-emails-remove-defaults branch from 8f76576 to d5e8517 Compare August 26, 2026 19:57
@isabellalam12
isabellalam12 force-pushed the 08-24-emails-add-sync-button branch from cd00456 to 09810e8 Compare August 26, 2026 19:57
@isabellalam12
isabellalam12 force-pushed the 08-24-emails-remove-defaults branch from d5e8517 to 6a582b0 Compare August 26, 2026 20:01
@isabellalam12
isabellalam12 force-pushed the 08-24-emails-add-sync-button branch 2 times, most recently from 606a1d9 to ba9446c Compare August 26, 2026 20:12
@isabellalam12
isabellalam12 force-pushed the 08-24-emails-remove-defaults branch from 6a582b0 to b10d002 Compare August 26, 2026 20:16
@isabellalam12
isabellalam12 force-pushed the 08-24-emails-add-sync-button branch 2 times, most recently from 7496a96 to 8b5194d Compare August 26, 2026 20:23
@isabellalam12
isabellalam12 force-pushed the 08-24-emails-remove-defaults branch 2 times, most recently from 888f075 to cc49247 Compare August 26, 2026 20:28
@isabellalam12
isabellalam12 force-pushed the 08-24-emails-remove-defaults branch from cc49247 to 19caa29 Compare August 26, 2026 20:29
@isabellalam12
isabellalam12 force-pushed the 08-24-emails-add-sync-button branch from 8b5194d to bd5c4e3 Compare August 26, 2026 20:29
@sonarqubecloud

Copy link
Copy Markdown

@isabellalam12 isabellalam12 changed the title Add button to send emails synchronously. Emails: Add button to send emails synchronously. Aug 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant