Skip to content

Commit

Permalink
fix: error when importing split-type in next js (#46)
Browse files Browse the repository at this point in the history
Fixes error when importing SplitType isomorphic applications such as NextJS.
The error was caused by a reference to Element which is not defined in node.
  • Loading branch information
lukePeavey authored Jul 20, 2022
1 parent b408340 commit 70721f4
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 16 deletions.
2 changes: 0 additions & 2 deletions lib/SplitType.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,5 +205,3 @@ export default class SplitType {
SplitType.revert(this.elements)
}
}

window.SplitType = SplitType
29 changes: 15 additions & 14 deletions lib/utils/polyfill.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Polyfill for the following DOM methods which are not supported in IE 11
// We will be dropping support for IE in an upcoming version
// Polyfill the following DOM methods that are not supported in IE 11.
// This can be removed in the near future since we no longer support IE.
// - Element.append
// - Element.replaceWith
// - Element.replaceChildren
Expand Down Expand Up @@ -39,17 +39,18 @@
}
}
}

if (!Element.prototype.append) {
Element.prototype.append = append
DocumentFragment.prototype.append = append
}
if (!Element.prototype.replaceChildren) {
Element.prototype.replaceChildren = replaceChildren
DocumentFragment.prototype.replaceChildren = replaceChildren
}
if (!Element.prototype.replaceWith) {
Element.prototype.replaceWith = replaceWith
DocumentFragment.prototype.replaceWith = replaceWith
if (typeof Element !== 'undefined') {
if (!Element.prototype.append) {
Element.prototype.append = append
DocumentFragment.prototype.append = append
}
if (!Element.prototype.replaceChildren) {
Element.prototype.replaceChildren = replaceChildren
DocumentFragment.prototype.replaceChildren = replaceChildren
}
if (!Element.prototype.replaceWith) {
Element.prototype.replaceWith = replaceWith
DocumentFragment.prototype.replaceWith = replaceWith
}
}
})()

0 comments on commit 70721f4

Please sign in to comment.