Skip to content
Torii docs

Runtime Status

The SDK’s rendering primitives and their CSS are delivered from the CDN. These three components gate their children on whether that runtime is loading, ready, or failed, distinct from the auth lifecycle that drives <SignedIn> / <SignedOut> / <AuthLoading>.

All three must be rendered inside <ToriiProvider>.

ComponentRenders children when…
<ToriiLoading>The runtime is still loading.
<ToriiLoaded>The runtime loaded and its styles are injected.
<ToriiFailed>The runtime failed to load.

Renders its children while the SDK runtime is still loading.

import { ToriiLoading } from '@torii-js/torii-react';
<ToriiLoading>
<FullPageSpinner />
</ToriiLoading>
NameTypeDefaultDescription
childrenReactNoden/aRendered while the runtime is loading.

Renders its children once the runtime has loaded and its styles are injected.

import { ToriiLoaded, SignedOut, SignIn } from '@torii-js/torii-react';
<ToriiLoaded>
<SignedOut>
<SignIn />
</SignedOut>
</ToriiLoaded>
NameTypeDefaultDescription
childrenReactNoden/aRendered once the runtime is ready.

Renders its children when the runtime fails to load. children may be plain nodes or a render function receiving the load error and a retry callback, so you can offer a retry button.

import { ToriiFailed } from '@torii-js/torii-react';
<ToriiFailed>
{({ error, retry }) => (
<div role="alert">
<p>Couldn't load the sign-in UI. {error?.message}</p>
<button onClick={retry}>Retry</button>
</div>
)}
</ToriiFailed>
NameTypeDefaultDescription
childrenReactNode | ((state: { error: Error | null; retry: () => void }) => ReactNode)n/aRendered on load failure. As a function, receives { error, retry }.

The three components are thin wrappers over the useRuntimeStatus() hook, which exposes the same lifecycle for fully custom chrome.

import { useRuntimeStatus } from '@torii-js/torii-react';
function Gate({ children }) {
const { status, error, retry } = useRuntimeStatus();
if (status === 'loading') return <Spinner />;
if (status === 'error') return <button onClick={retry}>Retry: {error?.message}</button>;
return children;
}
MemberTypeDescription
status'loading' | 'ready' | 'error''loading' until the CDN runtime resolves, then 'ready' or 'error'.
errorError | nullThe load error when status === 'error', otherwise null.
retry() => voidRe-attempt a failed load. No-op while loading or once ready.

Separately from “loading / ready / failed”, a runtime that did load can later become outdated: if Torii ships a breaking change to an endpoint and this tab is still running an older runtime, the server replies 426 and the SDK can no longer talk to that endpoint until the page reloads.

<ToriiProvider> handles this for you, no setup required: it shows a small “a new version is available, please refresh” banner (a reserved, label-driven prompt) and reloads the page when the user clicks it. The strings come from the runtimeOutdatedMessage / runtimeOutdatedRefreshButton labels.

To render your own UI instead, read the flag from useAuth():

import { useAuth } from '@torii-js/torii-react';
function OutdatedBanner() {
const { runtimeIncompatible } = useAuth();
if (!runtimeIncompatible) return null;
return (
<div role="alert">
A new version is available. <button onClick={() => location.reload()}>Refresh</button>
</div>
);
}
MemberTypeDescription
runtimeIncompatiblebooleantrue once the server reports this runtime is too old for an endpoint. The default prompt renders automatically; read this to render your own.

The default banner component is also exported as RuntimeOutdatedPrompt if you want to reuse its markup with your own trigger.

NameTypeDefaultDescription
messagestringn/a (required)The text explaining a reload is needed.
refreshLabelstringn/a (required)Label for the reload button.
onRefresh() => voidn/a (required)Invoked when the user clicks the reload button.

The default prompt rendered by <ToriiProvider> sources message and refreshLabel from the runtimeOutdatedMessage / runtimeOutdatedRefreshButton labels; supply your own strings when reusing the component directly.

import { RuntimeOutdatedPrompt, useAuth } from '@torii-js/torii-react';
function OutdatedBanner() {
const { runtimeIncompatible } = useAuth();
if (!runtimeIncompatible) return null;
return (
<RuntimeOutdatedPrompt
message="A new version is available."
refreshLabel="Refresh"
onRefresh={() => location.reload()}
/>
);
}

The runtime is client-only: loadRuntime never resolves on the server, so the server snapshot is a stable 'loading'. Gated widgets render null during SSR and hydrate cleanly once the client runtime resolves.

import type {
ToriiFailedProps,
RuntimeLoadStatus,
RuntimeOutdatedPromptProps,
RuntimeStatusSnapshot,
UseRuntimeStatusReturn,
} from '@torii-js/torii-react';