Merge pull request #7227 from tchak/fix-add-children-polyfill

fix(js): add DocumentFragment.children polyfill for IE
This commit is contained in:
Paul Chavard 2022-05-03 12:43:54 +02:00 committed by GitHub
commit 81fb1793e6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 29 deletions

View file

@ -16,7 +16,27 @@ import 'yet-another-abortcontroller-polyfill';
import './polyfills/insertAdjacentElement';
import './polyfills/dataset';
// IE 11 has no baseURI
// IE 11 has no baseURI (required by turbo)
if (document.baseURI == undefined) {
document.baseURI = document.URL;
}
// IE 11 has no children on DocumentFragment (required by turbo)
function polyfillChildren(proto) {
Object.defineProperty(proto, 'children', {
get: function () {
const children = [];
for (const node of this.childNodes) {
if (node.nodeType == 1) {
children.push(node);
}
}
return children;
}
});
}
const fragment = document.createDocumentFragment();
if (fragment.children == undefined) {
polyfillChildren(DocumentFragment.prototype);
}

View file

@ -1,28 +0,0 @@
diff --git a/node_modules/@hotwired/turbo/dist/turbo.es2017-esm.js b/node_modules/@hotwired/turbo/dist/turbo.es2017-esm.js
index 963422f..7820263 100644
--- a/node_modules/@hotwired/turbo/dist/turbo.es2017-esm.js
+++ b/node_modules/@hotwired/turbo/dist/turbo.es2017-esm.js
@@ -551,7 +551,8 @@ class StreamMessage {
}, []);
}
get templateChildren() {
- return Array.from(this.templateElement.content.children);
+ const content = this.templateElement.content;
+ return content.children ? Array.from(content.children) : Array.from(content.childNodes).filter((tag) => tag.tagName);
}
}
StreamMessage.contentType = "text/vnd.turbo-stream.html";
diff --git a/node_modules/@hotwired/turbo/dist/turbo.es2017-umd.js b/node_modules/@hotwired/turbo/dist/turbo.es2017-umd.js
index 101db1f..a63cfbe 100644
--- a/node_modules/@hotwired/turbo/dist/turbo.es2017-umd.js
+++ b/node_modules/@hotwired/turbo/dist/turbo.es2017-umd.js
@@ -557,7 +557,8 @@ Copyright © 2021 Basecamp, LLC
}, []);
}
get templateChildren() {
- return Array.from(this.templateElement.content.children);
+ const content = this.templateElement.content;
+ return content.children ? Array.from(content.children) : Array.from(content.childNodes).filter((tag) => tag.tagName);
}
}
StreamMessage.contentType = "text/vnd.turbo-stream.html";