Giter VIP home page Giter VIP logo

issue-20211215's Introduction

When the page require output bundles from multiple entries,only hmr of the entry which is latest be required work in webpack5.

introduction

first.js is the output bundle first be required in html. second.js is the output bundle latest be required in html.

npm run entries require two output bundles from single complier. npm run compliers require two output bundles form multiple compliers.

hmr of first.js doesn't work in webpack5. All work in webpack4.

behavior

In webpack5,after changed first.js and second.js,only second.js has been replaced.

Single complier and multiple compilers are both not work, although there are some difference when fetching xx.[hash].hot-update.json.

reason

In webpack4,each file has its own context of hmr server and own context of module hot repalce. I guess, in webpack5, context will be overwritten by next file.

For example,in webpack5:

var currentUpdatedModulesList;
var waitingUpdateResolves = {};
function loadUpdateChunk(chunkId) {
	return new Promise((resolve, reject) => {
		waitingUpdateResolves[chunkId] = resolve;
		var url = __webpack_require__.p + __webpack_require__.hu(chunkId);
		var error = new Error();
		var loadingEnded = (event) => {
      // ......
		};
		__webpack_require__.l(url, loadingEnded);
	});
}

self["webpackHotUpdatewebpack5"] = (chunkId, moreModules, runtime) => {
  // ......
	if(waitingUpdateResolves[chunkId]) {
		waitingUpdateResolves[chunkId]();
		waitingUpdateResolves[chunkId] = undefined;
	}
};

After files loaded,first.js and second.js are all declared waitingUpdateResolves,but waitingUpdateResolves in self["webpackHotUpdatewebpack5"] will be the one from file second.js .

solution

When two files are from same complier, using optimization.runtimeChunk can resolve this bug. This make code using same context. But When two files from two compliers, can't use this solution.

relevant

webpack/webpack#423

result

Setting output.uniqueName can generated different runtimes.

issue-20211215's People

Contributors

tobethelight avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.