webpack/webpack — pull request #468 by markmarijnissen (2014-09-14 00:10:34+00:00)
Title: HMR dispose bugfix: Don't dispose the cached version of a module if the module hasn't changed.

Use case: I want to hot-module-reload templates.

1. Setup a `require.context` to load template files (i.e. `./*.jade`).
2. Do a `module.accept` for the context module id, and just re-render the template in your view.

Example:

* I have a router that renders templates: Module 1.
* The router requires all *.jade files. The Require Context is Module 2.
* The template itself is Module 3.

1. When you change the template, HMR receives an update for module 3. It doesn't self-accept so it asks the parent.
2. Module 2 can't accept (it's an auto generated require context), so it asks the parent.
3. Module 1 accepts and re-renders the template view.

Before applying the update, HMR disposes all 'invalidated' or 'outdated' modules, which are Module 2 and 3. When disposing, it removes the module from the cache variable `installedModules`.

However, Module 2 hasn't changed, won't be updated, and the cached version is still valid!

When applying a second template update, the HMR code will throw an error when getting "affected stuff": `parent.hot._declinedDependencies[moduleId]` --> parent is undefined and has no method hot. Of course parent is undefined: It couldn't be retrieved from the `installedModules` anymore!

This pull request checks if the module is in the update before deleting it from the `installedModules` cache.