Skip to content

[fix] Stop trigger edit forms hydrating from stale cached details - #5606

Merged
mmabrouk merged 1 commit into
fe-chore/trigger-drawers-splitfrom
fix/trigger-drawer-stale-hydration
Jul 31, 2026
Merged

[fix] Stop trigger edit forms hydrating from stale cached details#5606
mmabrouk merged 1 commit into
fe-chore/trigger-drawers-splitfrom
fix/trigger-drawer-stale-hydration

Conversation

@mmabrouk

Copy link
Copy Markdown
Member

Fix for a finding on #5571. Targets fe-chore/trigger-drawers-split so it lands as part of that PR.

Context

Editing a trigger can silently save old values over new ones.

Both edit forms prefill their fields once per id and then latch, so a background refetch cannot overwrite edits in progress. The latch is set as soon as subscription (or schedule) is non-null. That is the bug: after any mutation the list query is invalidated, and the refetch serves the stale cache first. The form hydrates from that stale copy and marks the id hydrated. When the fresh response lands the effect runs again, hits the hydratedId.current === loadedId guard, and returns. The fields keep the old values, and saving writes them back.

The form had no way to tell. useTriggerSubscription and useTriggerSchedule expose isLoading: query.isPending, and isPending is true only when there is no cached data at all. During a background refetch there is cached data, so isPending is false.

invalidateSubscriptions() and invalidateSchedules() run after every create, edit, revoke, refresh, remove, and active toggle, so the stale window is easy to land in. Concretely: toggle a trigger off in the list, open its edit drawer straight away, rename it, save. The name change sticks and the active toggle flips back on.

Codex flagged this as P1 on SubscriptionForm and noted ScheduleForm shares the pattern. It does, at the identical guard.

Changes

Both hooks now return isFetching alongside isLoading:

isLoading:  true only when there is no cached data      (unchanged)
isFetching: true whenever a request is in flight        (new)

Both forms skip hydration while isFetching is true, and isFetching joins the effect's dependency list so hydration runs as soon as the fresh result arrives. First load is unaffected: there is no cached data, so the existing !subscription guard already covers it.

Notes

I could not run pnpm lint-fix, because the checkout I used has no node_modules. The hook returns are inferred object literals, so adding a field needs no type changes, and no existing caller destructures isFetching.

What to QA

  • Open a subscription trigger's edit drawer, change the name, save. Reopen it. The new name is there and nothing else changed.
  • The reported path: toggle a trigger off in the list, immediately open its edit drawer, rename it, save. It stays off. Before this change it flipped back on.
  • Same two checks on a schedule trigger.
  • Regression: open an edit drawer, start typing in a field, and leave it open long enough for a background refetch. Your typing is not overwritten.

@dosubot dosubot Bot added size:S This PR changes 10-29 lines, ignoring generated files. bug report Something isn't working frontend labels Jul 31, 2026
@coderabbitai

coderabbitai Bot commented Jul 31, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 1af3a1c0-29a8-4923-84c1-cd623f237a16

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@vercel

vercel Bot commented Jul 31, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
agenta-documentation Ready Ready Preview Jul 31, 2026 5:08pm

Request Review

@mmabrouk
mmabrouk merged commit 46f8bc7 into fe-chore/trigger-drawers-split Jul 31, 2026
36 of 37 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug report Something isn't working frontend size:S This PR changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant