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

fix: "onload" event order #8376

Merged
merged 8 commits into from
Nov 26, 2020
Merged

Conversation

benjamingr
Copy link
Contributor

Deno has a bug where it currently always attaches .onload before addEventListener see this for a web example.

The following code:

let arr: any = [];
window.addEventListener('load', () => {
  arr.push(1);
});
window.onload = () => arr.push(2);
window.addEventListener('load', () => {
  arr.push(3);
});

window.addEventListener('load', () => {
  setTimeout(() => {
    console.log(arr);
  })
})

Logs [ 2, 1, 3 ] in deno whereas browsers (and deno with this patch) log [ 1, 2, 3 ]

Note that this can be a relatively risky change compared to the AbortSignal/WebSocket/Worker timing fixes

cli/rt/99_main.js Outdated Show resolved Hide resolved
@bartlomieju bartlomieju added this to the 1.6.0 milestone Nov 23, 2020
Copy link
Member

@bartlomieju bartlomieju left a comment

Choose a reason for hiding this comment

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

LGTM, thanks @benjamingr

@benjamingr
Copy link
Contributor Author

Thanks, sorry I'm a bit sick (and on my phone and not computer) - note that de-duplication here means that we return undefined and not null for things like onload which probably needs a separate fix.

@bartlomieju
Copy link
Member

bartlomieju commented Nov 26, 2020

Thanks, sorry I'm a bit sick (and on my phone and not computer) - note that de-duplication here means that we return undefined and not null for things like onload which probably needs a separate fix.

@benjamingr thanks for pointing this out, should we hold on before merging then?

EDIT: I'm gonna revert my deduplication and leave a TODO comment to fix it in the future

@benjamingr
Copy link
Contributor Author

@benjamingr thanks for pointing this out, should we hold on before merging then?

I think merging is probably fine it's an improvement I will follow up with another fix

@bartlomieju bartlomieju changed the title fix(window) fix onload event order fix: "onload" event order Nov 26, 2020
@bartlomieju bartlomieju merged commit 4f46dc9 into denoland:master Nov 26, 2020
@benjamingr benjamingr deleted the onload-event-order branch December 7, 2020 16:05
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.

2 participants