Server rendering
How Svelte behaves during server-side rendering and hydration.
Nothing connects on the server. Importing the package, calling createSignalRClient, and rendering a component start no connection.
What the server renders
Every hub reports the status "idle" during a server render.
The browser also reports "idle" on its first render. Because both sides match, hydration works and no mismatch warning appears.
The connection starts in the browser, after the first render. Then the status changes to "connecting" and "connected".
Calls during a server render
Svelte disables the session on the server. An invoke or a wait rejects at once with SignalRDisabledError, and a teardown call resolves false. No timer stays pending.
Call hubInvoke in setup or component init, as with any helper. Do not call the function that it returns during a server render. Call that function in the browser, for example in an event handler. Use hubStatus to show an "offline" or loading state until the hub is connected.
Svelte and SvelteKit
provideSignalR builds no connection until the component mounts in the browser. onMount never runs during SSR. You can call provideSignalR in +layout.svelte without a guard for the server.
On the server, provideSignalR disables the session. hubInvoke rejects with SignalRDisabledError, and hubTeardown resolves false at once. A call that starts during component init also rejects.
Svelte 5 does not allow await at the top level of a component script, unless you enable experimental async mode.