Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

Script cleanup uses the class name instead of the registered scriptName

Chiusa Adatta ai principianti
#343 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
76/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
react, typescript
Ambito
frontend

Direzione di ricerca

Inizia dall’implementazione di useScript descritta nell’issue e verifica come ricava il nome di cleanup dal constructor. Verifica che cleanup utilizzi lo scriptName statico esplicito quando presente, mantenendo il fallback al nome della classe, quindi riproduci lo scenario di mount, unmount e remount di OrbitControls per confermare che lo script venga rimosso senza avvisi di script duplicati.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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.

Lingua principale
TypeScript
Stelle
536
Fork
60
Merge medio
2g 13h
PR unite (30g)
13

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di playcanvas/react

Tutte le issue di playcanvas/react

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.