Skip to content

fix(hooks): use the engine-registered script name on useScript cleanup - #345

Merged
abstrakt8 merged 2 commits into
playcanvas:mainfrom
ice1080:fix/script-name-cleanup
Sep 25, 2026
Merged

abstrakt8 merged 2 commits into
playcanvas:mainfrom
ice1080:fix/script-name-cleanup

Conversation

@ice1080

@ice1080 ice1080 commented Sep 10, 2026 •

Copy link
Copy Markdown
Contributor

Use the constructor’s explicit scriptName during cleanup, retaining the class-name fallback.

Add regression coverage for _OrbitCamera with scriptName = 'orbitCamera': unmount removes the script and remount succeeds without duplicate warnings. Also cover fallback cleanup and include a patch changeset.

Fixes #343.

@changeset-bot

changeset-bot Bot commented Sep 10, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 82657da

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@playcanvas/react Patch
@playcanvas/blocks Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@ice1080
ice1080 force-pushed the fix/script-name-cleanup branch from 2d81ff9 to 82657da Compare September 11, 2026 00:09
Pass the script class to ScriptComponent#destroy so the engine resolves
the same name that ScriptComponent#create registered, instead of
re-deriving it in useScript. This keeps cleanup correct as the engine's
naming rules change, and leaves the useScript signature unchanged.

The cast goes through Parameters<ScriptComponent['destroy']>[0] because
released engine typings still name the deprecated ScriptType there
(fixed on engine main in playcanvas/engine#9472).
@abstrakt8 abstrakt8 self-assigned this Sep 25, 2026
@pkg-pr-new

pkg-pr-new Bot commented Sep 25, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@playcanvas/blocks@345
npm i https://pkg.pr.new/@playcanvas/react@345

commit: 85f8bae

@abstrakt8 abstrakt8 changed the title Fix cleanup for scripts with explicit scriptName fix(hooks): use the engine-registered script name on useScript cleanup Sep 25, 2026
@abstrakt8

Copy link
Copy Markdown
Contributor

Thanks for the tests and initial PR! I made a small change to make it more stable by passing the constructor to delete, which means that the engine will resolve the correct name and can survive edge cases like you have observed.

@abstrakt8
abstrakt8 merged commit ef7eeab into playcanvas:main Sep 25, 2026
6 checks passed
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.

Script cleanup uses the class name instead of the registered scriptName

2 participants