vuejs / vue-loader

📦 Webpack loader for Vue.js components
MIT License
4.99k stars 915 forks source link

Hash generated(for HMR) from relative path name is not unique in a microfrontend architecture #2050

Open svihpinc opened 1 year ago

svihpinc commented 1 year ago

The hash is generated in this line of code: https://github.com/vuejs/vue-loader/blob/8357e071c45e77de0889a9feedf2079a327f69d4/src/index.ts#L142.

This hash is generated using the relative path of the file being considered. But, in a microfrontend architecture, eg: when using single-spa. Different parcels and applications, if loaded at the same time may be built using different webpack configs, but use the same Vue instance. This is causing duplicate hashes being registered to the same Vue instance, since the relative path remains the same (eg: parcel1/src/App.vue, app1/src/App.vue, parcel2/src/App.vue` all will have the same HMR id)

This is causing issues like:

In the above scenario, createApp().mount was never called with parcel1's App.vue, and still it gets mounted

Possible solutions:

  1. use the absolute path of the file being considered, by just replacing path.relative with path.resolve, since generally the absolute paths of different microfrontends are different (are located in different folders)
  2. give users an option to give a suffix/prefix to the string that is used to create the hash