0
0
Astroframework~8 mins

Sharing state between framework islands in Astro - Performance & Optimization

Choose your learning style9 modes available
Performance: Sharing state between framework islands
MEDIUM IMPACT
This affects page interactivity speed and smoothness by how efficiently state updates propagate between isolated UI parts.
Sharing user input state between multiple framework islands on the same page
Astro
Use a centralized state store or context shared via lightweight messaging or props passed from Astro root.
Updates propagate once and only affected islands re-render, reducing overhead.
📈 Performance GainSingle reflow and repaint per state change regardless of island count
Sharing user input state between multiple framework islands on the same page
Astro
Each island fetches and updates shared state independently via global events or polling.
Triggers multiple redundant updates and re-renders causing input lag and wasted CPU.
📉 Performance CostTriggers N reflows and repaints per update where N is number of islands
Performance Comparison
PatternDOM OperationsReflowsPaint CostVerdict
Independent state updates per islandMultiple DOM updatesMultiple reflows (N times)High paint cost[X] Bad
Centralized shared state with selective updatesMinimal DOM updatesSingle reflowLow paint cost[OK] Good
Rendering Pipeline
State changes flow from the centralized store to framework islands, triggering selective updates and repainting only necessary DOM nodes.
JavaScript Execution
Layout
Paint
Composite
⚠️ BottleneckLayout and Paint due to multiple independent island re-renders
Core Web Vital Affected
INP
This affects page interactivity speed and smoothness by how efficiently state updates propagate between isolated UI parts.
Optimization Tips
1Avoid independent state updates in each island to reduce reflows.
2Use centralized state management to batch updates and minimize repaints.
3Monitor reflows and paints in DevTools to detect inefficient state sharing.
Performance Quiz - 3 Questions
Test your performance knowledge
What is a main performance problem when each framework island updates shared state independently?
AFaster initial page load
BMultiple redundant reflows and repaints slowing input responsiveness
CReduced JavaScript bundle size
DImproved visual stability
DevTools: Performance
How to check: Record a performance profile while interacting with shared state UI. Look for multiple layout and paint events triggered by state changes.
What to look for: High number of reflows and long scripting times indicate inefficient state sharing.