Presence
A primitive that manages mount/unmount lifecycle of its children, keeping them in the DOM during exit animations and removing them only after the animation completes. Used internally by Popover, Sheet, Collapsible and other animated components.
Interactive teardown removes animation listeners and cancels pending detection frames. A detached Presence host does not start new callbacks into its former .NET owner. A completed exit hides before the next paint, so the content does not flash back into view while Blazor removes it. Interrupted animations still wait for their replacement to finish.
Static SSR behavior
In true static SSR, Present defines the initial response state. Closed children remain in the HTML as
hidden and inert so the static JavaScript API or a supported parent component can reveal them.
Direct Presence has no built-in browser trigger, and its .NET lifecycle callbacks do not run after the static response.
Hidden markup is not a security boundary. Components such as Collapsible, Sheet, and Drawer
still need their own static-render support.
Static SSR JavaScript API
A true-static Presence instance exports setPresent(owner, present). Put one Presence inside a consumer-owned
container, find its emitted static owner, import the exact module URL from that owner, and pass true to show or
false to close. Keep the controls outside the Presence boundary so closing it does not hide the controls.
Razor markup
Browser module
Install the delegated handler once from your application's JavaScript entry module. Delegation continues to work when enhanced navigation replaces the buttons or Presence markup.
The returned promise completes after the winning lifecycle operation. Its result contains present,
state, and superseded. Closing applies inert immediately and resolves after the
finite exit animations finish and the host becomes hidden. A later show request can supersede an earlier close.
This is browser-only state: it does not update the C# Present parameter or invoke .NET callbacks, and the
next server response is authoritative. Presence controls its own host and participant state; your JavaScript remains
responsible for external trigger ARIA such as aria-expanded. The static owner is absent in interactive render modes.
Basic Toggle
The simplest usage — mount/unmount content driven by a boolean. The child is removed from the DOM when Present is false.
Slide-in Panel
Uses Tailwind's slide-in-from-* / slide-out-to-* animation utilities driven by data-state.
The preview area has a fixed height so the button never shifts when the panel mounts or unmounts.
State Change Callback
OnStateChanged fires with PresenceState.mounted, PresenceState.animating, and PresenceState.unmounted
so you can react to each phase of the lifecycle.
Visibility Changed Callback
OnStateVisibilityChanged reports true after mounted content renders and initial detection setup completes,
and false after the content is fully hidden or unmounted.
Multiple Independent Instances
Each Presence manages its own lifecycle independently. Keep ElementId stable and distinct when callback consumers use it as a content token.
No Animation — Instant Mount/Unmount
When no CSS animation is detected on the child element, Presence falls back to instant mount/unmount.
No data-state animation classes are needed.
Rapid Toggle — Stress Test
Click rapidly to verify that Presence does not corrupt its internal state during fast open/close cycles.
Changes during an initialized animation are coalesced; completion reconciles the latest Present value.