clockworklabs / clockworklabs/SpacetimeDB

Svelte (and Vue) bindings can't reconnect with a new auth token without a page reload

Open
#5,373 0 comments 0 reactions 0 assignees View on GitHub

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 after build(), 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 on ConnectionManager from 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 a reconnect(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

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.