webpack-hot-middleware icon indicating copy to clipboard operation
webpack-hot-middleware copied to clipboard

Url changes

Open SergeyMiracle opened this issue 8 years ago • 12 comments

Init: var hotClient = require('webpack-hot-middleware/client?noInfo=true&reload=true&dynamicPublicPath=true&path=__webpack_hmr')

Version 2.18.0 result url - http://localhost:8085/__webpack_hmr Version 2.18.1 result url - http://server.dev/localhost:8085/__webpack_hmr As u see now opened domain added to HMR path

How to make it work?

SergeyMiracle avatar Jul 06 '17 05:07 SergeyMiracle

Try having the path setting start with /

glenjamin avatar Jul 06 '17 06:07 glenjamin

@glenjamin still get http://server.dev/localhost:8085/__webpack_hmr Even tryed path=http://localhost:8085/__webpack_hmr and got http://server.dev/localhost:8085/http:/localhost:8085/__webpack_hmr

SergeyMiracle avatar Jul 06 '17 06:07 SergeyMiracle

Could you add manually add some console logs or use the debugger to tell me what the dynamic public path are the calculated path are at runtime?

The relevant lines are in the config parsing section of the client code

glenjamin avatar Jul 06 '17 07:07 glenjamin

@glenjamin not really understand where to put log. Code looks like this

require('eventsource-polyfill')
var hotClient = require('webpack-hot-middleware/client?noInfo=true&reload=true&dynamicPublicPath=true&path=__webpack_hmr')

hotClient.subscribe(function (event) {
  if (event.action === 'reload') {
    window.location.reload()
  }
})

SergeyMiracle avatar Jul 06 '17 08:07 SergeyMiracle

You'd need to edit client.js inside node_modules, or put a breakpoint there

glenjamin avatar Jul 06 '17 08:07 glenjamin

Ok so in init() section i do

function init() {
    console.log(options.path)
    source = new window.EventSource(options.path);
    console.log(source)
    source.onopen = handleOnline;
    source.onerror = handleDisconnect;
    source.onmessage = handleMessage;
  }

1st log - http:/localhost:8085/__webpack_hmr 2nd log - http://prntscr.com/fsa9sa

SergeyMiracle avatar Jul 06 '17 09:07 SergeyMiracle

With 2.18.0 i get http://prntscr.com/fsadkw

SergeyMiracle avatar Jul 06 '17 09:07 SergeyMiracle

I think i see what's going on - what does __webpack_public_path__ log out as?

I think the problem is that the patch in 2.18.1 uses path.join but it should use something like url.resolve.

I'm going to deprecate 2.18.1 and re-release 2.18.0 as 2.18.2 based on this report.

Sorry for the problems this has caused you, thanks for helping me debug!

glenjamin avatar Jul 06 '17 09:07 glenjamin

cc @pd4d10 - FYI i'm going to revert your fix for the moment.

Will try and bring it back soonish including a testcase that has __webpack_public_path__ be an absolute URL including protocol.

glenjamin avatar Jul 06 '17 09:07 glenjamin

log of __webpack_public_path__ shows http://localhost:8085/

SergeyMiracle avatar Jul 06 '17 09:07 SergeyMiracle

Hey @glenjamin,

I'm very likely wrong about this 😛 but it seems to me like I need that path.join you had added here.

I've done a bit of debugging over here in relation to this issue as well, thinking that it was webpack core. I still think it's weird that __webpack_public_path__ strips its trailing slash somewhere along the way, but everything on that end works until I combine it with HMR via this library and the dev-middleware.

As per my last comment on that issue on webpack, this library ended up sending requests to https://localhost:3000//__webpack_hmr in my attempts to ensure a slash at the end of the https://localhost:3000/ path. So I actually went into node_modules and removed the prefixing / in client.js and now it works.

I can achieve the same using the path override on the entry string. Mine is running via a custom CLI and so it looks like this:

entry: [
  path.join(__dirname, '../node_modules/webpack-hot-middleware/client?dynamicPublicPath=true&path=__webpack_hmr'),
  ...
]

This appears to work fine so I'm happy with it for now, but wanted to bring it to your attention in case it helps!

estrattonbailey avatar Sep 19 '17 18:09 estrattonbailey

Public path is a URL Path, so it'd have to be URL.resolve or equivalent.

If someone adds a PR which includes a few testcases and a fix I'll gladly take it

glenjamin avatar Sep 19 '17 20:09 glenjamin