improvement(react-query): codebase-wide audit — server-state hooks, webhook coherence, resume migration#5024
Conversation
…ebhook coherence, resume migration
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
PR SummaryMedium Risk Overview Runs a broad React Query cleanup: hierarchical Resume UI moves off local Webhook coherence: Smaller touches: demo modal uses Reviewed by Cursor Bugbot for commit f7e87df. Configure here. |
Greptile SummaryThis PR performs a codebase-wide React Query audit across ~46 files, applying consistent patterns (explicit
Confidence Score: 5/5Safe to merge after a manual pause/resume smoke test on the resume page, which underwent the largest single-component rewrite in the PR. The webhook and resume changes are behavior-preserving migrations with clear correctness: isDisabled/webhookId derivations in use-webhook-info.ts produce identical outputs to the old setState logic, onSettled returns the Promise.all so mutateAsync correctly stays pending through refetch, and the optimistic setQueryData in handleResume is followed by invalidation-driven reconciliation. No cache keys are left dangling — useReactivateWebhook invalidates the exact byBlock key that useWebhookQuery subscribes to. The schedules, subscription, workflow, and other bulk-updated hooks are mechanical onSuccess→onSettled conversions with no logic changes. The new check-react-query-patterns.ts CI script locks in the conventions going forward. apps/sim/app/resume/[workflowId]/[executionId]/resume-page-client.tsx — largest change (~350 lines net), worth a manual pause/resume smoke test before merge. Important Files Changed
Sequence DiagramsequenceDiagram
participant UI as ResumeExecutionPage
participant RQ as React Query Cache
participant API as /api/resume/...
participant WH as use-webhook-info
participant WHAPI as /api/webhooks/...
Note over UI,RQ: Resume Page - React Query migration
UI->>RQ: useResumeExecutionDetail(workflowId, executionId, initialData)
RQ-->>UI: data (from initialData or background refetch)
UI->>RQ: usePauseContextDetail(workflowId, executionId, contextId)
RQ->>API: GET /api/resume/[wId]/[eId]/[cId]
API-->>RQ: PauseContextDetail
RQ-->>UI: selectedDetail
UI->>RQ: "useResumeContext().mutateAsync({...})"
RQ->>API: POST /api/resume/[wId]/[eId]/[cId]
API-->>RQ: "{ok, payload}"
Note over UI,RQ: Optimistic update via setQueryData
RQ-->>UI: "resumeStatus=resuming (optimistic)"
Note over RQ: onSettled: invalidate execution + context keys
RQ->>API: GET refetch (execution + context)
API-->>RQ: Fresh server state
RQ-->>UI: Reconciled data
Note over WH,WHAPI: Webhook Cache-Coherence Fix
WH->>RQ: useWebhookQuery(workflowId, blockId, isConfigured)
RQ->>WHAPI: GET listWebhooksByBlock
WHAPI-->>RQ: "{isActive, id}"
RQ-->>WH: "webhook (shared cache, staleTime=60s)"
WH->>RQ: "useReactivateWebhook().mutateAsync({webhookId, workflowId, blockId})"
RQ->>WHAPI: PATCH /api/webhooks/[id]
WHAPI-->>RQ: updated webhook
Note over RQ: onSettled: invalidate webhookKeys.byBlock(wId, bId)
RQ->>WHAPI: GET refetch (all consumers see fresh isActive)
RQ-->>WH: "{isActive: true} (cache coherent)"
Reviews (2): Last reviewed commit: "chore(react-query): add static pattern l..." | Re-trigger Greptile |
- add scripts/check-react-query-patterns.ts (staleTime/signal/key-factory/inline-key enforcement) wired into CI as check:react-query; strict zone hooks/queries/**, ratchet elsewhere - fix(resume): use same-origin relative path for resume POST (getBaseUrl could cross origin on whitelabel/preview hosts and drop session cookies) — Cursor Bugbot - remove explanatory inline comments in favor of TSDoc per repo convention
|
@greptile review |
|
@cursor review |
There was a problem hiding this comment.
✅ Bugbot reviewed your changes and found no new issues!
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit f7e87df. Configure here.
Summary
staleTime, forwarded{ signal }intoqueryFn, reshaped key factories to the hierarchicalall/lists()/details()form, narrowed broad invalidations to targeted prefixes, and madeonSettledreturn theinvalidateQueriespromise so mutations stay pending through refetchreactivateWebhookPATCHed without invalidating the sharedwebhookKeyscache, souseWebhookManagementserved staleisActivefor up to 60s. AddeduseReactivateWebhookmutation and refactoreduse-webhook-info.tsoff its duplicate fetch-into-useStateonto the shareduseWebhookQueryresume-page-client.tsxoff rawfetch+useStateonto React Query: newgetPauseContextDetailContract, newresume-execution.tshooks (2useQuery+ 1useMutation), collapsed two byte-identical GET paths into one query + effect-on-data, optimistic updates viasetQueryData, invalidation-driven reconciliationType of Change
Testing
bunx tsc --noEmitclean (only a pre-existing unrelatedtailwind.config.tserror)bun run check:api-validationpassedorigin/staging; recommend a manual pause/resume smoke test before mergeChecklist