Skip to content
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

replace window.onload with window.addEventListener #2379

Merged
merged 1 commit into from
Apr 11, 2023
Merged

Conversation

robin-drexler
Copy link
Member

@robin-drexler robin-drexler commented Mar 10, 2023

PR Summary:

window.onload only allows a single callback to be attached.
As soon as a second callback is added, the previous one is removed.

Some third party scripts contain window.onload handlers which breaks the address forms on customer account pages. The edit form can't be toggled for example.

What approach did you take?

Replaces window.onload with window.addEventListener("load") which supports multiple event listeners.

Demo onload vs addEventListener: https://jsfiddle.net/0ydwoen7/2/
onload 1 is never logged because it's been overridden by the second callback.
addEventListener 2 is shown, however.

addEventListener isn't supported in IE<=8, but I think those are outside of the supported browser matrix and it's already been widely used throughout the code base https://github.com/search?q=repo%3AShopify%2Fdawn%20addEventListener&type=code

Visual impact on existing themes

none

Testing steps/scenarios

  • Step 1

Demo links

Checklist

@robin-drexler robin-drexler marked this pull request as ready for review March 10, 2023 16:55
Copy link
Contributor

@ludoboludo ludoboludo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for noticing and creating the fix for it 👍

@ludoboludo ludoboludo merged commit 5fda144 into main Apr 11, 2023
@ludoboludo ludoboludo deleted the fix-onload branch April 11, 2023 15:40
phapsidesGT pushed a commit to Gravytrain-UK/gt-shopify-dawn-theme that referenced this pull request Sep 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants