-
-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(react-query): Allow optional initialData in infiniteQueryOptions #8154
fix(react-query): Allow optional initialData in infiniteQueryOptions #8154
Conversation
☁️ Nx Cloud ReportCI is running/has finished running commands for commit 45db433. As they complete they will appear below. Click to see the status, the terminal output, and the build insights. 📂 See all runs for this CI Pipeline Execution ✅ Successfully ran 2 targetsSent with 💌 from NxCloud. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you please add a type test to packages/react-query/src/__tests__/infiniteQueryOptions.test-d.tsx
that fails before and succeeds with your fix ?
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #8154 +/- ##
===========================================
+ Coverage 45.41% 81.89% +36.48%
===========================================
Files 200 26 -174
Lines 7456 359 -7097
Branches 1696 99 -1597
===========================================
- Hits 3386 294 -3092
+ Misses 3694 56 -3638
+ Partials 376 9 -367
|
I added a type test that failed before and succeeds with my fix. |
initialData?: | ||
| undefined | ||
| InitialDataFunction< | ||
NonUndefinedGuard<InfiniteData<TQueryFnData, TPageParam>> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should this have been something like
initialData?:
| undefined
| NonUndefinedGuard<InfiniteData<TQueryFnData, TPageParam>>
| InitialDataFunction<
NonUndefinedGuard<InfiniteData<TQueryFnData, TPageParam>>
to allow passing initialData as object and not within a callback function?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we can pass initialData as an object via DefinedInitialDataInfiniteOptions
:
query/packages/react-query/src/infiniteQueryOptions.ts
Lines 41 to 45 in febbde6
> & { | |
initialData: | |
| NonUndefinedGuard<InfiniteData<TQueryFnData, TPageParam>> | |
| (() => NonUndefinedGuard<InfiniteData<TQueryFnData, TPageParam>>) | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sure, but it still won't work conditionally, see this modified playground based on the original example:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
okay then what’s the fix please 😅
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I made a PR here :) #8157
Hope that clarifies things, or perhaps I'm misunderstanding something!
thanks for addressing my issue so quickly! i added a post-merge comment with a potential overlook. :) |
Issue fix : #8132
There was a typescript error(but could be run with no problem) when using optional
initialData
ininfiniteQueryOptions