Uh oh!
There was an error while loading. Please reload this page.
Use document.currentScript for deriving socket connection url - #1994
Use document.currentScript for deriving socket connection url#1994dburrows wants to merge 3 commits into
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
facebook-github-bot
commented
Apr 18, 2017
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. |
facebook-github-bot
commented
Apr 18, 2017
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks! |
dburrows
commented
Apr 18, 2017
Timer
commented
Apr 19, 2017
I'm not sure if I understand how this fixes the underlying issue, afaik the browser doesn't know a connection is being proxied. |
dburrows
commented
Apr 19, 2017
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 have look at https://github.com/webpack/webpack/blob/54aa3cd0d6167943713491fd5e1110b777336be6/lib/JsonpMainTemplate.runtime.js#L27 This was what was blocking me from opening a pr like this: Edit: It could also be possible to set |
dburrows
commented
Apr 21, 2017
@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 |
gaearon
commented
Jan 9, 2018
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.