Skip to content

Commit

Permalink
Fix DomPlatform.isAttached (#9448)
Browse files Browse the repository at this point in the history
  • Loading branch information
kurkle committed Jul 23, 2021
1 parent 3311377 commit 0d0481d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/platform/platform.dom.js
Expand Up @@ -382,6 +382,6 @@ export default class DomPlatform extends BasePlatform {
*/
isAttached(canvas) {
const container = _getParentNode(canvas);
return !!(container && _getParentNode(container));
return !!(container && container.isConnected);
}
}
9 changes: 7 additions & 2 deletions test/specs/platform.dom.tests.js
Expand Up @@ -408,17 +408,22 @@ describe('Platform.dom', function() {
var platform = new DomPlatform();
var canvas = document.createElement('canvas');
var div = document.createElement('div');
var anotherDiv = document.createElement('div');

expect(platform.isAttached(canvas)).toEqual(false);
div.appendChild(canvas);
expect(platform.isAttached(canvas)).toEqual(false);
document.body.appendChild(div);
anotherDiv.appendChild(div);
expect(platform.isAttached(canvas)).toEqual(false);
document.body.appendChild(anotherDiv);

expect(platform.isAttached(canvas)).toEqual(true);

anotherDiv.removeChild(div);
expect(platform.isAttached(canvas)).toEqual(false);
div.removeChild(canvas);
expect(platform.isAttached(canvas)).toEqual(false);
document.body.removeChild(div);
document.body.removeChild(anotherDiv);
expect(platform.isAttached(canvas)).toEqual(false);
});
});
Expand Down

0 comments on commit 0d0481d

Please sign in to comment.