Skip to content

update 3D scene when an <extra-model> is removed#5187

Merged
diegoteran merged 1 commit into
masterfrom
mult
Jun 30, 2026
Merged

update 3D scene when an <extra-model> is removed#5187
diegoteran merged 1 commit into
masterfrom
mult

Conversation

@diegoteran

Copy link
Copy Markdown
Collaborator

Fixes #5186.

Summary & Root Cause

When an <extra-model> child element was removed from <model-viewer> (e.g. via element.remove()), the DOM child change triggered a slotchange event, which invoked this[$updateSource](). However, because the primary model had already finished loading, this.loaded remained true. Inside [$updateSource](), an early return check (if (this.loaded || ...)) caused the update to bail out before invoking scene.setSource(). As a result, the removed <extra-model>'s 3D mesh was orphaned and remained rendered inside the Three.js scene graph. ### Changes Made

  • model-viewer-base.ts:
    • Updated [$onSlotChange] to reset this[$loaded] = false; and this[$loadedTime] = 0; whenever the list of <extra-model> URLs or element count changes. This allows [$updateSource]() to proceed past the load guard and properly synchronize the Three.js scene graph with the DOM.
    • Added explicit handling for the edge case where all primary and extra models are removed (this.src == null && extraModels.length === 0), directly invoking this[$scene].reset() and clearing loaded state.
  • ModelScene.ts:
    • Updated reset() to ensure this.extraUrls = []; is properly cleared during scene resets.
  • extra-model-spec.ts:

Reference Issue

Fixes #5186.
### Summary & Root Cause
When an `<extra-model>` child element was removed from `<model-viewer>` (e.g. via `element.remove()`), the DOM child change triggered a `slotchange` event, which invoked `this[$updateSource]()`. However, because the primary model had already finished loading, `this.loaded` remained `true`. Inside `[$updateSource]()`, an early return check (`if (this.loaded || ...)`) caused the update to bail out before invoking `scene.setSource()`. As a result, the removed `<extra-model>`'s 3D mesh was orphaned and remained rendered inside the Three.js scene graph.
### Changes Made
* **`model-viewer-base.ts`**:
  * Updated `[$onSlotChange]` to reset `this[$loaded] = false;` and `this[$loadedTime] = 0;` whenever the list of `<extra-model>` URLs or element count changes. This allows `[$updateSource]()` to proceed past the load guard and properly synchronize the Three.js scene graph with the DOM.
  * Added explicit handling for the edge case where all primary and extra models are removed (`this.src == null && extraModels.length === 0`), directly invoking `this[$scene].reset()` and clearing loaded state.
* **`ModelScene.ts`**:
  * Updated `reset()` to ensure `this.extraUrls = [];` is properly cleared during scene resets.
* **`extra-model-spec.ts`**:
@diegoteran diegoteran merged commit e33ab46 into master Jun 30, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Removing an <extra-model> does not update the scene (deleted model stays rendered)

1 participant