Skip to content
Inertia

Shared data

Lives for the life of the process (or until cleared):

Inertia.share("appName", "Kona")
Inertia.share(mapOf("features" to listOf("a", "b")))
Inertia.share("appName", "Kona");
Inertia.share(Map.of("features", List.of("a", "b")));

Inspect with Inertia.manager().shared(). Clear with manager.clearShared().

Subclass middleware:

class HandleInertia : HandleInertiaRequests() {
override fun share(request: Request) = mapOf(
"path" to request.path,
"auth" to mapOf("user" to currentUser(request)),
)
}

Internally this calls manager.shareForRequest(props) for the duration of the request. The ThreadLocal map is cleared when the middleware finishes.

  1. Global share
  2. Middleware / shareForRequest
  3. Props passed to Inertia.render (highest priority)

Duplicate keys: later layers win. Prefer putting stable app metadata in global share and request-specific flash/auth in middleware so controllers stay thin.

There is no separate “flash” bag in kona-inertia. Typical approach:

  1. Store flash in the session from a controller or filter.
  2. In share(request), read and clear that session key into props (e.g. "flash" to mapOf("success" to …)).
  3. Display on the client from usePage().props.flash (Vue/React adapter APIs — see inertiajs.com).

In unit tests, boot a manager, call share / shareForRequest, render with an explicit Request, and assert the JSON props map. See Testing.