#[Isolate]
Exclude a component from request pooling for independent AJAX requests.
Basic Usage
By default, LiVue batches multiple simultaneous AJAX requests into a single HTTP call. Use #[Isolate] to opt out and send requests independently.
use LiVue\Attributes\Isolate;
#[Isolate]
class SlowDashboard extends Component
{
public array $stats = [];
public function loadStats()
{
// Slow external API call
$this->stats = ExternalApi::fetchStats();
}
}
Request Pooling Explained
Without isolation, LiVue's request pooling works like this:
Without #[Isolate]
Requests are batched together:
With #[Isolate]
Requests are independent:
When to Use
Components that fetch from slow external services shouldn't block others.
Analytics dashboards or reports with complex queries.
Components that need to respond quickly regardless of other operations.
Components whose response time varies significantly.
Visual Example
Consider a page with a fast counter and a slow dashboard:
// Fast counter - stays in pool
class Counter extends Component
{
public int $count = 0;
public function increment() { $this->count++; }
}
// Slow dashboard - isolated
#[Isolate]
class Dashboard extends Component
{
public function refresh()
{
// 3-second API call won't block Counter
sleep(3);
}
}
Without #[Isolate], clicking both buttons would make the counter wait 3 seconds. With isolation, the counter responds instantly.
How It Works
-
1
Flag set at render
The
isolate: trueflag is added to the snapshot memo and asdata-livue-isolateon the wrapper. -
2
Client detects isolation
When a request is made, the runtime checks for the isolate flag in the payload.
-
3
Separate fetch sent
Instead of being queued in the pool, an immediate separate HTTP request is dispatched.
Considerations
More HTTP Requests
Isolated components send separate requests, which increases total HTTP traffic. Use this attribute only when the performance benefit outweighs the cost of additional requests.