Internal Component._setActive can be accidentally overridden by user Script

オープン
#3,103 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
54/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
静か
技術スタック
typescript
領域
backend

調査の方向性

Read packages/core/src/Component.ts and packages/core/src/Entity.ts, especially the lifecycle call sites linked in the issue; then find the core regression-test conventions. Add a focused test for a Script with a string-keyed _setActive helper, covering component and hierarchy activation plus onAwake and onEnable. Done means the helper is not invoked by Engine lifecycle calls, while the virtual hooks still work and public declarations remain unchanged.

索引モデルが issue の本文から書いたものです。

説明

bug entity script

Describe the bug

A user Script can accidentally override the Engine's internal Component._setActive(value, activeChangeFlag) method with an unrelated helper of the same name. Entity currently invokes the method through normal JavaScript dynamic dispatch, so the user method receives Engine lifecycle arguments and can crash project startup.

This has occurred twice in independent scripts on @galacean/[email protected] (GameManager and UIController).

To Reproduce

import { Entity, Script } from "@galacean/engine";

export default class UIController extends Script {
  private _setActive(entity: Entity | null, active: boolean): void {
    if (entity) entity.isActive = active;
  }
}

entity.addComponent(UIController);

Entity.addComponent() calls:

component._setActive(true, ActiveChangeFlag.All);

Because TypeScript private is emitted as a normal string-keyed prototype method, the call dispatches to UIController._setActive. The boolean true is then treated as an Entity, producing:

TypeError: Cannot create property 'isActive' on boolean 'true'
    at UIController._setActive
    at Entity.addComponent

Current source locations:

Why TypeScript does not catch it

_setActive is marked @internal, and packages/core/tsconfig.json enables stripInternal. The published Component.d.ts therefore contains no _setActive member, so strict consumer typechecking sees the user helper as a new private method rather than an override.

Expected behavior

Internal non-virtual lifecycle operations must not be overrideable by consumer Script members. A user helper named _setActive should not corrupt component activation, while intentionally virtual Engine hooks such as _onAwake and _onEnable must keep their existing behavior.

Suggested ownership boundary

Give this non-virtual operation a package-internal unique Symbol identity and let Entity call it through that identity. The symbol can be imported directly between core modules without being re-exported from packages/core/src/index.ts; @internal + stripInternal can keep the public declarations unchanged. This encodes non-overridability once and does not reserve the string _setActive in user scripts.

A focused regression should add a Script with an unrelated string-keyed _setActive helper, then verify that addComponent, hierarchy activation, onAwake, and onEnable still work and the user helper is not invoked by the Engine.

Environment

  • Engine: 2.0.0-alpha.43
  • Branch/source checked: dev/2.0@490d2bc8ca1f1c187a995da3c913e59c56959a30
  • Browser: Chromium-based runtime
  • OS-specific: No

Screenshots

N/A — the failure occurs before window.engine is created.

主要言語
TypeScript
スター
5.9k
フォーク
413
平均マージ
16時間 17分
マージ済み PR(30日)
41

環境構築

  • Dockerfile・Docker Compose ファイルなし
  • プルリクエストのテンプレートあり
  • コントリビューションガイドなし

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

galacean/engine のほかの issue

galacean/engine の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。