wilsonpage/fastdom

`this` is undefined in global scope

hedinne opened this issue ยท 2 comments

Hi! ๐Ÿ‘‹

Firstly, thanks for your work on this project! ๐Ÿ™‚

I've been using a package called ui-observer for years, which depends on fastdom. I am now using it with the new "App router" in NextJS, which runs fastdom on the server. This should be fine, but for some reason, this is undefined in global scope, but globalThis works.

Can we fix this error? I can submit a pull request if that helps. Here is the diff that solved the problem.

fastdom@1.0.11

diff --git a/node_modules/fastdom/fastdom.js b/node_modules/fastdom/fastdom.js
index 70bf7d7..a0d5833 100644
--- a/node_modules/fastdom/fastdom.js
+++ b/node_modules/fastdom/fastdom.js
@@ -241,4 +241,4 @@ var exports = win.fastdom = (win.fastdom || new FastDom()); // jshint ignore:lin
 if ((typeof define) == 'function') define(function() { return exports; });
 else if ((typeof module) == 'object') module.exports = exports;
 
-})( typeof window !== 'undefined' ? window : this);
+})( typeof window !== 'undefined' ? window : typeof this !== 'undefined' ? this : globalThis);

Sinceerly, Hedinn

Fixed by #132

Thank you ๐Ÿ™