Mounted Identity and Lifetime
Associate state with structural paths and preserve ownership through speculative scene updates.
Mounted state survives a new view description only when the runtime can associate it with the same place in the interface. Kit establishes that association through paths assembled during evaluation, using sibling positions or keys, concrete type scopes, and a final named field.
Structural Identity
Conceptually, a slot might be described as:
ancestor scopes / child key "document-42" / row type scopes / field "editing"This conceptual path shows how several scopes contribute to one slot; it is not a serialized format. Containers establish child scopes, wrappers can add scopes of their own, and view evaluation adds concrete type scopes before the named field is looked up.
Because their ancestor paths differ, two instances of the same view keep separate storage. A key makes a child's path stable as siblings reorder within the same parent, but it cannot move that storage to an unrelated parent scope.
Mount Initialization
cx.state("editing", initializer) retrieves or creates a mounted binding through the context's retained storage. The initializer runs for a new identity, not as a synchronization hook whenever props change.
Changing the key, concrete type path, or relevant structure can create new state. Slot names must be unique within the body and their stored types must remain stable.
Accepted Tree Lookup
At the beginning of a build, Kit reconstructs mounted lookup from the accepted UiNode tree. Evaluation uses that lookup to attach existing or newly created values to candidate nodes. The temporary lookup is cleared afterward, leaving the trees and retained handles responsible for actual ownership.
An accepted insertion adds its new slots to the ownership available for the next build. If insertion is rejected, those speculative slots do not become the baseline. Removal follows the same rule in reverse: acceptance releases the tree's ownership, while rejection leaves the old tree's values available.
Ownership and Value Rollback
If an action changes a counter and the resulting scene is rejected, the accepted tree stays unchanged but the counter's model value remains changed. Mounted ownership and application mutation are different layers.
Bindings, callbacks, memo caches, or application handles can extend storage lifetime after a node disappears. Final lease drop queues retirement for collection rather than promising immediate deallocation at removal.
Raw State Storage
A raw State<T> handle identifies runtime storage without carrying the mounted ownership lease described here. Host-owned state normally remains with the runtime that allocated it, so dropping a handle does not imply the mounted cleanup behavior. All state handles still need to be used with their originating runtime.
See reconciliation and environment for related ownership boundaries.
Source Reference
The following files in the Hera checkout define the behavior described on this page.
crates/kit/src/ag/reactive.rscrates/kit/src/view/context.rscrates/kit/src/ag/binding.rs