hot-module-replacement icon indicating copy to clipboard operation
hot-module-replacement copied to clipboard

Differentiate Save vs. Change?

Open ericclemmons opened this issue 7 years ago • 0 comments

I just introduced this to a (personal) project and was trying to figure out how to tell if the module has actually changed:

https://github.com/sidorares/hot-module-replacement/blob/834782b4ee000435c392beb46f34932b0c8c6012/index.js#L70

Traditionally, webpack generates a hash for the file contents so that, even if HMR fires on the client, there's a way to tell (via the websocket payload) what the current hash is.

(By comparing the previous hash vs. the current hash for a module, you can determine if there have been any changes, or if the user simple saved twice)

Now, why is this important?

Sometimes HMR can get into a bad state, in which case I've been using double-save to reload the server/client/browser.

Unfortunately, I can't tell what file prompted to HMR, since this line is called with path instead of filename:

https://github.com/sidorares/hot-module-replacement/blob/834782b4ee000435c392beb46f34932b0c8c6012/index.js#L97


What would you recommend I do to differentiate changes vs. saved?

My first thought was to change the call to:

 // Send the accepted path & the file that triggered the change
 parent.hot._acceptedDependencies[path](path, filename);

ericclemmons avatar Dec 31 '18 06:12 ericclemmons