Skip to content

Add setTimeout fallback to yieldToMain for hidden/backgrounded tabs#3

Closed
Copilot wants to merge 1 commit intofeat-yield-to-main-6772570358825470314from
copilot/sub-pr-2
Closed

Add setTimeout fallback to yieldToMain for hidden/backgrounded tabs#3
Copilot wants to merge 1 commit intofeat-yield-to-main-6772570358825470314from
copilot/sub-pr-2

Conversation

Copy link
Copy Markdown

Copilot AI commented Jan 23, 2026

The yieldToMain() utility relied solely on requestAnimationFrame, which browsers heavily throttle when tabs are hidden. This could stall streaming parse operations if users background the tab during analysis.

Changes

  • Added document visibility detection in yieldToMain()
  • Falls back to setTimeout(resolve, 0) when document is hidden or rAF unavailable
  • Preserves rAF behavior for visible pages (more efficient for UI updates)
export function yieldToMain(): Promise<void> {
  return new Promise(resolve => {
    const hasRaf = typeof requestAnimationFrame === 'function';
    const isDocumentHidden = 
      typeof document !== 'undefined' && (document as any).hidden === true;

    if (!hasRaf || isDocumentHidden) {
      setTimeout(resolve, 0);
      return;
    }
    requestAnimationFrame(() => resolve());
  });
}

This ensures streaming operations progress regardless of tab visibility while maintaining optimal rendering behavior for active tabs.


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI changed the title [WIP] Update requestAnimationFrame optimization for UI rendering Add setTimeout fallback to yieldToMain for hidden/backgrounded tabs Jan 23, 2026
Copilot AI requested a review from kira1928 January 23, 2026 16:19
@kira1928 kira1928 closed this Jan 23, 2026
@kira1928 kira1928 deleted the copilot/sub-pr-2 branch January 23, 2026 16:21
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.

2 participants