-
Notifications
You must be signed in to change notification settings - Fork 124
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
fix: Tolerate multiple imports/loads of the script #245
base: main
Are you sure you want to change the base?
Conversation
It may come up that multiple scripts import or load the polyfill into the same document. In such cases we want to ensure the polyfill only runs once.
} | ||
|
||
if (typeof document !== 'undefined') { |
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.
I'm assuming these conditional blocks can be safely joined, for simplicity+brevity
@@ -276,7 +276,7 @@ function applyFocusVisiblePolyfill(scope) { | |||
// It is important to wrap all references to global window and document in | |||
// these checks to support server-side rendering use cases | |||
// @see https://github.com/WICG/focus-visible/issues/199 | |||
if (typeof window !== 'undefined' && typeof document !== 'undefined') { | |||
if (typeof window !== 'undefined' && typeof document !== 'undefined' && !window.applyFocusVisiblePolyfill) { |
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.
Just checking for applyFocusVisiblePolyfill
is sufficiently safe as the function is always run right after it's assignment into the global Window scope
@maranomynet - can you join the WICG to appease the IPR bots? |
I've ventured down that rabbit hole of bad onboarding UX, and emerged mostly unscathed.
|
Any chance of seeing this merged? |
I can't believe it's been three years already. Time flies. |
It may come up that multiple scripts import or load the polyfill into the same document.
In such cases we want to ensure the polyfill only runs once.