[4.0.0] Phaser.Class (incl. Class.mixin) is not exposed on the public ESM namespace — forces third-party plugins into inadequate mixin fallbacks
メンテナーはふだん 3 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 2/5
- 見積もり時間
- 1〜3時間
- 初心者へのやさしさ
- 62/100
- issue の種類
- バグ
- 明瞭さ
- 明確に書かれている
- 活発さ
- 静か
- 技術スタック
- javascript, vite
調査の方向性
src/index.js または ESM の公開サーフェスアグリゲーターから始めて、utils/Class.js を調べます。次に、ソースのエクスポートと生成された phaser.esm.js マニフェストを比較します。最小限の repro.ts import を実行し、Phaser.Class、Class.mixin、Class.extend が公開 namespace に公開されていることを確認します。
索引モデルが issue の本文から書いたものです。
説明
[4.0.0] Phaser.Class (incl. Class.mixin) is not exposed on the public ESM namespace — forces third-party plugins into inadequate mixin fallbacks
Versions
- Phaser:
4.0.0(latest stable) - Build: ESM via Vite
7.3.2(node_modules/phaser/dist/phaser.esm.js) - Browser: Chrome (any recent), renderer-agnostic (this is a JS-namespace ergonomics issue, not a render issue)
- OS: Windows
- Third-party plugin hitting the fallback:
@esotericsoftware/[email protected]
Summary
Phaser.Class is present inside the ESM bundle (the internal Class utility including Class.mixin, Class.extend, and the getProperty helper that unwraps { value: { get, set } } accessor descriptors) but is not re-exported on the public Phaser object that consumers receive via import * as Phaser from "phaser".
Third-party plugins that feature-detect Phaser.Class?.mixin (including the official @esotericsoftware/spine-phaser-v4) therefore always take their fallback branch on ESM builds. Those fallbacks typically don't replicate Class.mixin's def.value-unwrap semantics, which causes Phaser 4 component mixins (Transform, Origin, Alpha, Flip, ScrollFactor, Visible, Depth, ComputedSize, ...) to be installed as broken data descriptors instead of real accessors on the consuming class's prototype.
The consequence for my project: SpineGameObject.rotation reads as a literal { get, set } object, GetCalcMatrix produces NaN, and all Spine skeletons render invisible.
This request is a small API ergonomics fix on Phaser's side. The actual rendering bug is more accurately a bug in spine-phaser-v4's fallback (filed at EsotericSoftware/spine-runtimes#3065. But re-exporting Phaser.Class here would make that fallback path unreachable and pre-empt the same class of bug in every other plugin that does the same feature-detect.
Expected behavior
import * as Phaser from "phaser";
typeof Phaser.Class; // 'function'
typeof Phaser.Class.mixin; // 'function'
typeof Phaser.Class.extend; // 'function'
— identical to Phaser 3.x, where consumers and plugins have relied on Phaser.Class.mixin since at least 3.0 to correctly install Phaser's component accessors on their own classes.
Actual behavior
import * as Phaser from "phaser";
typeof Phaser.Class; // 'undefined'
Plugins feature-detecting Phaser.Class?.mixin fall back to hand-rolled mixin code that doesn't implement Phaser's descriptor-unwrap contract, and their users get invisible / broken Game Objects.
Minimal repro
// repro.ts
import * as Phaser from "phaser";
// fail
console.log("Phaser.Class:", Phaser.Class);
console.log("Phaser.Class.mixin:", (Phaser as any).Class?.mixin);
// Confirm Class exists inside the bundle but isn't re-exported:
// rg -n "Class\\.mixin|var Class|Class = " node_modules/phaser/dist/phaser.esm.js
Result on Phaser 4.0.0:
Phaser.Class: undefined
Phaser.Class.mixin: undefined
(Class + Class.mixin are present in phaser.esm.js; just not listed in the final export manifest.)
Why this matters (concrete downstream break)
@esotericsoftware/[email protected] contains this code in dist/mixins.js:
// ~L53
function applyMixins(target, mixins) {
if (Phaser.Class?.mixin) {
Phaser.Class.mixin(target, mixins); // never taken on ESM
} else {
applyMixinsFallback(target, mixins); // taken on ESM — broken
}
}
// ~L40
function applyMixinsFallback(target, mixins) {
for (const mixin of mixins) {
const source = mixin.prototype || mixin;
for (const key of Object.getOwnPropertyNames(source)) {
if (key === "constructor") continue;
const descriptor = Object.getOwnPropertyDescriptor(source, key);
if (descriptor) {
Object.defineProperty(target.prototype, key, descriptor); // naive
}
}
}
}
The fallback doesn't honor the def.value unwrap step that Phaser's own getProperty performs:
// phaser.esm.js — getProperty (invoked by Class.mixin)
var def = Object.getOwnPropertyDescriptor(definition, k);
if (def.value && typeof def.value === 'object') {
def = def.value; // ← the step every fallback fails to replicate
}
if (def && hasGetterOrSetter(def)) { /* install as accessor */ }
So Phaser.GameObjects.Components.Transform.scale, which ships as:
scale: {
get: function () { return (this._scaleX + this._scaleY) / 2; },
set: function (value) { /* ... */ }
}
gets installed on SpineGameObject.prototype as a data property whose value is { get, set }. hero.scale returns that object, NaN propagates, skeleton invisible.
A minimal prototype inspection confirms it:
const desc = Object.getOwnPropertyDescriptor(
Object.getPrototypeOf(hero),
"rotation"
);
// Phaser 4 ESM: { value: { get: ƒ, set: ƒ }, writable: true, enumerable: true, configurable: true }
// Expected: { get: ƒ, set: ƒ, enumerable: true, configurable: true }
Suggested fix
Re-export Class from the ESM entry so import * as Phaser from "phaser" receives it:
// src/index.js (or wherever the ESM public-surface aggregator lives)
export { default as Class } from "./utils/Class.js";
or, if the existing Phaser-namespace builder is centralized, add Class alongside the other already-exposed utilities (Math, Utils, Structs, Scenes.Events, etc.).
That's the entire fix. Class already exists in the bundle; only the public re-export is missing.
Bisect
| Configuration | Phaser.Class.mixin accessible? |
|---|---|
| Phaser 3.90.0 ESM | ✅ |
| Phaser 4.0.0 ESM | ❌ (this issue) |
| Phaser 4.0.0 global/UMD builds | ✅ |
Cross-reference
I filed the matching issue against spine-phaser-v4 so they're aware their fallback needs to match Class.mixin's semantics regardless of what Phaser decides here EsotericSoftware/spine-runtimes#3065
Either fix alone solves my specific symptom. Both fixes together would make it robust for every plugin author who reaches for Phaser.Class.mixin on instinct.
Workaround (what I'm shipping today)
Consumer-side prototype-walking shim against SpineGameObject.prototype that reinstalls the wrapped descriptors as real accessors. Works, but obviously not a pattern that scales to every plugin that touches Phaser mixins:
import * as Phaser from "phaser";
import { SpineGameObject } from "@esotericsoftware/spine-phaser-v4";
const FIXED = Symbol.for("spine-phaser-v4.accessorsPatched");
const isWrappedAccessor = (d) =>
d && typeof d.value === "object" && d.value !== null && "writable" in d &&
(typeof d.value.get === "function" || typeof d.value.set === "function");
export function installSpinePhaserCompat() {
const proto = SpineGameObject?.prototype;
if (!proto || proto[FIXED]) return;
const stopAt = Phaser.GameObjects.GameObject.prototype;
let current = proto;
while (current && current !== stopAt && current !== Object.prototype) {
for (const key of Object.getOwnPropertyNames(current)) {
if (key === "constructor") continue;
const desc = Object.getOwnPropertyDescriptor(current, key);
if (!isWrappedAccessor(desc)) continue;
const { get, set } = desc.value;
Object.defineProperty(current, key, { configurable: true, enumerable: desc.enumerable, get, set });
}
current = Object.getPrototypeOf(current);
}
Object.defineProperty(proto, FIXED, { value: true });
}
- 主要言語
- JavaScript
- スター
- 40.7k
- フォーク
- 7.2k
- PR マージ指標
- 30日以内にマージされた PR はありません
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
phaserjs/phaser のほかの issue
-
難易度 1/5 1時間未満 初心者へのやさしさ 80/100
メンテナーはふだん 3 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 80/100
メンテナーはふだん 3 日以内に返信
-
Type definition for TilemapLayer.getTileAt is wrong対応中かも @hkbughk が 34 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
メンテナーはふだん 3 日以内に返信
-
Shader.preDestroy leaks its ShaderQuad's vertex buffer and VAO on every create/destroy cycle (4.2.1)対応中かも @k1epg01ng129-eng が 32 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 86/100
メンテナーはふだん 3 日以内に返信
-
Black opaque background on transparent Phaser.Text textures in Phaser 4.2.1 on older iOS WebGL対応中かも @SamuelMalmfors が 14 日前に担当しました。 オープン
難易度 1/5 1時間未満 初心者へのやさしさ 85/100
phaserjs/phaser#7392 · コメント 1 件 ·
メンテナーはふだん 3 日以内に返信
phaserjs/phaser の issue をすべて見る
似ている issue
-
enhancement ready
難易度 2/5 1〜3時間 初心者へのやさしさ 84/100
-
enhancement
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
DCGM/semant-demo#708 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
-
agents area: runtime automation chore cli consistency dependencies developer-experience difficulty: easy documentation enhancement good first issue help wanted hygiene json-output priority: P3 starters tests
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
メンテナーはふだん 1 日以内に返信
-
Client codegen: an import repeated in an impl file is emitted twice, and the browser rejects the module対応中かも @MalithaPrabhashana が今日担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 64/100
jaseci-labs/jac#10756 ·
メンテナーはふだん 1 日以内に返信