-
-
Notifications
You must be signed in to change notification settings - Fork 313
feat: preload template style files #825
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Summary of ChangesHello @HardyNLee, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! 此拉取请求旨在通过在游戏初始化阶段预先加载并解析关键 UI 组件(如选择框、文本框、标题)的样式文件,来解决因组件重新渲染时重复加载样式导致的视觉延迟问题。这一改进确保了用户界面的流畅性,提升了用户体验。虽然目前样式文件路径是硬编码的,但设计上已为未来从 Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
这个 PR 通过在游戏初始化时预加载模板样式文件,有效地解决了组件(如 choose)每次出现时因重新加载样式而导致的视觉延迟和样式闪烁问题。整体实现思路清晰,通过将解析后的样式存储在全局的 Map 中,并在组件中通过 useApplyStyle hook 读取,实现了样式的复用。同时,引入了新的 afterStyleUpdate 事件来处理模板更新后的样式刷新,设计合理。
我提出了一些建议,主要涉及性能优化和修复一个潜在的 bug,希望能帮助进一步提升代码质量。
| function useRegisterAfterStyleUpdate(callback: Function) { | ||
| const handler = () => { | ||
| callback(); | ||
| }; | ||
| useEffect(() => { | ||
| WebGAL.events.styleUpdate.on(handler); | ||
| return () => WebGAL.events.styleUpdate.off(handler); | ||
| WebGAL.events.afterStyleUpdate.on(handler); | ||
| return () => WebGAL.events.afterStyleUpdate.off(handler); | ||
| }, []); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
在 useRegisterAfterStyleUpdate hook 中,useEffect 的依赖数组为空 [],这会导致 handler 函数只在组件首次渲染时创建一次,并且捕获了初始的 callback。如果父组件重渲染并传入了新的 callback,事件监听器将继续使用旧的、可能已经过时的 callback,这会引发 stale closure (闭包过期) 的 bug。
为了修复这个问题,应该将 callback 添加到 useEffect 的依赖数组中。同时,可以简化代码,直接在 useEffect 中使用 callback,并为 callback 提供更精确的类型签名。
function useRegisterAfterStyleUpdate(callback: () => void) {
useEffect(() => {
WebGAL.events.afterStyleUpdate.on(callback);
return () => WebGAL.events.afterStyleUpdate.off(callback);
}, [callback]);
}
packages/webgal/src/Core/util/coreInitialFunction/templateLoader.ts
Outdated
Show resolved
Hide resolved
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
介绍
在初始化游戏时预加载模板样式文件。
背景
此 PR 前,像 choose 这种每次出场时都会重新刷新组件,导致每次要重新读取 choose.scss ,重新应用样式,观感上有很明显的延迟,会露出一会原样式。
兼容性
完全兼容现有的模板,替换模板并更新、applyStyle 命令均可正常工作。
其他
您可能会注意到我并没有从 template.json 文件里读取样式文件路径,而是写在一个常量里。因为目前我还没有完全设计好属性结构,以及可能需要和未来的多模板切换留空间,还要一起修改编辑器等等。此 PR 只是一个最基础的影响最小的修改,目前工作得很好,并且也为以后修改留下了空间。