Skip to content

Commit 92b312f

Browse files
priosshrsthclaude
andcommitted
OUT-4109 | Handle SWR mutate rejections instead of letting them reach Sentry
Two rejection paths per component: the optimistic mutate() was never awaited, so its rejection escaped the surrounding try/catch, and debounceMutate() is fire-and-forget. Both surface as unhandled rejections when fetcher() throws. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Y4tF84tzJW7Bo1DehsDX22
1 parent 9806fe8 commit 92b312f

3 files changed

Lines changed: 11 additions & 8 deletions

File tree

src/app/configure-tasks-app/ui/Subtemplates.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ export const Subtemplates = ({ template_id, token }: { template_id: string; toke
5353

5454
const { mutate } = useSWRConfig()
5555

56-
const _debounceMutate = async (cacheKey: string) => await mutate(cacheKey)
56+
const _debounceMutate = (cacheKey: string) =>
57+
mutate(cacheKey).catch((error) => console.error('Failed to revalidate subtemplates:', error))
5758
const debounceMutate = useDebounce(_debounceMutate, 200)
5859

5960
useEffect(() => {
@@ -68,7 +69,7 @@ export const Subtemplates = ({ template_id, token }: { template_id: string; toke
6869
debounceMutate(cacheKey)
6970
}, [activeTemplate?.subTaskTemplates])
7071

71-
const handleSubtemplateCreation = (payload: CreateTemplateRequest) => {
72+
const handleSubtemplateCreation = async (payload: CreateTemplateRequest) => {
7273
const tempId = generateRandomString('temp-template')
7374
setOptimisticUpdates((prev) => [
7475
...prev,
@@ -90,7 +91,7 @@ export const Subtemplates = ({ template_id, token }: { template_id: string; toke
9091
const optimisticData = sortTaskByDescendingOrder([...currentSubtemplates, tempSubtemplate])
9192

9293
try {
93-
mutate(
94+
await mutate(
9495
cacheKey,
9596
async () => {
9697
const subTask = await createSubTemplate(token, template_id, payload)

src/app/detail/ui/ActivityWrapper.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ export const ActivityWrapper = ({
5555

5656
useScrollToElement('commentId')
5757

58-
const _debounceMutate = async (cacheKey: string) => await mutate(cacheKey)
58+
const _debounceMutate = (cacheKey: string) =>
59+
mutate(cacheKey).catch((error) => console.error('Failed to revalidate activity logs:', error))
5960
const debounceMutate = useDebounce(_debounceMutate, 300)
6061

6162
const shouldRefetchRef = useRef(true) //preventing double fetching from comment apis. Due to optimistic update revalidation, we are already fetching logs there. So no need to refetch in case for comment creation and deletion.
@@ -102,7 +103,7 @@ export const ActivityWrapper = ({
102103
const optimisticData = getOptimisticData(postCommentPayload, activities.data, tempLog)
103104

104105
try {
105-
mutate(
106+
await mutate(
106107
cacheKey,
107108
async () => {
108109
shouldRefetchRef.current = false

src/app/detail/ui/Subtasks.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@ export const Subtasks = ({
6767

6868
const { mutate } = useSWRConfig()
6969

70-
const _debounceMutate = async (cacheKey: string) => await mutate(cacheKey)
70+
const _debounceMutate = (cacheKey: string) =>
71+
mutate(cacheKey).catch((error) => console.error('Failed to revalidate subtasks:', error))
7172
const debounceMutate = useDebounce(_debounceMutate, 200)
7273

7374
useEffect(() => {
@@ -84,7 +85,7 @@ export const Subtasks = ({
8485
setLastUpdated(activeTask?.lastSubtaskUpdated)
8586
}, [activeTask?.lastSubtaskUpdated])
8687

87-
const handleSubTaskCreation = (payload: CreateTaskRequest) => {
88+
const handleSubTaskCreation = async (payload: CreateTaskRequest) => {
8889
const tempId = generateRandomString('temp-task')
8990
setOptimisticUpdates((prev) => [
9091
...prev,
@@ -104,7 +105,7 @@ export const Subtasks = ({
104105
)
105106
const optimisticData = subTasks?.tasks ? sortSubtasksByPriority([...subTasks.tasks, tempSubtask]) : [tempSubtask]
106107
try {
107-
mutate(
108+
await mutate(
108109
cacheKey,
109110
async () => {
110111
const subTask = await handleCreate(token, payload, { disableSubtaskTemplates: true })

0 commit comments

Comments
 (0)