Merge pull request #7227 from tchak/fix-add-children-polyfill
fix(js): add DocumentFragment.children polyfill for IE
This commit is contained in:
commit
81fb1793e6
2 changed files with 21 additions and 29 deletions
|
@ -16,7 +16,27 @@ import 'yet-another-abortcontroller-polyfill';
|
||||||
import './polyfills/insertAdjacentElement';
|
import './polyfills/insertAdjacentElement';
|
||||||
import './polyfills/dataset';
|
import './polyfills/dataset';
|
||||||
|
|
||||||
// IE 11 has no baseURI
|
// IE 11 has no baseURI (required by turbo)
|
||||||
if (document.baseURI == undefined) {
|
if (document.baseURI == undefined) {
|
||||||
document.baseURI = document.URL;
|
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);
|
||||||
|
}
|
||||||
|
|
|
@ -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";
|
|
Loading…
Reference in a new issue