Skip to content

Conversation

@draedful
Copy link
Collaborator

@draedful draedful commented Nov 7, 2025

Fixes race conditions in the BlocksList component and scheduler system that prevented HTML blocks from rendering when tabs were opened in the background or when debounced functions were called recursively.

1. Background Tab Rendering Issue

When a browser tab was opened in the background, HTML blocks would not render until the user interacted with the page. This was caused by browsers pausing or throttling requestAnimationFrame calls in inactive tabs.

Solution
  • Added listener for the visibilitychange event in GlobalScheduler
  • When a tab becomes visible, immediately triggers performUpdate() if the scheduler is running

2. Race Condition in debounce/throttle

When a debounced or throttled function triggered new calls to itself during execution, the state management could lead to conflicts due to incorrect operation ordering.

Solution
  • Save removeScheduler reference

3. Performance Optimization (BlocksList.tsx)

Replaced lodash.isEqual + sort with Set-based comparison for better performance on small to medium lists (10-100 blocks).

Performance gains (see benchmarks):

  • 10 blocks: ~2x faster
  • 50 blocks: ~3x faster
  • 100 blocks: ~4x faster

perf(BlockList): use a faster way to determine if the list of visible components has changed.
@draedful draedful requested a review from Antamansid as a code owner November 7, 2025 11:24
@gravity-ui-bot
Copy link
Contributor

Preview is ready.

@draedful draedful changed the title fix(BlockList): fix race condition in BlockList. fix(BlockList): fix race condition in BlockList Nov 7, 2025
@draedful draedful force-pushed the fix-first-render-html branch from c08bc3b to 667e58b Compare November 7, 2025 12:19
@draedful draedful merged commit b24f536 into main Nov 10, 2025
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants