-
-
Notifications
You must be signed in to change notification settings - Fork 26.9k
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
Use document.currentScript for deriving socket connection url #1994
Conversation
…tion url When loading a create-react-app bundle from another domain everything works ok except the auto-page reload. The socket connection fails because webpackHotDevClient uses window.location to derive the socket connection url. This commit uses document.currentScript (if available) to derive the SockJS connection url details.
…g a getLocation local function
Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. In order for us to review and merge your code, please sign up at https://code.facebook.com/cla - and if you have received this in error or have any questions, please drop us a line at cla@fb.com. Thanks! If you are contributing on behalf of someone else (eg your employer): the individual CLA is not sufficient - use https://developers.facebook.com/opensource/cla?type=company instead. Contact cla@fb.com if you have any questions. |
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks! |
I'm not sure if I understand how this fixes the underlying issue, afaik the browser doesn't know a connection is being proxied. |
The browser doesn't need to know, it just needs to make a socket connection to the same domain that the bundle is loaded from, probably easier with an example: Say create-react-app is running on We then have a dev server running on Current behaviour: webpackHotDevClient uses the New behaviour: webpackHotDevClient uses |
@dburrows I don't think this works fully unless your This was what was blocking me from opening a pr like this: Edit: It could also be possible to set |
@sktt ok, I guess a reload is better than nothing though? |
It is better with nothing than a half implemented feature edit: sorry about that. I mean, it would be really nice to have it fully working.. This wouldnt though break anything so ... you might actually be right |
I don't think we'll merge a half-working solution because it will be harder for people to figure out why it doesn't work. Whereas in the current case it's pretty clear we just don't support this use case. Thanks for PR though! |
When loading a create-react-app bundle from another domain everything works ok except the auto-page reload. The socket connection fails because webpackHotDevClient uses window.location to derive the socket connection url. This commit uses document.currentScript (if available) to derive the SockJS connection url details.
There's a load of ways to find the current executing script in browsers that don't support document.currentScript but they all seemed a bit fragile, so I've made a pragmatic decision to just use currentScript - main downside is that this won't work in IE but that's ok for a dev tool I think. Full support details outlined here: http://caniuse.com/#feat=document-currentscript
I've tested this by loading a normally created app and then loading the same app bundle from another domain, both worked.
P.S. Feel free to close this if you don't think it's a good idea, I'd implemented it anyway and it's quicker to open a PR with it than explain what I wanted to do ahead of time.