Skip to content

refactor(components): drive cloneComponent from shared _properties lists#8879

Merged
willeastcott merged 1 commit into
mainfrom
refactor/clone-from-properties-ui
Jun 11, 2026
Merged

refactor(components): drive cloneComponent from shared _properties lists#8879
willeastcott merged 1 commit into
mainfrom
refactor/clone-from-properties-ui

Conversation

@willeastcott

Copy link
Copy Markdown
Contributor

Summary

Second PR in the component-consistency series (follows #8878).

Button, scroll-view, scrollbar and collision systems already define a module-level _properties array used by initializeComponentData, but each duplicated the same list as a hand-written object literal in cloneComponent — the exact drift hazard that bit the camera system in #8878. This PR builds the clone data from the shared list instead.

Behavior-preserving — before converting, each clone literal was verified to match its _properties list 1:1:

  • button: 14 properties + enabled, exact match.
  • scroll-view: 14 properties + enabled, exact match (init order, which is what matters, is unchanged).
  • scrollbar: 4 properties + enabled, exact match.
  • collision: the two intentional differences are now explicit and commented — type is initialized outside the property list (written to the backing field before the list is applied), and shape is skipped because the type implementation creates it during initialization and must not be shared with the clone.

Clone value semantics are unchanged: the loop passes the same references the literals passed (component setters handle copying, covered by the existing Color/Vec input-cloning tests).

Testing

  • All four systems have dedicated #cloneComponent tests (clone round-trips, entity-ref remapping) — 95 tests pass unchanged, no test edits needed
  • Full npm test suite passes (1817 passing)
  • ESLint clean on changed files

Remaining PRs in the series

  1. Hoist inline lists in model, sound, rigid-body
  2. Animation system (isolated due to its post-add clone assignment)
  3. Standardize beforeremove handler naming across all systems

🤖 Generated with Claude Code

Button, scroll-view, scrollbar and collision systems already define a
module-level _properties array used by initializeComponentData, but each
duplicated the same list as a hand-written object literal in
cloneComponent. Build the clone data from the shared list instead (the
camera pattern from #8878) so the two paths can no longer drift.

Collision keeps its two intentional differences explicit: type is
initialized outside the property list, and shape is excluded because the
type implementation creates it during initialization.

No behavior changes - all four clone literals matched their lists 1:1.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Refactors several component systems so cloneComponent derives its clone data from the same module-level _properties list used by initializeComponentData, reducing drift risk and keeping clone/init behavior consistent across UI + collision components.

Changes:

  • Updated button, scroll-view, and scrollbar systems to build clone data by iterating _properties (plus enabled).
  • Updated collision system clone to iterate _properties while explicitly handling type and intentionally skipping shape.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
src/framework/components/button/system.js Builds clone payload from _properties to match initializer behavior and avoid list drift.
src/framework/components/scroll-view/system.js Builds clone payload from _properties while preserving the initializer’s property ordering assumptions.
src/framework/components/scrollbar/system.js Builds clone payload from _properties for consistency with initialization.
src/framework/components/collision/system.js Builds clone payload from _properties, explicitly includes type, and intentionally skips cloning shape.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@willeastcott willeastcott merged commit 9636bb3 into main Jun 11, 2026
10 checks passed
@willeastcott willeastcott deleted the refactor/clone-from-properties-ui branch June 11, 2026 19:21
willeastcott added a commit that referenced this pull request Jun 11, 2026
…body (#8880)

Continue the pattern from #8878/#8879: hoist the inline property list in
initializeComponentData to a module-level _properties array and drive
cloneComponent from the same list, so the two paths cannot drift.

Special-case handling is preserved:
- model: material/materialAsset are still resolved by the dedicated
  clone logic, mapping is still shallow-copied via extend
- sound: slots are still converted back to plain option objects
- rigid-body: linearFactor/angularFactor now pass the component Vec3s
  directly instead of converting to arrays; the component setters copy
  values, so the end state is identical with no aliasing

Also drops the unused legacy properties parameter from the
initializeComponentData overrides.

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement Request for a new feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants