Skip to content

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

@krisajenkins

Description

@krisajenkins

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:

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions