Script cleanup uses the class name instead of the registered scriptName
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
- 难度
- 2/5
- 预计耗时
- 1-3 小时
- 新手友好度
- 76/100
- Issue 类型
- 缺陷
- 描述清晰度
- 描述清楚
- 活跃度
- 活跃
- 技术栈
- react, typescript
- 领域
- frontend
调研方向
从 issue 中描述的 useScript 实现开始,检查它如何从 constructor 推导 cleanup 名称。验证存在显式静态 scriptName 时 cleanup 会使用它,同时保留回退到类名的逻辑,然后复现 OrbitControls 的 mount、unmount 和 remount 场景,以确认 script 会被移除且不会出现重复 script 警告。
由索引模型根据 Issue 内容生成。
描述
Description
useScript creates scripts using their constructor but destroys them using a name derived from scriptConstructor.name:
const scriptName = toLowerCamelCase(scriptConstructor.name);
This can differ from the name PlayCanvas uses to register the script when the constructor defines a static scriptName.
Bundlers can expose this mismatch. In my Vite development build, OrbitCamera becomes _OrbitCamera, while its static scriptName remains orbitCamera. Cleanup therefore calls destroy('_OrbitCamera'), which fails to remove the registered script.
Steps to reproduce
- Mount
<OrbitControls />on a camera in a Vite application. - Conditionally unmount the controls while keeping the camera entity alive.
- Mount another camera controller on the same camera.
In my application, the globe orbit controls are unmounted before a separate part of the scene takes over the shared camera. But because the orbit script survives unmounting, the orbit controller continues writing the camera transform, competing with the new controller.
Remounting also produces warnings such as:
script 'orbitCamera' is already added to entity 'camera'
React StrictMode's effect cleanup/remount cycle exposes these duplicate-script warnings as well.
Environment
- @playcanvas/react: 0.11.5
- PlayCanvas: 2.21.3
- React: 19
- Vite: 6
- Desktop Chrome
Proposed fix
Prefer the constructor's explicit scriptName, retaining the existing class-name fallback:
const scriptName = scriptConstructor.scriptName || toLowerCamelCase(scriptConstructor.name);
I verified the mismatch with a PlayCanvas script whose class name is _OrbitCamera and whose static scriptName is orbitCamera: destroying _OrbitCamera returns false and leaves the script attached; destroying orbitCamera succeeds.
Found with the assistance of GPT-6 Astra, but verified manually.
- 主要语言
- TypeScript
- 星标
- 536
- 派生
- 60
- 平均合并
- 2 天 13 小时
- 30 天内合并 PR
- 13
环境准备
这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
playcanvas/react 的其他 Issue
-
难度 4/5 3-5 天 新手友好度 35/100
playcanvas/react#320 ·
维护者通常 1 天内回复
-
难度 3/5 1-2 天 新手友好度 35/100
playcanvas/react#315 · 2 条评论 ·
维护者通常 1 天内回复
-
Expose reference from <Application /> component可能重新可做 @abstrakt8 于 251 天前认领,目前没有进行中的 PR。 未关闭enhancement
playcanvas/react#309 · 1 个 reaction · 已指派 1 人 ·
维护者通常 1 天内回复
-
难度 4/5 3-5 天 新手友好度 45/100
playcanvas/react#308 · 8 条评论 ·
维护者通常 1 天内回复
-
难度 3/5 1-2 天 新手友好度 35/100
playcanvas/react#306 · 3 条评论 ·
维护者通常 1 天内回复
相似的 Issue
-
community first-timers-only good first issue hacktoberfest help wanted low hanging fruit up-for-grabs
难度 1/5 1 小时以内 新手友好度 75/100
lingdojo/kana-dojo#32018 · 1 条评论 · 5 个 reaction ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 72/100
paperclipai/paperclip#15751 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 72/100
BuilderIO/agent-native#7275 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 74/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 65/100
维护者通常 1 天内回复