]> git.ipfire.org Git - thirdparty/Chart.js.git/commitdiff
Fix DomPlatform.isAttached (#9448)
authorJukka Kurkela <jukka.kurkela@gmail.com>
Fri, 23 Jul 2021 05:28:09 +0000 (08:28 +0300)
committerGitHub <noreply@github.com>
Fri, 23 Jul 2021 05:28:09 +0000 (08:28 +0300)
src/platform/platform.dom.js
test/specs/platform.dom.tests.js

index 7cbe719f27d01c56e4b890e8fc0c80175438c12b..8e7858f750a561c2085cbd4259f860590c47c0c4 100644 (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);
   }
 }
index 7e6ab03e54f52411c811ea7fab328563ca4f2316..b3b05a5cacf4f32f26c1d60cbf6251826e57ef4d 100644 (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);
     });
   });