fix: failed to modify source transform#838
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! 此拉取请求旨在解决 #832 引入的一个关键错误,该错误导致编辑器在预览时卡死。核心问题被确定为在转换赋值过程中对源对象进行了意外修改。通过在应用转换之前对源对象进行深度克隆,此拉取请求确保了数据完整性,并防止编辑器进入不稳定状态,从而提高了预览功能的稳定性和可靠性。 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
|
| export default class PixiStage { | ||
| public static assignTransform<T extends ITransform>(target: T, source?: ITransform, convertAlpha = true) { | ||
| if (!source) return; | ||
| let cloneSource = cloneDeep(source); |
There was a problem hiding this comment.
为了解决只读属性无法修改的问题,这里使用了 cloneDeep,这虽然能解决问题,但 cloneDeep 是一个深拷贝操作,当 source 对象复杂时可能会有性能开销。分析此函数可知,我们仅修改了 source 对象的一级属性(alpha 和 alphaFilterVal),而嵌套的对象(如 scale 和 position)仅被读取。因此,使用浅拷贝就足以解决问题,并且性能会好得多。
建议使用对象展开语法 { ...source } 来进行浅拷贝。另外,由于 cloneSource 变量未被重新赋值,建议使用 const 声明。
| let cloneSource = cloneDeep(source); | |
| const cloneSource = { ...source }; |
MakinoharaShoko
left a comment
There was a problem hiding this comment.
assignTransform 是一个调用频繁的函数,每一帧都会调用,深拷贝可能影响性能,建议单独取出受影响的字段赋值给临时变量。
3eee53b to
298dead
Compare
已修改 |
介绍
#832 后,在编辑器那边预览的时候,有几率卡死并触发以下错误。
cloneDeep一下似乎就好了