Skip to content

重构:使用 requestAnimationFrame 优化 UI 渲染#2

Merged
kira1928 merged 7 commits intomainfrom
feat-yield-to-main-6772570358825470314
Jan 23, 2026
Merged

重构:使用 requestAnimationFrame 优化 UI 渲染#2
kira1928 merged 7 commits intomainfrom
feat-yield-to-main-6772570358825470314

Conversation

@google-labs-jules
Copy link
Copy Markdown
Contributor

本次提交用一个基于 requestAnimationFrame 的新工具函数 yieldToMain 替换了代码中用于UI渲染让步的 setTimeout 调用。这是一种更高效、更可靠的方法,可以防止长时间运行的任务阻塞UI线程,从而提高应用的响应性能。此更改已成功应用并验证于 GopPlayer.tsx 组件。


PR created automatically by Jules for task 6772570358825470314 started by @kira1928

引入 `yieldToMain` 工具函数,使用 `requestAnimationFrame` 代替 `setTimeout` 来让出主线程。

此项重构可以防止长时间运行的任务阻塞浏览器渲染,从而提高 UI 响应速度并消除不必要的延迟。

- 新增 `web-src/src/utils/yieldToMain.ts` 工具文件。
- 将 `web-src/src/components/GopPlayer.tsx` 中所有用于延迟执行的 `setTimeout` 调用替换为新的 `yieldToMain` 函数。

(注意: 由于在 `web-src/src/App.tsx` 文件上的修改操作反复遇到问题,本次提交并未包含对该文件的更改。)
@google-labs-jules
Copy link
Copy Markdown
Contributor Author

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@kira1928
Copy link
Copy Markdown
Owner

/gemini review

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

本次提交将 setTimeout 调用替换为基于 requestAnimationFrameyieldToMain 工具函数,以优化 UI 渲染。这是一个很好的改进,能够更高效、更可靠地防止长时间运行的任务阻塞 UI 线程,从而提高应用的响应性能。代码变更清晰,符合预期,并且 yieldToMain 函数的实现也正确无误。干得好!

@kira1928 kira1928 marked this pull request as ready for review January 23, 2026 16:04
Copilot AI review requested due to automatic review settings January 23, 2026 16:04
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

该 PR 引入基于 requestAnimationFrameyieldToMain 工具函数,用于替换部分 setTimeout 让步逻辑,以提升 UI 渲染/响应性。

Changes:

  • 新增 yieldToMain():用 rAF 在下一帧让出主线程
  • GopPlayer.tsx 中多处 setTimeout 让步替换为 yieldToMain()
  • App.tsx 中解析前的 UI 让步替换为 yieldToMain()
  • 更新 AI Review Relay Action 版本并补充 pr_number 参数

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
web-src/src/utils/yieldToMain.ts 新增基于 rAF 的主线程让步工具函数
web-src/src/components/GopPlayer.tsx yieldToMain 替代多处 setTimeout 以改善 UI 响应
web-src/src/App.tsx 解析前用 yieldToMain 让进度 UI 先渲染
.github/workflows/ai-review.yml 升级 action 版本并传递 PR number

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.


// 强制让 UI 有时间渲染进度条
await new Promise(r => setTimeout(r, 100));
await yieldToMain();
Copy link

Copilot AI Jan 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This await now depends on requestAnimationFrame. If the user switches to a background tab (or the page is hidden) right after starting analysis, yieldToMain() may not resolve promptly and can delay or stall starting the streaming parse. Prefer a yield mechanism that still progresses when hidden (e.g., yieldToMain with a setTimeout fallback, or keep a small timer-based yield here).

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot open a new pull request to apply changes based on this feedback

kira1928 and others added 2 commits January 24, 2026 01:10
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copy link
Copy Markdown

Copilot AI commented Jan 23, 2026

@kira1928 I've opened a new pull request, #3, to work on those changes. Once the pull request is ready, I'll request review from you.

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@kira1928 kira1928 merged commit 0d4ef1c into main Jan 23, 2026
@kira1928 kira1928 deleted the feat-yield-to-main-6772570358825470314 branch January 23, 2026 16:22
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.

3 participants