Skip to content

Commit 9fc551e

Browse files
willeastcottclaude
andauthored
test(element): cover reparenting an element after its screen is destroyed (#8899)
Regression test for #1151: an element reparented to null, whose screen is then destroyed (e.g. on scene unload), can be reparented again without throwing 'this.screen.screen is undefined'. Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 6261a49 commit 9fc551e

1 file changed

Lines changed: 22 additions & 0 deletions

File tree

test/framework/components/element/component.test.mjs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,28 @@ describe('ElementComponent', function () {
157157
expect(screen.screen._elements).to.not.include(e.element);
158158
});
159159

160+
it('can be reparented after its screen has been destroyed (#1151)', function () {
161+
const screen = new Entity();
162+
screen.addComponent('screen');
163+
app.root.addChild(screen);
164+
165+
const e = new Entity();
166+
e.addComponent('element');
167+
screen.addChild(e);
168+
169+
// detach the element for later reuse, then destroy its screen (e.g. on scene unload)
170+
e.reparent(null);
171+
screen.destroy();
172+
173+
// the dangling screen reference should have been cleared
174+
expect(e.element.screen).to.equal(null);
175+
176+
// reparenting the element again should not throw
177+
const newParent = new Entity();
178+
app.root.addChild(newParent);
179+
expect(() => newParent.addChild(e)).to.not.throw();
180+
});
181+
160182
describe('#type', function () {
161183

162184
it('adds model to layers when type is set to image after entity is in hierarchy', function () {

0 commit comments

Comments
 (0)