Fix DomPlatform.isAttached (#9448)

This commit is contained in:
Jukka Kurkela
2021-07-23 08:28:09 +03:00
committed by GitHub
parent 3311377682
commit 0d0481d64c
2 changed files with 8 additions and 3 deletions

View File

@@ -382,6 +382,6 @@ export default class DomPlatform extends BasePlatform {
*/
isAttached(canvas) {
const container = _getParentNode(canvas);
return !!(container && _getParentNode(container));
return !!(container && container.isConnected);
}
}

View File

@@ -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);
});
});