Plugin

class litestar_vite.inertia.plugin.InertiaPlugin[source]

Bases: InitPluginProtocol

Inertia plugin.

This plugin configures Litestar for Inertia.js support, including: - Session middleware requirement validation - Exception handler for Inertia responses - InertiaRequest and InertiaResponse as default classes - Type encoders for StaticProp and DeferredProp

Async Prop Resolution:

Async optional()/defer()/lazy()/once() callbacks are pre-resolved by InertiaResponse on the request event loop before the body is serialized. This guarantees they share the loop with request-scoped async resources (asyncpg/aiosqlite/sqlspec sessions), so callbacks can safely use those resources.

SSR Client Pooling:

When SSR is enabled, the plugin maintains a shared httpx.AsyncClient for all SSR requests. This provides significant performance benefits: - Connection pooling with keep-alive - TLS session reuse - HTTP/2 multiplexing (when available)

The client is initialized during app lifespan and properly closed on shutdown. Access via inertia_plugin.ssr_client if needed.

Example:

from litestar_vite.inertia import InertiaPlugin, InertiaConfig

app = Litestar(
    plugins=[InertiaPlugin(InertiaConfig())],
    middleware=[ServerSideSessionConfig().middleware],
)
__init__(config: InertiaConfig) None[source]

Initialize the plugin with Inertia configuration.

lifespan(app: Litestar) AsyncGenerator[None, None][source]

Lifespan to manage the shared SSR HTTP client.

Parameters:

app – The Litestar instance.

Yields:

An asynchronous context manager.

property ssr_client: AsyncClient | None

Return the shared httpx.AsyncClient for SSR requests.

The client is initialized during app lifespan and provides connection pooling, TLS session reuse, and HTTP/2 multiplexing benefits.

Returns:

The shared AsyncClient instance, or None if not initialized.

on_app_init(app_config: AppConfig) AppConfig[source]

Configure application for use with Vite.

Parameters:

app_config – The AppConfig instance.

Raises:

ImproperlyConfiguredException – If the Inertia plugin is not properly configured.

Returns:

The AppConfig instance.