clockworklabs / clockworklabs/SpacetimeDB
Svelte (and Vue) bindings can't reconnect with a new auth token without a page reload
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 25.2k
- Forks
- 1.1k
- Avg merge
- 2d 7h
- Merged PRs (30d)
- 46
Description
Problem
The common auth flow for a SpacetimeDB web app is "start anonymous, then the user signs in" — you open an anonymous connection, the user authenticates (e.g. via Google), you get a logged-in token, and you want to reconnect with it. In the Svelte binding there's no clean way to do this:
- The provider holds its connection in a module-level singleton that's reused across remounts, so even a
{#key}swap keeps the old token. - There's no reconnect path on the context value.
- A
DbConnection's token is immutable afterbuild(), so you can't mutate your way out either.
The only thing that actually works today is a hard window.location.reload(), which throws away all client state and flickers the UI on every sign-in/sign-out. Separately, the Svelte binding also lacks the exponential-backoff auto-reconnect that React and Solid already get from ConnectionManager, so a dropped socket just stays dropped.
Vue has the same shape (it doesn't use ConnectionManager either).
Proposed fix
I think this can be fixed cleanly by extracting and updating work that already exists in-flight:
- The
rebuild()primitive onConnectionManagerfrom the open multi-module-provider PR #4887 (design by @Ludv1gL) — lifted into a focused, additive change and adapted to the current post-#5185 reconnect machinery. - Porting the Svelte binding onto the shared
ConnectionManager(the same pool React and Solid already use), which drops the bespoke singleton, gains auto-reconnect for free, and lets the provider surface areconnect(builder)method for token swaps with no page reload.
This hangs off the reconnect tracking issue #1936.
Next step
I'll submit a pull request shortly that does both: the ConnectionManager.rebuild() primitive plus tests, then the Svelte port.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with ConnectionManager and the Svelte binding provider; review the rebuild() design in PR #4887 and the reconnect machinery added after #5185. Add the proposed rebuild tests, then verify the binding can replace its token and regain exponential-backoff reconnect behavior without a page reload.
Written by the indexing model from the issue text.
Assessment
- Domain
- frontend, web-dev
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100