Commit e33ab46
authored
update 3D scene when an <extra-model> is removed (#5187)
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`**:1 parent 8dfcf8a commit e33ab46
3 files changed
Lines changed: 71 additions & 21 deletions
File tree
- packages/model-viewer/src
- test/features
- three-components
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
212 | 212 | | |
213 | 213 | | |
214 | 214 | | |
215 | | - | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
216 | 224 | | |
217 | 225 | | |
218 | 226 | | |
| |||
230 | 238 | | |
231 | 239 | | |
232 | 240 | | |
| 241 | + | |
233 | 242 | | |
234 | 243 | | |
235 | 244 | | |
| |||
Lines changed: 60 additions & 20 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
57 | 57 | | |
58 | 58 | | |
59 | 59 | | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
60 | 99 | | |
61 | 100 | | |
62 | 101 | | |
| |||
102 | 141 | | |
103 | 142 | | |
104 | 143 | | |
105 | | - | |
106 | | - | |
107 | | - | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
108 | 148 | | |
109 | | - | |
110 | | - | |
111 | | - | |
112 | | - | |
113 | | - | |
114 | | - | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
115 | 155 | | |
116 | | - | |
| 156 | + | |
117 | 157 | | |
118 | | - | |
119 | | - | |
120 | | - | |
121 | | - | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
122 | 162 | | |
123 | | - | |
124 | | - | |
125 | | - | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
126 | 166 | | |
127 | | - | |
128 | | - | |
129 | | - | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
130 | 170 | | |
131 | 171 | | |
132 | 172 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
396 | 396 | | |
397 | 397 | | |
398 | 398 | | |
| 399 | + | |
399 | 400 | | |
400 | 401 | | |
401 | 402 | | |
| |||
0 commit comments