Skip to content
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

fix: use "api.isRecorded" instead of "module.hot.data" #1569

Merged
merged 1 commit into from Jul 17, 2019

Conversation

liximomo
Copy link
Member

@liximomo liximomo commented Jul 16, 2019

We should not use module.hot.data, which is highly unreliable. Plugins like lazy-compile-webpack-plugin use a dummy loader to prevent webpack from building async modules, the module will be compiled and hot-update on demand. In such a case, the module.hot.data is truthy but the record does not exist, which will cause a running error in api.reload. I think api.isRecorded is more reliable and reasonable.

lib/codegen/hotReload.js Show resolved Hide resolved
@yyx990803
Copy link
Member

Oh nvm... Haha I was looking at the diff without syntax highlighting

@liximomo
Copy link
Member Author

@yyx990803 yyx990803 merged commit 6a05115 into vuejs:master Jul 17, 2019
@yyx990803
Copy link
Member

/cc @sodatea let's test this patch in the CLI and publish a patch version.

@sodatea
Copy link
Member

sodatea commented Jul 18, 2019

Though I'm still struggling to understand why module.hot.data is unreliable (is it because there may be multiple sources of dispose call?), this commit seems to work great.

@liximomo
Copy link
Member Author

liximomo commented Jul 18, 2019

@sodatea Hope this pseudo code can provide some insight

compiler.hooks.compilation.tap('LazyCompilePlugin', compilation => {
  compilation.hooks.buildModule.tap('LazyCompilePlugin', wpModule => {
    if (ShouldBlock) {
      // relace the whole loaders
      wpModule.loaders = [
        {
          loader: dummy,
        },
      ];
    } else {
      // restore original loaders
      wpModule.loaders = originLoaders;
      // The same module will be hot-updated, and module.hot.data will be truthy.
      // Since vue-loader has't run before, there are no any records.
    }
  });
});

@sodatea
Copy link
Member

sodatea commented Jul 18, 2019

@liximomo Thanks! The new version is now available.

@liximomo
Copy link
Member Author

liximomo commented Jul 18, 2019

❤️ 🎉

lovetingyuan pushed a commit to lovetingyuan/vue-flags-webpack-plugin that referenced this pull request Jul 19, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants