Repository navigation
Description
Provide environment information
System:
OS: macOS 15.4
CPU: (10) arm64 Apple M1 Max
Memory: 7.85 GB / 64.00 GB
Shell: 5.9 - /bin/zsh
Binaries:
Node: 22.11.0 - ~/.nvm/versions/node/v22.11.0/bin/node
npm: 11.2.0 - ~/.nvm/versions/node/v22.11.0/bin/npm
Watchman: 2024.11.04.00 - /opt/homebrew/bin/watchman
Browsers:
Brave Browser: 133.1.75.181
Chrome: 135.0.7049.41
Safari: 18.4
Safari Technology Preview: 18.4
npmPackages:
@tanstack/react-query: ^5.67.1 => 5.72.2
@trpc/client: ^11.0.0 => 11.0.4
@trpc/server: ^11.0.0 => 11.0.4
next: ^15.0.0 => 15.3.0
react: ^19.0.0 => 19.1.0
typescript: ^5.8.2 => 5.8.3
Describe the bug
When using the useSubscription hook from the new @trpc/tanstack-react-query integration, the onConnectionStateChange callback never fires. However, the subscription.status value does update as expected.
I believe this is happening because the useSubscription hook implementation does not appear to be calling the user-provided onConnectionStateChange callback. See L202, where updateState is being called in a similar fashion as onStarted / onData / onError. However, in these other cases, there is a call to the user-provided callback in addition to updateState:
optsRef.current.onError?.(error);
updateState((prev) => {
// ...
})However, in the onConnectionStateChange block, it looks like we are missing this call, which should appear on line 203:
optsRef.current.onConnectionStateChange?.(result);In fact, there does not appear to be any reference to optsRef.current.onConnectionStateChange anywhere in the hook implementation.
Link to reproduction
To reproduce
- Provide a
onConnectionStateChangecallback tosubscriptionOptionswhen creating a subscription. - Take any action that would normally trigger a connection state change, such as shutting down the local development server.
- Observe that
subscription.status(as returned from theuseSubscriptionhook) will update to reflect this change (likely because the hook is callingupdateState) butonConnectionStateChangeis never called.
Additional information
No response
👨👧👦 Contributing
- 🙋♂️ Yes, I'd be down to file a PR fixing this bug!
Activity
KATT commentedon Apr 11, 2025
Wanna have a stab at testing it?
First step is probably to add a regression test inside of https://github.com/trpc/trpc/blob/main/packages/tanstack-react-query/test/useSubscription.test.tsx
The
testReactResourceshould have a function to.destroyConnections()which should trigger the clients to reconnectfix: `useSubscription` calls `onConnectionStateChange` (trpc#6797)
github-actions commentedon Jun 1, 2025
This issue has been locked because we are very unlikely to see comments on closed issues. If you are running into a similar issue, please create a new issue. Thank you.