Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

Script cleanup uses the class name instead of the registered scriptName

Closed Beginner friendly
#343 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
76/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
react, typescript
Domain
frontend

Research direction

Start at the useScript implementation described in the issue and inspect how it derives the cleanup name from the constructor. Verify cleanup uses the explicit static scriptName when present while preserving the class-name fallback, then reproduce the OrbitControls mount, unmount, and remount scenario to confirm the script is removed without duplicate-script warnings.

Written by the indexing model from the issue text.

Description

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
  1. Mount <OrbitControls /> on a camera in a Vite application.
  2. Conditionally unmount the controls while keeping the camera entity alive.
  3. 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.

Dominant language
TypeScript
Stars
535
Forks
60
Avg merge
2d 13h
Merged PRs (30d)
13

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from playcanvas/react

All issues in playcanvas/react

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.