Surface Lifecycle
When present() is called, Imperative Surface performs a small lifecycle:
- Check that the code is running in a browser.
- Create an
imperative-surfacehost element. - Append the host to
document.body. - Create a React root for the surface.
- Render the backdrop and surface panel.
- Render the supplied
bodycomponent. - Wait for
pop()or backdrop dismissal. - Start the closing animation.
- Unmount the React root and remove the host element.
- Resolve the Promise.
The Promise is resolved after the closing animation finishes.
Browser-only API
Surfaces require window and document. Calling present() during server rendering rejects with Window not available.
For Next.js, see SSR Considerations.
Body lifecycle
The body is a normal React component. It can use hooks, local state, forms, data fetching, and other React features.
function MySurface({ pop }: SurfaceContext<boolean>) {
const [loading, setLoading] = useState(false);
// ...
}When the surface is closed, its React root is unmounted automatically.