feat: add extraQueryKeys param to useCustomer and useEntity for declarative revalidation#82
Merged
SirTenzin merged 1 commit intouseautumn:mainfrom Feb 27, 2026
Conversation
|
@kylegrahammatzen is attempting to deploy a commit to the Autumn Team on Vercel. A member of the Team first needs to authorize it. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
extraQueryKeysparameter touseCustomeranduseEntityhooks that gets spread into the SWR query keyextraQueryKeyschanges, SWR automatically refetches without needinguseEffector imperativerefetch()callsProblem
When a user switches organizations (or any external dependency changes), there's no declarative way to trigger a refetch of customer/entity data. The current options are:
refetch()imperativelyrefetch()in auseEffect— bad practice with real sync issuesrefreshInterval— wasteful and laggySolution
Spread an optional
extraQueryKeysarray into the SWR query key. When any value changes, SWR treats it as a new cache entry and refetches automatically.Files changed
useCustomerBase.tsx— addedextraQueryKeystoUseCustomerParams, spread into SWR query keyuseEntityBase.tsx— addedextraQueryKeysparam, spread into SWR query keyuseEntity.tsx(react) — forwardextraQueryKeysto base hookuseEntity.tsx(next) — forwardextraQueryKeysto base hookuseCustomerwrappers (react + next) already passparamsthrough touseCustomerBase, so they getextraQueryKeysfor free.Testing
autumn-jspackage with zero errorstsc --noEmitSummary by cubic
Adds an optional extraQueryKeys param to useCustomer and useEntity so data refetches automatically when external dependencies change. This enables declarative revalidation without useEffect or manual refetch calls.
New Features
Migration
Written for commit 1a7a52a. Summary will update on new commits.
Greptile Summary
This PR adds declarative revalidation support to the
useCustomeranduseEntityhooks by introducing an optionalextraQueryKeysparameter that gets spread into the SWR query key. When any value inextraQueryKeyschanges (e.g., when switching organizations), SWR automatically refetches the data without requiring imperativerefetch()calls oruseEffectworkarounds.Key Changes:
extraQueryKeys?: (string | null | undefined)[]parameter touseCustomeranduseEntityhooksThe implementation spreads
extraQueryKeysinto the SWR query key across both base hooks (useCustomerBaseanduseEntityBase), and the wrapper hooks properly forward this parameter. The type signature allowsnullandundefinedvalues in the array to handle loading states gracefully.Confidence Score: 5/5
Important Files Changed
extraQueryKeysparam toUseCustomerParamsinterface and spread it into SWR query key - clean implementation with no issuesextraQueryKeysas separate param and spread it into SWR query key - consistent with useCustomer implementationextraQueryKeysfrom params and forwards it touseEntityBaseextraQueryKeystouseEntityBaseFlowchart
%%{init: {'theme': 'neutral'}}%% flowchart TD A[User calls useCustomer/useEntity with extraQueryKeys] --> B{Wrapper Hook} B --> C[Destructure extraQueryKeys from params] C --> D[Forward to Base Hook] D --> E[Build SWR Query Key] E --> F["queryKey = ['customer/entity', baseUrl/entityId, expand, ...extraQueryKeys]"] F --> G[SWR Cache Lookup] G --> H{extraQueryKeys changed?} H -->|Yes| I[New cache key - trigger refetch] H -->|No| J[Return cached data] I --> K[Fetch from API] K --> L[Update cache with new key] L --> M[Return fresh data] J --> MLast reviewed commit: 1a7a52a