Skip to content

fix(profile): make profile saves actually revalidate (#581, #586) - #598

Merged
thinkclay merged 1 commit into
mainfrom
claude/fix-581-query-keys
Aug 12, 2026
Merged

thinkclay merged 1 commit into
mainfrom
claude/fix-581-query-keys

Conversation

@thinkclay

Copy link
Copy Markdown
Contributor

Closes #581, #586. Part of #594. The epic pairs these because they are two independent reasons the same symptom occurs — you save a profile section and the screen keeps showing pre-save data.

#581 — invalidateProfileQueries matched nothing

It namespaced its keys under 'scaffald'; the hooks that register those queries do not. Nine of eleven keys corresponded to no query in the app:

invalidator hook
['scaffald','profiles','general'] ['profiles','general']
['scaffald','profiles','employment'] ['profiles','employment']
['scaffald','profiles','education-level'] ['profiles','education','level']
['scaffald','profiles','experience-summary'] ['profiles','experience','summary']
['scaffald','user-profiles'] ['user-profiles',…]

And the widget queries the Profile Overview actually renders — ['profiles','widgets',…] — were absent under either spelling, which is the visible half: edit a section, go to the overview, see the old values until staleTime lapses.

Both halves now read from one factory, utils/profile-query-keys.ts. The hooks import their keys from it and the invalidator derives its roots from it, so they cannot drift apart again — a literal is how they drifted in the first place.

Roots rather than leaves, deliberately: react-query matches by key prefix, so ['profiles','certifications'] covers tree / top-level / children without the list having to enumerate them and go stale.

#586 — caller options replaced the hook's own

The *WithSync hooks merged with ...overrides, so a caller's onSuccess replaces the hook's instead of adding to it. ProfileEmploymentLeft passed an empty onSuccess purely as somewhere to hang a comment, and silently deleted the only working invalidation on that page.

Options now merge through composeMutationOptions, which chains both handlers with the hook's running first — it owns cache correctness and a caller's handler should not be able to skip it. onMutate is deliberately not chained: react-query threads its return value through as the rollback context and two functions cannot both own that, so the hook's wins.

The helper is typed structurally rather than against UseMutationOptions generics, so it stays correct across react-query's callback-arity changes (v5 passes (data, variables, context); this version adds onMutateResult).

The test that let this through

profile-sync.test.ts asserted toHaveBeenCalledTimes(11) against a bare mock. Nine of those eleven keys matched nothing and it passed anyway, because it never checked that a key corresponded to anything real.

It now seeds a real QueryClient with all 21 keys the hooks actually register and asserts every one ends up invalidated — so a hook changing its key turns this file red. Plus a case proving unrelated queries (jobs, communities) are left alone, and one proving a single rejected invalidation does not abort the rest.

Verification

  • 323 assertions across 41 files in the profile suite — 0 failures.
  • 41 of those are new (profile-sync rewritten, compose-mutation-options new).
  • scf-core typechecks at 0 errors; pnpm prepush green.

CI checks will show red without running — Actions billing block, see #375.

🤖 Generated with Claude Code

Two independent reasons a profile save left stale data on screen.

#581 — invalidateProfileQueries matched nothing. It namespaced its keys under
'scaffald' while the hooks that register those queries did not, so nine of its
eleven keys corresponded to no query in the app:

    invalidator                                hook
    ['scaffald','profiles','general']          ['profiles','general']
    ['scaffald','profiles','employment']       ['profiles','employment']
    ['scaffald','profiles','education-level']  ['profiles','education','level']
    ['scaffald','profiles','experience-summary'] ['profiles','experience','summary']
    ['scaffald','user-profiles']               ['user-profiles',...]

The widget queries the Profile Overview actually renders — ['profiles','widgets',
...] — were not in the list under either spelling, which is why saving a section
and navigating to the overview showed pre-save data until staleTime lapsed.

Both halves now read from one factory (utils/profile-query-keys.ts), so the two
cannot drift apart again. Roots rather than leaves: react-query matches by key
prefix, so ['profiles','certifications'] covers tree/top-level/children without
the list enumerating them.

#586 — the *WithSync hooks merged caller options with `...overrides`, which
means a caller's onSuccess replaces the hook's rather than adding to it.
ProfileEmploymentLeft passed an empty onSuccess purely as somewhere to hang a
comment and silently deleted the only working invalidation on that page. Options
are now merged through composeMutationOptions, which chains both handlers with
the hook's running first — it owns cache correctness and a caller should not be
able to skip it. onMutate is deliberately not chained: react-query threads its
return value through as the rollback context and two functions cannot both own
that, so the hook's wins.

The old test asserted toHaveBeenCalledTimes(11) against a bare mock. Nine of
those eleven keys matched nothing and it passed anyway — it never checked that a
key corresponded to a real query. It now seeds a real QueryClient with every key
the hooks actually register and asserts each one ends up invalidated, so a hook
changing its key turns this file red.

Co-Authored-By: Claude Opus 5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(profile): invalidateProfileQueries matches no queries — 9 of 11 keys are misnamespaced

1 participant