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.onmessage with window.addEventListener #513

Merged
merged 2 commits into from
Oct 12, 2014

Conversation

nickdima
Copy link
Contributor

@nickdima nickdima commented Oct 7, 2014

When having multiple bundles that use hot module replacement loaded in the page, window.onmessage got overwritten by the last loaded bundle, making it the only one receiving the message. Changed it with window.addEventListener so it gets handled by all the bundles. See discussion here: webpack-contrib/extract-text-webpack-plugin#30

@jhnns
Copy link
Member

jhnns commented Oct 8, 2014

👍

@sokra
Copy link
Member

sokra commented Oct 9, 2014

https://developer.mozilla.org/en-US/docs/Web/API/EventTarget.addEventListener

In Internet Explorer versions prior to IE 9, you have to use attachEvent rather than the standard addEventListener.

Could you add this?

@nickdima
Copy link
Contributor Author

nickdima commented Oct 9, 2014

I'll look into this. Even if I don't see anyone developing on IE8 or planing to use HMR in production for IE8. :)

@sokra
Copy link
Member

sokra commented Oct 9, 2014

It's easy to support, and may be used for hot-testing in different browsers.

@nickdima
Copy link
Contributor Author

nickdima commented Oct 9, 2014

Hot-testing in different browsers sounds like a good case. OK, I'll get down to it.

@akre54
Copy link
Contributor

akre54 commented Oct 9, 2014

It just has to look like this: https://github.com/jashkenas/backbone/blob/4927b6e3f013821a5c94a9e8f6e3d5c3acdeaca8/backbone.js#L1474-L1477

var addEventListener = window.addEventListener || function (eventName, listener) {
  return attachEvent('on' + eventName, listener);
};

addEventListener('message', fn);

@nickdima
Copy link
Contributor Author

nickdima commented Oct 9, 2014

Done, thanks @akre54

@sokra sokra merged commit 513f551 into webpack:master Oct 12, 2014
@nickdima nickdima deleted the HMR/addEventListener branch October 12, 2014 15:09
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.

None yet

4 participants