-
Notifications
You must be signed in to change notification settings - Fork 0
feat: imperative infinite queries #6
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -14,7 +14,7 @@ export function infiniteQueryBehavior<TQueryFnData, TError, TData, TPageParam>( | |||||||||||||||||||||||||||||||||||||||||||||||
return { | ||||||||||||||||||||||||||||||||||||||||||||||||
onFetch: (context, query) => { | ||||||||||||||||||||||||||||||||||||||||||||||||
const options = context.options as InfiniteQueryPageParamsOptions<TData> | ||||||||||||||||||||||||||||||||||||||||||||||||
const direction = context.fetchOptions?.meta?.fetchMore?.direction | ||||||||||||||||||||||||||||||||||||||||||||||||
const fetchMore = context.fetchOptions?.meta?.fetchMore | ||||||||||||||||||||||||||||||||||||||||||||||||
const oldPages = context.state.data?.pages || [] | ||||||||||||||||||||||||||||||||||||||||||||||||
const oldPageParams = context.state.data?.pageParams || [] | ||||||||||||||||||||||||||||||||||||||||||||||||
let result: InfiniteData<unknown> = { pages: [], pageParams: [] } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -81,14 +81,17 @@ export function infiniteQueryBehavior<TQueryFnData, TError, TData, TPageParam>( | |||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||
// fetch next / previous page? | ||||||||||||||||||||||||||||||||||||||||||||||||
if (direction && oldPages.length) { | ||||||||||||||||||||||||||||||||||||||||||||||||
const previous = direction === 'backward' | ||||||||||||||||||||||||||||||||||||||||||||||||
if (fetchMore && oldPages.length) { | ||||||||||||||||||||||||||||||||||||||||||||||||
const previous = fetchMore.direction === 'backward' | ||||||||||||||||||||||||||||||||||||||||||||||||
const pageParamFn = previous ? getPreviousPageParam : getNextPageParam | ||||||||||||||||||||||||||||||||||||||||||||||||
const oldData = { | ||||||||||||||||||||||||||||||||||||||||||||||||
pages: oldPages, | ||||||||||||||||||||||||||||||||||||||||||||||||
pageParams: oldPageParams, | ||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||
const param = pageParamFn(options, oldData) | ||||||||||||||||||||||||||||||||||||||||||||||||
const param = | ||||||||||||||||||||||||||||||||||||||||||||||||
fetchMore.pageParam === undefined | ||||||||||||||||||||||||||||||||||||||||||||||||
? pageParamFn(options, oldData) | ||||||||||||||||||||||||||||||||||||||||||||||||
: fetchMore.pageParam | ||||||||||||||||||||||||||||||||||||||||||||||||
atharvsabdeai marked this conversation as resolved.
Show resolved
Hide resolved
Comment on lines
+91
to
+94
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing PageParam ValidationUser-provided pageParam is used without validation. Attackers could inject malicious values causing data exposure or application crashes. Especially risky when pageParam flows to database queries.
Suggested change
Standards
Comment on lines
+91
to
+94
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing Null CheckNo null check for pageParamFn before invocation. If getNextPageParam/getPreviousPageParam is undefined, this will cause runtime errors when fetchMore.pageParam is undefined. Standards
Comment on lines
+91
to
+94
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Refetch Performance ImpactThe refetch operation now uses manual pageParams when available, which is beneficial for custom pagination. However, when refetching all pages, this could lead to unnecessary computation if pageParam functions are complex. Consider adding a performance optimization that caches computed pageParams during initial fetch to avoid recalculation during refetches. Standards
Comment on lines
+91
to
+94
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Optional getNextPageParam CheckThe code assumes pageParamFn always exists, but getNextPageParam is now optional. If getNextPageParam is undefined, pageParamFn will be undefined causing runtime error when called.
Suggested change
Standards
Comment on lines
+91
to
+94
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing getNextPageParam CheckpageParamFn is called unconditionally even when options.getNextPageParam might be undefined. This could cause runtime errors when manual pageParam is not provided and getNextPageParam is missing. Standards
Comment on lines
+91
to
+94
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Inconsistent Parameter HandlingLogic allows manual pageParam to override automatic pageParam calculation without checking if getNextPageParam/getPreviousPageParam exists. This creates inconsistency where automatic pagination can be unexpectedly bypassed, breaking pagination continuity. Standards
Comment on lines
+91
to
+94
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Conditional Logic ComplexityNested conditional logic increases cognitive complexity. The parameter determination logic mixes multiple concerns, making future modifications to parameter handling more error-prone. Standards
Comment on lines
+91
to
+94
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Preserve Manual PageParamsThe implementation correctly uses manual pageParam when provided, but doesn't store this value for future refetches. When refetching, the code uses oldPageParams which may not contain the manually provided pageParam. Standards
Comment on lines
+91
to
+94
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Optimize Refetch LogicThe current implementation checks fetchMore.pageParam === undefined to determine whether to use the pageParamFn or the explicit pageParam. This creates unnecessary function calls when pageParam is provided. Consider short-circuit evaluation to avoid calling pageParamFn entirely when pageParam is provided, reducing computational overhead during pagination operations. Standards
Comment on lines
+91
to
+94
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Input Validation MissingManual pageParam is used without validation. Attackers could inject malicious values causing unexpected behavior or data exposure. Add validation before using external pageParam values. Standards
Comment on lines
+91
to
+94
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Optional Parameter TypeThe pageParam is conditionally used but lacks explicit typing. Adding proper type annotations would improve code clarity and maintainability, especially for future developers working with this API. Standards
Comment on lines
+91
to
+94
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Potential Parameter OverrideThe implementation allows overriding pageParam with user-provided values without validation. This could potentially lead to injection attacks if pageParam is used in sensitive operations like database queries or file operations without proper validation. Standards
Comment on lines
+91
to
+94
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Conditional Logic ComplexityThe nested ternary operator increases cognitive complexity. This pattern could be simplified with a more direct approach like destructuring with defaults or early returns, making the code more readable and maintainable. Standards
|
||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||
result = await fetchPage(oldData, param, previous) | ||||||||||||||||||||||||||||||||||||||||||||||||
} else { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -97,8 +100,8 @@ export function infiniteQueryBehavior<TQueryFnData, TError, TData, TPageParam>( | |||||||||||||||||||||||||||||||||||||||||||||||
// Fetch all pages | ||||||||||||||||||||||||||||||||||||||||||||||||
do { | ||||||||||||||||||||||||||||||||||||||||||||||||
const param = | ||||||||||||||||||||||||||||||||||||||||||||||||
currentPage === 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
? (oldPageParams[0] ?? options.initialPageParam) | ||||||||||||||||||||||||||||||||||||||||||||||||
currentPage === 0 || !options.getNextPageParam | ||||||||||||||||||||||||||||||||||||||||||||||||
? (oldPageParams[currentPage] ?? options.initialPageParam) | ||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+103
to
+104
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing getNextPageParam CheckLogic incorrectly treats missing getNextPageParam as a condition to use oldPageParams instead of calculating next page. This breaks expected behavior for subsequent pages when getNextPageParam is undefined. Standards
Comment on lines
+103
to
+104
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Optional GetNextPageParam CheckThe check for !options.getNextPageParam is new but will always be false when refetching since getNextPageParam is used later. This creates an unnecessary condition check on every page fetch. Consider simplifying this logic or adding a comment explaining the purpose of this check for better code clarity. Standards
Comment on lines
+103
to
+104
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Conditional Operator InconsistencyThe condition adds !options.getNextPageParam but only affects currentPage === 0 case. For subsequent pages, getNextPageParam is still required but now optional in the type definition, creating a logical inconsistency. Standards
Comment on lines
+103
to
+104
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Optional getNextPageParam LogicMaking getNextPageParam optional changes core behavior where currentPage > 0 but getNextPageParam is undefined. Logic now falls back to oldPageParams[currentPage] instead of calculating next param, potentially causing inconsistent pagination behavior. Standards
Comment on lines
+103
to
+104
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Inconsistent Direction ParameterWhen refetching, all pages use 'forward' direction regardless of original fetch direction. This inconsistency could cause unexpected behavior for direction-sensitive queryFn implementations. Standards
Comment on lines
+103
to
+104
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Incorrect pageParam ConditionLogic incorrectly applies initialPageParam when getNextPageParam is missing for any page. This creates inconsistency where subsequent pages would use oldPageParams but first page might not, causing unexpected parameter values. Standards
Comment on lines
+103
to
+104
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Incomplete Optional HandlingLogic added to handle missing getNextPageParam but only in one location. Other code paths still assume getNextPageParam exists, creating inconsistent behavior. Standards
Comment on lines
+103
to
+104
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Inconsistent Direction ParameterWhen refetching pages, direction is always 'forward' regardless of original fetch direction. This could cause inconsistent behavior when refetching pages originally fetched with backward direction. Standards
Comment on lines
+103
to
+104
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Inconsistent PageParam LogicLogic change creates inconsistency in pageParam selection. For currentPage=0, oldPageParams[0] was replaced with oldPageParams[currentPage], but for currentPage>0 with getNextPageParam defined, the logic still uses getNextPageParam without considering oldPageParams[currentPage]. Standards
Comment on lines
+103
to
+104
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Optional getNextPageParamThe condition checks for missing getNextPageParam but uses oldPageParams[currentPage] which may be undefined. This creates inconsistent parameter handling that could lead to unexpected behavior when refetching pages. Standards
Comment on lines
+103
to
+104
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Incorrect PageParam SelectionThe condition incorrectly uses currentPage === 0 OR !options.getNextPageParam, which means even if getNextPageParam is defined, it will still use oldPageParams for the first page. This breaks the expected behavior where getNextPageParam should be used for all pages except the first one.
Commitable Suggestion
Suggested change
Standards
|
||||||||||||||||||||||||||||||||||||||||||||||||
: getNextPageParam(options, result) | ||||||||||||||||||||||||||||||||||||||||||||||||
if (currentPage > 0 && param == null) { | ||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+103
to
106
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing Null CheckThe code attempts to call getNextPageParam() at line 104 even when options.getNextPageParam is undefined (checked at line 103). This inconsistency could lead to runtime errors when getNextPageParam is undefined. Standards
|
||||||||||||||||||||||||||||||||||||||||||||||||
break | ||||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -136,7 +139,7 @@ function getNextPageParam( | |||||||||||||||||||||||||||||||||||||||||||||||
): unknown | undefined { | ||||||||||||||||||||||||||||||||||||||||||||||||
const lastIndex = pages.length - 1 | ||||||||||||||||||||||||||||||||||||||||||||||||
return pages.length > 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
? options.getNextPageParam( | ||||||||||||||||||||||||||||||||||||||||||||||||
? options.getNextPageParam?.( | ||||||||||||||||||||||||||||||||||||||||||||||||
atharvsabdeai marked this conversation as resolved.
Show resolved
Hide resolved
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Optional getNextPageParam Creates Inconsistent BehaviorChanged getNextPageParam from required to optional with ?. operator, but code logic still depends on it for subsequent pages. Without proper fallback logic, this can cause runtime errors when function is undefined. Standards
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nullable Function CallChanged getNextPageParam from required to optional with ?. operator but still unconditionally used in logic flow. If undefined, will return undefined instead of expected next page parameter, potentially breaking pagination. Standards
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Null Check MissingOptional chaining added for getNextPageParam but similar null checks are missing elsewhere in the code. This inconsistency could cause runtime errors when getNextPageParam is undefined. Standards
|
||||||||||||||||||||||||||||||||||||||||||||||||
pages[lastIndex], | ||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+142
to
143
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Incorrect Optional ChainingOptional chaining added to getNextPageParam but the function is already checked for existence on line 104. This creates inconsistent logic flow where the function is treated as both optional and required. Standards
Comment on lines
+142
to
143
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Null Check MissingOptional chaining added but result can be undefined. Missing null check before using returned pageParam could cause runtime errors if getNextPageParam returns undefined.
Suggested change
Standards
Comment on lines
+142
to
143
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nullable Function CallOptional chaining on getNextPageParam could result in undefined function call if getNextPageParam is not provided. This would cause runtime errors when attempting to invoke undefined as a function. Standards
Comment on lines
+142
to
143
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing Null CheckOptional chaining added for getNextPageParam but missing null check before usage. If undefined, subsequent property access will cause runtime error. Standards
|
||||||||||||||||||||||||||||||||||||||||||||||||
pages, | ||||||||||||||||||||||||||||||||||||||||||||||||
pageParams[lastIndex], | ||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+142
to
145
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing Null CheckOptional chaining on getNextPageParam but no fallback if undefined. Could return undefined when called, potentially causing runtime errors in consumers expecting a value.
Suggested change
Standards
Comment on lines
+142
to
145
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Optional getNextPageParamMaking getNextPageParam optional could cause runtime issues if code expects it to be defined. The optional chaining operator allows it to be undefined, but code might still assume a valid function exists. Standards
Comment on lines
+142
to
145
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Optional getNextPageParamThe getNextPageParam function is now optional but used without null check at line 105. This could cause runtime errors if getNextPageParam is undefined but the code at line 105 attempts to call it. Standards
|
||||||||||||||||||||||||||||||||||||||||||||||||
|
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -124,24 +124,27 @@ export class InfiniteQueryObserver< | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
fetchNextPage( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
options?: FetchNextPageOptions, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
): Promise<InfiniteQueryObserverResult<TData, TError>> { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
fetchNextPage({ pageParam, ...options }: FetchNextPageOptions = {}): Promise< | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
InfiniteQueryObserverResult<TData, TError> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
> { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return this.fetch({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
...options, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
meta: { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
fetchMore: { direction: 'forward' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
fetchMore: { direction: 'forward', pageParam }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+127
to
134
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing Parameter ValidationfetchNextPage doesn't validate pageParam before passing it to fetch. When getNextPageParam is defined, pageParam should be rejected as it would override the calculated value, potentially causing inconsistent pagination behavior. Standards
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+127
to
135
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing Type ValidationThe pageParam is passed directly to fetchMore without type validation. Since this is a new parameter that could be undefined, null, or any other value, it should be validated before use to prevent potential type-related issues in the pagination logic. Standards
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+127
to
136
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good update to support imperative infinite queries The A small issue to note: the pipeline shows a TypeScript error (TS2339) indicating that 'pageParam' doesn't exist on the
Comment on lines
+127
to
136
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Optional Parameter TypeThe pageParam parameter is destructured but its type isn't explicitly defined in the function signature. This could lead to maintainability issues when other developers need to understand the expected type. Standards
Comment on lines
+127
to
136
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Optional PageParam TypeThe pageParam parameter is passed without type checking. This could lead to type inconsistencies when manual pageParam values don't match expected types in the query function. Standards
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
fetchPreviousPage( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
options?: FetchPreviousPageOptions, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
): Promise<InfiniteQueryObserverResult<TData, TError>> { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
fetchPreviousPage({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
pageParam, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
...options | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}: FetchPreviousPageOptions = {}): Promise< | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
InfiniteQueryObserverResult<TData, TError> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
> { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+138
to
+143
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing PageParam ValidationfetchPreviousPage accepts pageParam without validation. If undefined/null is passed, it could cause unexpected behavior when getNextPageParam is missing. Standards
Comment on lines
+138
to
+143
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing PageParam ValidationfetchPreviousPage accepts pageParam without validation. Invalid pageParam values could cause unexpected behavior or failures during pagination operations. Standards
Comment on lines
+127
to
+143
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing pageParam ValidationNo validation ensures pageParam is provided when getNextPageParam is missing. Without validation, fetchNextPage/fetchPreviousPage could silently pass undefined pageParam when required, causing runtime errors.
Suggested change
Standards
Comment on lines
+127
to
+143
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Optional Parameter HandlingInconsistent parameter destructuring patterns between fetchNextPage and fetchPreviousPage methods. The first uses inline destructuring while the second uses multi-line format. This inconsistency makes the code harder to maintain as developers need to mentally parse different patterns. Standards
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return this.fetch({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
...options, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
meta: { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
fetchMore: { direction: 'backward' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
fetchMore: { direction: 'backward', pageParam }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+138
to
150
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Support for explicit pageParam added to fetchPreviousPage This change mirrors the update to The same type issue applies here - ensure that |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -271,7 +271,7 @@ export interface InfiniteQueryPageParamsOptions< | |||||
* This function can be set to automatically get the next cursor for infinite queries. | ||||||
* The result will also be used to determine the value of `hasNextPage`. | ||||||
*/ | ||||||
getNextPageParam: GetNextPageParamFunction<TPageParam, TQueryFnData> | ||||||
getNextPageParam?: GetNextPageParamFunction<TPageParam, TQueryFnData> | ||||||
atharvsabdeai marked this conversation as resolved.
Show resolved
Hide resolved
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Type Definition UpdateMaking getNextPageParam optional changes the contract significantly. This requires comprehensive documentation updates and might affect consumers who expect this function to always exist. Standards
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Optional getNextPageParam Without FallbackMaking getNextPageParam optional without fallback behavior could cause runtime failures when used without pageParam. This change requires consumers to provide pageParam manually when getNextPageParam is omitted. Standards
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Optional GetNextPageParam FunctionMaking getNextPageParam optional changes a core API contract. This could lead to inconsistent usage patterns where some implementations use automatic pagination while others require manual pageParam specification. Standards
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Optional getNextPageParamMaking getNextPageParam optional without updating all dependent code could cause runtime errors. Some code may assume this function always exists, leading to potential null reference exceptions. Standards
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Optional getNextPageParamMaking getNextPageParam optional without default behavior could cause runtime issues when undefined. Without getNextPageParam, pagination logic depends entirely on manual pageParam values. Standards
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Type Definition MismatchMaking getNextPageParam optional without updating all dependent code paths could cause runtime errors. Some code may assume this function always exists. Standards
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Optional GetNextPageParamMaking getNextPageParam optional without updating all dependent code could cause runtime errors. Function is called directly in infiniteQueryBehavior.ts without null checks. Standards
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Optional getNextPageParamMaking getNextPageParam optional changes API contract without corresponding type adjustments in fetchNextPage/fetchPreviousPage. This creates inconsistent behavior where manual pageParam is required when getNextPageParam is undefined. Standards
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Optional getNextPageParam LogicMaking getNextPageParam optional without updating all dependent logic creates inconsistency. InfiniteQueryBehavior.ts line 142 still calls getNextPageParam directly without null check, risking runtime errors when getNextPageParam is undefined. Standards
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Optional getNextPageParam Without Code UpdatesMaking getNextPageParam optional without updating all dependent code could cause runtime failures. Some code paths may assume this function exists without checking, leading to potential undefined behavior.
Suggested change
Standards
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Optional getNextPageParamMaking getNextPageParam optional changes the core API contract. This requires careful consideration of backward compatibility and may lead to inconsistent behavior in existing code that expects getNextPageParam to always be defined. Standards
|
||||||
} | ||||||
|
||||||
export type ThrowOnError< | ||||||
|
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.
Inconsistent Direction Handling
The code now uses fetchMore object but inconsistently handles the direction property. In some places it checks for direction existence, in others it assumes direction is defined. This inconsistency creates maintenance challenges and potential bugs when modifying direction-related logic.
Commitable Suggestion
Standards