use-signalr
Guides

Server rendering

How Lit 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.

In Lit, hostConnected() does nothing on the server, so a host render reads "idle". In the browser, the first render shows "connecting", because the controller starts the session in hostConnected(), before the first update. Render text that depends on the status after firstUpdated.

Calls during a server render

An invoke during a server render waits for a connection that never comes. It ends with a SignalRTimeoutError when its timeout expires (10 seconds by default).

Call controller.invoke 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 controller.status to show an "offline" or loading state until the hub is connected.

Lit SSR

Importing the package, creating the client, creating the session, and creating a controller start no connection. hostConnected() does nothing on the server, even when Lit calls it. The connection starts in the browser. A host render reads "idle" on the server, so render text that depends on the status after firstUpdated.

On this page