-
-
Notifications
You must be signed in to change notification settings - Fork 126
fix(tanstack-query): set stream query to success immediately after stream resolves #1202
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(tanstack-query): set stream query to success immediately after stream resolves #1202
Conversation
…solves Previously, the query remained in a pending/undefined state until the first chunk was yielded. Now, after successfully resolving the stream promise, the query is immediately set to an empty array (success state) before iterating through chunks.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
WalkthroughThe stream-query implementation is refactored to introduce refetch mode handling with conditional cache management. The test suite expands significantly to validate various streaming scenarios including refetch modes, chunk limiting, abort handling, and edge cases. Changes
Sequence DiagramsequenceDiagram
participant Caller
participant StreamQuery
participant Cache
participant DataStream
Caller->>StreamQuery: streamQuery(queryFn, options)
alt hasPreviousData && refetchMode === 'reset'
StreamQuery->>Cache: clear cache
else
StreamQuery->>Cache: initialize with limited empty array
end
StreamQuery->>DataStream: subscribe to stream
loop for each chunk
DataStream->>StreamQuery: chunk arrives
StreamQuery->>StreamQuery: apply limitArraySize
alt shouldUpdateCacheDuringStream
StreamQuery->>Cache: update cache incrementally
else
StreamQuery->>StreamQuery: accumulate in local result
end
end
DataStream->>StreamQuery: stream resolves
alt !shouldUpdateCacheDuringStream
StreamQuery->>Cache: finalize with accumulated result
end
alt cached result exists
StreamQuery->>Caller: return size-limited cached data
else
StreamQuery->>Caller: return accumulated result
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Summary of ChangesHello @unnoq, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request addresses a specific behavior in Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
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.
Code Review
This pull request fixes an issue where a streamed query would remain in a pending state until the first chunk arrived. The change correctly sets the query to a success state with an empty array immediately after the stream promise resolves. The accompanying tests have been significantly improved, with more granular checks and better organization, providing much stronger validation for the streaming logic. I've found one area for a minor refactoring to remove a redundant operation, but overall the changes are excellent and improve both correctness and test quality.
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
More templates
@orpc/ai-sdk
@orpc/arktype
@orpc/client
@orpc/contract
@orpc/experimental-durable-iterator
@orpc/hey-api
@orpc/interop
@orpc/json-schema
@orpc/nest
@orpc/openapi
@orpc/openapi-client
@orpc/otel
@orpc/experimental-pino
@orpc/experimental-publisher
@orpc/experimental-ratelimit
@orpc/react
@orpc/react-query
@orpc/experimental-react-swr
@orpc/server
@orpc/shared
@orpc/solid-query
@orpc/standard-server
@orpc/standard-server-aws-lambda
@orpc/standard-server-fastify
@orpc/standard-server-fetch
@orpc/standard-server-node
@orpc/standard-server-peer
@orpc/svelte-query
@orpc/tanstack-query
@orpc/trpc
@orpc/valibot
@orpc/vue-colada
@orpc/vue-query
@orpc/zod
commit: |
Previously, the query remained in a pending/undefined state until the first chunk was yielded. Now, after successfully resolving the stream promise, the query is immediately set to an empty array (success state) before iterating through chunks.
Summary by CodeRabbit
New Features
Bug Fixes
Tests