Performance: Sharing state between framework islands
This affects page interactivity speed and smoothness by how efficiently state updates propagate between isolated UI parts.
Use a centralized state store or context shared via lightweight messaging or props passed from Astro root.
Each island fetches and updates shared state independently via global events or polling.
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Independent state updates per island | Multiple DOM updates | Multiple reflows (N times) | High paint cost | [X] Bad |
| Centralized shared state with selective updates | Minimal DOM updates | Single reflow | Low paint cost | [OK] Good |
---
import { signal } from '@astrojs/signals';
const sharedCount = signal(0);
---
// Inside CounterIsland component:
// count.value++}>Clicked {count.value} timesPass the test and this pattern moves unknown