Emails: Add button to send emails synchronously. - #88
Draft
isabellalam12 wants to merge 1 commit into
Draft
Conversation
This was referenced Aug 26, 2026
Draft
Merged
Merged
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.
This stack of pull requests is managed by Graphite. Learn more about stacking. |
isabellalam12
force-pushed
the
08-24-emails-add-sync-button
branch
2 times, most recently
from
August 26, 2026 17:55
5aea21b to
a6da2c8
Compare
isabellalam12
force-pushed
the
08-24-emails-remove-defaults
branch
from
August 26, 2026 17:55
67fb00b to
89ca9db
Compare
isabellalam12
force-pushed
the
08-24-emails-add-sync-button
branch
from
August 26, 2026 19:11
a6da2c8 to
76bf469
Compare
isabellalam12
force-pushed
the
08-24-emails-remove-defaults
branch
3 times, most recently
from
August 26, 2026 19:27
9d0d65f to
8f76576
Compare
isabellalam12
force-pushed
the
08-24-emails-add-sync-button
branch
from
August 26, 2026 19:27
76bf469 to
cd00456
Compare
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]); |
There was a problem hiding this comment.
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:
- User selects Template A → starts loading
- User quickly switches to Template B → starts loading
- Template B finishes loading → sets template to B
- Template A finishes loading → sets template to A (WRONG!)
- 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
Is this helpful? React 👍 or 👎 to let us know.
isabellalam12
force-pushed
the
08-24-emails-remove-defaults
branch
from
August 26, 2026 19:57
8f76576 to
d5e8517
Compare
isabellalam12
force-pushed
the
08-24-emails-add-sync-button
branch
from
August 26, 2026 19:57
cd00456 to
09810e8
Compare
isabellalam12
force-pushed
the
08-24-emails-remove-defaults
branch
from
August 26, 2026 20:01
d5e8517 to
6a582b0
Compare
isabellalam12
force-pushed
the
08-24-emails-add-sync-button
branch
2 times, most recently
from
August 26, 2026 20:12
606a1d9 to
ba9446c
Compare
isabellalam12
force-pushed
the
08-24-emails-remove-defaults
branch
from
August 26, 2026 20:16
6a582b0 to
b10d002
Compare
isabellalam12
force-pushed
the
08-24-emails-add-sync-button
branch
2 times, most recently
from
August 26, 2026 20:23
7496a96 to
8b5194d
Compare
isabellalam12
force-pushed
the
08-24-emails-remove-defaults
branch
2 times, most recently
from
August 26, 2026 20:28
888f075 to
cc49247
Compare
isabellalam12
force-pushed
the
08-24-emails-remove-defaults
branch
from
August 26, 2026 20:29
cc49247 to
19caa29
Compare
isabellalam12
force-pushed
the
08-24-emails-add-sync-button
branch
from
August 26, 2026 20:29
8b5194d to
bd5c4e3
Compare
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.




No description provided.