Skip to content

fix(fetchium): re-subscribe TopicQuery on refetch and invalidate - #16

Closed
jimmy-phantom wants to merge 1 commit into
mainfrom
jimmy/topicquery-refetch-resnapshot
Closed

jimmy-phantom wants to merge 1 commit into
mainfrom
jimmy/topicquery-refetch-resnapshot

Conversation

@jimmy-phantom

@jimmy-phantom jimmy-phantom commented May 4, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • Bugs:
    • Calling __refetch() on a fulfilled TopicQuery returned 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 flipped updatedAt to 0 and waited for the next deactivate/reactivate cycle that never came.
  • Fix: adds an optional QueryAdapter.invalidate(ctx) lifecycle method. TopicQueryAdapter implements it as unsubscribe(topic); stateless adapters like REST don't need to implement it. QueryInstance.runQueryImmediately() now calls adapter.invalidate?.(ctx) before each send() so the next subscribe delivers fresh data, and markStale() kicks a debounced refetch when the relay is currently active so invalidateQueries actually refreshes mounted consumers.
  • Tests: new Refetch describe block in topic-query.test.ts covering: __refetch returns fresh data, concurrent __refetch calls dedupe, mutation events keep flowing on the post-refetch subscription, and invalidateQueries refreshes a still-mounted consumer.
  • Contract: strengthens the TopicQueryAdapter.unsubscribe docstring to make the "must call clearTopic" obligation explicit, since the base class can't enforce it and a non-compliant subclass would still return stale data on resubscribe.
  • Patch-level changeset.

Test plan

  • npm run test:unit (1133 passed)
  • npm run check-types
  • npm run lint

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
jimmy-phantom force-pushed the jimmy/topicquery-refetch-resnapshot branch from e6098e9 to 9063e3d Compare May 4, 2026 18:10
@jimmy-phantom jimmy-phantom changed the title fix(fetchium): re-snapshot TopicQuery on refetch fix(fetchium): re-subscribe TopicQuery on refetch and invalidate May 4, 2026
@jimmy-phantom

Copy link
Copy Markdown
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.

@jimmy-phantom

Copy link
Copy Markdown
Collaborator Author

Superseded by #17 — same invalidateQueries fix on its own, scoped down and rebranded after the topic-resubscribe parts of this branch were rendered unnecessary by a separate fix.

@jimmy-phantom
jimmy-phantom deleted the jimmy/topicquery-refetch-resnapshot branch May 18, 2026 15:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant