fix: race condition with pagination token #105
Merged
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.
flyteorg/flyte#546
usePagination
stores the pagination token in separate state hook. After theuseFetchableData
refactor to use state machines, the fetchable will now reset before we have a change to update the token state, causing the value to persist across API calls. This updateusePagination
to store the token in the fetchable data, so that it is part of the context used by the state machine and will remain in sync with the data it applies to.Also removed the unnecessary use of a separate state hook for the
moreItemsAvailable
field, since that can be directly computed from the presence of thetoken
.Since
usePagination
returns an object that mostly looks like aFetchableData<T>
, but using a different context shape under the hood, it was necessary to update the type forFetchableData
so that thestate
field was aFetchableState<any>
. This changes feels okay, because the intended usage of passing that state field along is to allow consumers to check which state we are in for conditional rendering (usingstate.matches
), not necessarily to allow logic based on the context contained within the state. I may open a follow-up PR to refactor the usage of fetch state to pass an even more restricted object, or remove the visibility of that state field from consuming code altogether.