-
Notifications
You must be signed in to change notification settings - Fork 48
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
🐛 Force @percy/dom globalization #237
Conversation
Sometimes modules or exports are polyfilled causing the UMD bundle to not attach the DOM script to the global scope. Since this scope issue seems to keep coming up, let's always set the serialize function globally when the window object is defined.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🏁
// `globalThis` is probably not defined | ||
// works around instances where the context has an incorrect scope | ||
if (typeof window !== 'undefined') { | ||
window.PercyDOM = exports; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test error was because the test bundles use the global PercyDOM
to reference this module, however setting this manually to a new object caused it to lose other module properties. Setting it to exports
will set it to be the same value as the module exports (including a default
property).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🏁
What is this?
Sometimes modules or exports are polyfilled causing the UMD bundle to not attach the DOM script to the global scope. Since this scope issue seems to keep coming up, let's always set the serialize function globally when the window object is defined.
I also updated the bundle intro to use
typeof
rather thantry-catch
.