Add reactive() for pending subscriptions, that returns a reactive store for the subscription#1524
Conversation
🦋 Changeset detectedLatest commit: 8ec21aa The changes in this PR will be included in the next version bump. This PR includes changesets to release 46 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
This stack of pull requests is managed by Graphite. Learn more about stacking. |
BundleMonFiles updated (7)
Unchanged files (135)
Total files change +754B +0.15% Final result: ✅ View report in BundleMon website ➡️ |
1f7053c to
7594c68
Compare
5c10989 to
632c232
Compare
|
Documentation Preview: https://kit-docs-p7hozon2a-anza-tech.vercel.app |
lorisleiva
left a comment
There was a problem hiding this comment.
This is amazing! And so much cleaner than what I thought it was going to be. Just left a comment on the error handling side but happy to merge as-is.
632c232 to
20263d3
Compare
…tore for the subscription
20263d3 to
8ec21aa
Compare
Merge activity
|
|
🔎💬 Inkeep AI search and chat service is syncing content for source 'Solana Kit Docs' |
|
Because there has been no activity on this PR for 14 days since it was merged, it has been automatically locked. Please open a new issue if it requires a follow up. |

Summary of Changes
This PR adds an alternative API for RPC subscriptions:
This returns an object with fields
getState(),getError()andsubscribe()getState()returns the latest published value from the subscription, orundefineduntil a value is publishedgetError()returns the first error from the subscription, orundefinedif there has not been any errorsubscribe(listener)registers a function to be called if either data or an error occursTogether they enable reactive frameworks to consume subscriptions:, eg react with an error boundary
Or without error boundaries:
And svelte:
Vanilla JS:
It's also compatible with libraries like SWR subscriptions:
Note that we intentionally separate error handling, and
getState()never throws. This gives consumers maximum flexibility and allows access to the stale latest value while recovering from an error.This change is purely additive to the existing async generator API for subscriptions, and architecturally lives alongside it as an alternative interface to the
DataPublisherabstraction. It's intended to make subscriptions easier to use in reactive UIs.