Sébastien Rigaux

TanStack Query: sync query invalidations across tabs

View resource

dev.to

To keep views consistent across tabs, this article recommends broadcasting only the query key to invalidate, then letting each tab fetch its own data with its own filters, authentication, and error handling. The example uses BroadcastChannel and a listener mounted once near QueryClientProvider.

Invalidation marks matching queries stale; only active queries refetch immediately. The same mechanism can signal a logout, but the server remains responsible for revoking the session: a closed or frozen tab may miss the message.

Illustration for a DEV article showing a message about changing a project name in one tab while another tab still displays the old name. Idan Shalem’s name and “Oct 30 · 3 min read” appear below.