Repository navigation
fix(fetchium): re-subscribe TopicQuery on refetch and invalidate - #16
Closed
jimmy-phantom wants to merge 1 commit into
Closed
jimmy-phantom wants to merge 1 commit into
jimmy-phantom wants to merge 1 commit into
Conversation
3 tasks done
Adds an optional `QueryAdapter.invalidate(ctx)` lifecycle method that drops adapter-internal cached state for a query so the next send() delivers fresh data. TopicQueryAdapter implements it as unsubscribe(topic); stateless adapters like REST don't need to. QueryInstance now calls adapter.invalidate?.(ctx) before each send() on the refetch path, and markStale() kicks a debounced refetch when the relay is currently active so invalidateQueries actually refreshes mounted consumers without requiring a deactivate/reactivate cycle. The TopicQueryAdapter.unsubscribe contract is strengthened to make the "must call clearTopic" obligation explicit, since the base class can't enforce it and any subclass that doesn't clear state will return stale data on resubscribe. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
jimmy-phantom
force-pushed
the
jimmy/topicquery-refetch-resnapshot
branch
from
May 4, 2026 18:10
e6098e9 to
9063e3d
Compare
Collaborator
Author
|
Superseded by #17 — same fix on its own, scoped down and rebranded after the topic-resubscribe parts of this branch were rendered unnecessary by a separate fix. |
Collaborator
Author
|
Superseded by #17 — same |
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
__refetch()on a fulfilledTopicQueryreturned the previously cached payload instead of a fresh snapshot. New optional fields added to a topic's result shape never surfaced to consumers; only wiping the cache fixed it.queryClient.invalidateQueries(...)on a still-mounted consumer didn't actually trigger a refetch; it just flippedupdatedAtto 0 and waited for the next deactivate/reactivate cycle that never came.QueryAdapter.invalidate(ctx)lifecycle method.TopicQueryAdapterimplements it asunsubscribe(topic); stateless adapters like REST don't need to implement it.QueryInstance.runQueryImmediately()now callsadapter.invalidate?.(ctx)before eachsend()so the next subscribe delivers fresh data, andmarkStale()kicks a debounced refetch when the relay is currently active soinvalidateQueriesactually refreshes mounted consumers.Refetchdescribe block intopic-query.test.tscovering:__refetchreturns fresh data, concurrent__refetchcalls dedupe, mutation events keep flowing on the post-refetch subscription, andinvalidateQueriesrefreshes a still-mounted consumer.TopicQueryAdapter.unsubscribedocstring to make the "must callclearTopic" obligation explicit, since the base class can't enforce it and a non-compliant subclass would still return stale data on resubscribe.Test plan
npm run test:unit(1133 passed)npm run check-typesnpm run lint