refactor: standardize Layer on class fields with grouped ordering#8649
Conversation
Declares every `Layer` instance property as a class field with JSDoc and sensible defaults, and reorders them into labelled logical groups (identity, enabled state, sorting, render target & clear flags, callbacks, mesh instances, lights, cameras, gsplat, composition, and profiler). The constructor is slimmed down to only option-driven / runtime initialization. No behavioral changes. Made-with: Cursor
There was a problem hiding this comment.
Pull request overview
Refactors Layer to standardize instance properties as top-of-class fields with grouped ordering, keeping the constructor focused on option-driven initialization and runtime work.
Changes:
- Promotes and groups
Layerinstance properties into ordered class fields with JSDoc and defaults where applicable. - Simplifies the constructor to primarily handle id allocation, option copying, and initial
onEnable()call. - Narrows the
// #if _PROFILERguard to only wrap profiler-related fields and adds a JSDoc@importforRenderTarget.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…ation
Declaring `renderTarget` as a class field installs an own property on
every Layer instance, which shadows the `_removedClassProperty(Layer,
'renderTarget')` accessor on the prototype and silences the
"has been removed" warning. Drop the class-field declaration (and the
now-unused `@import { RenderTarget }`) and document the reason inline
so future refactors don't re-introduce the issue. The conditional
`this.renderTarget = options.renderTarget` in the constructor is
unchanged and now correctly falls through to the deprecation setter.
Made-with: Cursor
The comment explaining why `renderTarget` is deliberately not a class field is more discoverable next to the actual `this.renderTarget = options.renderTarget` assignment in the constructor than in the class body. No behavioral change. Made-with: Cursor
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 1 out of 1 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
`Layer#renderTarget` is registered as a removed property in
`src/deprecated/deprecated.js` via `_removedClassProperty(Layer, 'renderTarget')`,
and nothing in the engine (src, examples, scripts, tests) ever reads
`layer.renderTarget`. The ctor block
if (options.renderTarget) {
this.renderTarget = options.renderTarget;
}
therefore only ever hit the deprecation setter (logging an error and
discarding the value) and had no useful effect. Remove the block and the
now-orphaned explanatory comment. The `_removedClassProperty` entry in
`deprecated.js` stays for engine v2 cleanup, per maintainer request.
Made-with: Cursor
Made-with: Cursor
Summary
Layeron class fields: every instance property is declared at the top of the class body with JSDoc and a default value (where appropriate), so the constructor no longer mixes class-field declarations with property initialization.layerCounter, copying values fromoptions, and the initialonEnable()invocation.if (options.renderTarget) { this.renderTarget = options.renderTarget; }block from the constructor.Layer#renderTargetis already registered as a removed property via_removedClassProperty(Layer, 'renderTarget')insrc/deprecated/deprecated.js, and nothing in the engine readslayer.renderTarget, so the block only ever hit the deprecation setter and had no useful effect. The_removedClassPropertyentry itself stays for engine v2 cleanup.No behavioral changes.
The
// #if _PROFILERguard now wraps only the five profiler fields.Test plan
npm run buildsucceeds (class-field +// #if _PROFILERpreprocessing).npm testpasses.id, one disabled, and one withonEnable/onDisable) renders identically tomain.