mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-09 13:01:00 +00:00
fix(settings): keep a managed record's edit form across a refetch
The fields component was keyed on the query's `dataUpdatedAt` under a comment saying the key stopped a refetch landing mid-edit from replacing what somebody is typing. It did the reverse: the timestamp moves every time the query resolves, so invalidating the `managed-profiles` prefix from anywhere — the guardian list on another row is enough — remounted the fields and threw the half-typed name away. Keyed on the record's id instead, which is stable for as long as the form is about the same record.
This commit is contained in:
1 parent
0bae48180a
commit
038fc72be2
1 file changed
+9
-4
@@ -99,12 +99,17 @@ export function ManagedProfileEditForm({
|
||||
);
|
||||
}
|
||||
|
||||
// Keyed on the loaded record so the field state below is seeded from it once
|
||||
// rather than through an effect that re-seeds on every refetch — a refetch
|
||||
// landing mid-edit must not silently replace what somebody is typing.
|
||||
// Keyed on WHICH record is open, so the field state below is seeded once per
|
||||
// record rather than through an effect that re-seeds on every refetch. The
|
||||
// key was the query's `dataUpdatedAt`, which did the opposite of what it
|
||||
// claimed: any invalidation of the `managed-profiles` prefix — removing a
|
||||
// guardian from another row, say — refetches this read, moves the timestamp
|
||||
// and remounts the fields, so a half-typed name disappears while somebody is
|
||||
// looking at it. The id is stable for as long as the form is about the same
|
||||
// record, which is exactly as long as the seeding should hold.
|
||||
return (
|
||||
<ManagedProfileEditFields
|
||||
key={profile.dataUpdatedAt}
|
||||
key={profile.data.id}
|
||||
profile={profile.data}
|
||||
onDone={onDone}
|
||||
/>
|
||||
|
||||
Reference in new issue
Block a user