Skip to content

Commit aede3b6

Browse files
committed
check that document exists before mounting debug panel
1 parent d84e6af commit aede3b6

2 files changed

Lines changed: 18 additions & 8 deletions

File tree

src/client/client.js

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -279,16 +279,19 @@ class _ClientImpl {
279279
this.debug !== false &&
280280
this._debugPanel == null
281281
) {
282-
let target = document.body;
283-
if (this.debug && this.debug.target) {
282+
let target = document && document.body;
283+
if (this.debug && this.debug.target !== undefined) {
284284
target = this.debug.target;
285285
}
286-
this._debugPanel = new debugImpl({
287-
target,
288-
props: {
289-
client: this,
290-
},
291-
});
286+
287+
if (target) {
288+
this._debugPanel = new debugImpl({
289+
target,
290+
props: {
291+
client: this,
292+
},
293+
});
294+
}
292295
}
293296
}
294297

src/client/client.test.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -642,6 +642,13 @@ describe('start / stop', () => {
642642
client.stop();
643643
});
644644

645+
test('no error when mounting on null element', () => {
646+
const client = Client({ game: {}, debug: { target: null } });
647+
client.start();
648+
client.stop();
649+
expect(client._debugPanel).toBe(null);
650+
});
651+
645652
test('override debug implementation', () => {
646653
const client = Client({ game: {}, debug: { impl: Debug } });
647654
client.start();

0 commit comments

Comments
 (0)