-
Notifications
You must be signed in to change notification settings - Fork 10.6k
Description
Building on the .NET 10.0 foundation where Blazor.pauseCircuit() and Blazor.resumeCircuit() APIs already exist along with circuit state persistence, this work aims to provide developers with more convenient and powerful tools for managing circuit lifecycle. Currently, these APIs are available but developers must manually implement the logic for when to pause and resume circuits.
Background
What already exists in .NET 10.0:
Blazor.pauseCircuit()andBlazor.resumeCircuit()client-side JavaScript APIs- Circuit state persistence infrastructure with
[PersistentState]attribute - State automatically saved to browser storage when pausing, restored when resuming
- In-memory and distributed (HybridCache) state storage options
The current gap:
Developers must write custom JavaScript to decide when to trigger pause/resume. For example, to pause on tab visibility changes, developers need to manually implement:
window.addEventListener('visibilitychange', () => {
if (document.visibilityState === 'hidden') {
Blazor.pauseCircuit();
} else if (document.visibilityState === 'visible') {
Blazor.resumeCircuit();
}
});This leads to:
- Every developer reinventing the same patterns for common scenarios (hidden tabs, user inactivity)
- Inconsistent implementations across applications
- Hidden tab circuits consuming server resources indefinitely until developers manually implement pausing
- Missed opportunities for resource optimization in high-traffic applications
Objectives
1. Automatic Circuit Pausing on Inactivity (#64886)
Provide opt-in configuration that automatically calls the existing Blazor.pauseCircuit() and Blazor.resumeCircuit() APIs based on common inactivity scenarios:
Primary feature:
- Automatically pause circuits when browser tabs are hidden for a configurable period (default: 2 minutes)
- Automatically resume when tabs become visible again
- Simple configuration API requiring no custom JavaScript
Secondary feature (extension):
- Detect user inactivity on visible tabs (no mouse/keyboard/touch events)
- Configurable timeout (default: 5 minutes) and customizable activity events
- Automatic resume on any detected user activity
2. Server-Triggered State Persistence (#62327)
Extend pause/resume to support server-initiated pausing:
- Add
RequestCircuitPause()API on theCircuitclass accessible viaCircuitHandler - Allow server code to signal the browser to pause the circuit
- Enable server-side resource management policies (e.g., pause circuits during known idle periods, pause based on server load)
- Maintain client involvement to ensure proper UX (blocking UI with dialog, similar to reconnect dialog)
Benefits
- Developer convenience: No need to write custom JavaScript for common pause/resume scenarios
- Consistent behavior: Standardized patterns across Blazor applications
- Improved resource utilization: Automatically free server resources from idle circuits instead of requiring manual implementation
- Reduced hosting costs: Lower memory and CPU consumption in high-traffic applications
- Server-side control: Enable sophisticated resource management strategies driven by server conditions
- Better scalability: Support more concurrent users by reclaiming resources from inactive circuits
Success Criteria
- Developers can enable automatic pausing with simple configuration (no custom JavaScript required)
- Circuits pause and resume reliably using the existing
pauseCircuit()/resumeCircuit()infrastructure - Server code can request circuit pausing through a clean API
- State persistence and restoration works seamlessly (leveraging existing
[PersistentState]infrastructure) - Users experience smooth transitions without losing application state
- Clear documentation and examples for common scenarios
This work builds upon the foundation of pause/resume APIs introduced in .NET 10.0 by making them more accessible and automatic, reducing the burden on developers while improving resource efficiency for Blazor Server applications.