Skip to content
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

duplicated defined ccclass in js plugin scripts #15847

Closed
PPpro opened this issue Aug 2, 2023 · 8 comments
Closed

duplicated defined ccclass in js plugin scripts #15847

PPpro opened this issue Aug 2, 2023 · 8 comments
Assignees
Labels

Comments

@PPpro
Copy link
Contributor

PPpro commented Aug 2, 2023

企业微信截图_b981a1cb-d113-4d4f-93d4-9af98faa2db5

@PPpro PPpro self-assigned this Aug 2, 2023
@PPpro PPpro added the Scripting Engine bindings, script system and editor script compiler related label Aug 2, 2023
@dogeFu
Copy link
Contributor

dogeFu commented Aug 2, 2023

https://github.com/cocos/cocos-editor/pull/2259 这个引入的问题,浏览器预览时都会触发脚本重新执行。

@PPpro
Copy link
Contributor Author

PPpro commented Aug 2, 2023

https://github.com/cocos/cocos-editor/pull/2259 这个引入的问题,浏览器预览时都会触发脚本重新执行。

please take a look @yanOO1497 @changhua0118

@PPpro PPpro assigned yanOO1497 and nianba23 and unassigned PPpro Aug 2, 2023
@PPpro PPpro added Bug and removed Scripting Engine bindings, script system and editor script compiler related labels Aug 2, 2023
@yanOO1497
Copy link
Contributor

加载脚本之前不会自己会清空缓存吗? 为什么会有重复 ID 的警告?

@nianba23
Copy link
Contributor

nianba23 commented Aug 4, 2023

加载脚本之前不会自己会清空缓存吗? 为什么会有重复 ID 的警告?

image
image
image
image

The ccclass registration in the plugin script works correctly during the initial startup, but when attempting to register the script again after subsequent reloads, it results in a duplicate registration error.
Module.__protected__.removeCache(codeFile) only clears the cache referenced by the plugin script but does not clear the engine's registered component cache.

please check if it's possible to clear the registered cache before loading the plugin script to registe class or component? @PPpro

@nianba23
Copy link
Contributor

nianba23 commented Aug 4, 2023

The same issues also exist in build task.

@dogeFu
Copy link
Contributor

dogeFu commented Aug 4, 2023

Plugins should not be executed repeatedly.
We don't know what the user will do in the code, what changes will be made to the js global environment
Remove from the module, just re-require this file.
And the pollution of the global environment in plugins is unpredictable unless we can provide a sandbox

@PPpro
Copy link
Contributor Author

PPpro commented Aug 8, 2023

it seems there are 2 issues here:

  1. on 3.8.0, every preview will execute the plugin script, need to take a look at the design of Load in Editor option, it stands to reason that it should not be executed every preview @yanOO1497 @changhua0118
  2. globalEnv.clear() not cleared global environment, resulting in the second execution of the plugin script and an error class duplication registration @PPpro

@PPpro
Copy link
Contributor Author

PPpro commented Aug 8, 2023

globalEnv.clear() not cleared global environment, resulting in the second execution of the plugin script and an error class duplication registration @PPpro

ccclass is register in local variable _idToClass and _nameToClass, need to mannually call js.unregisterClass somewhere

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: Done
Development

No branches or pull requests

4 participants