Incorrect HMR behavior with webpack 5 and enabled source maps
See original GitHub issueVersion
16.1.2
Reproduction link
https://github.com/yura3d/vue3-webpack5
Steps to reproduce
- Clone GitHub repo.
- Run
yarn
andyarn dev
. - Browse
localhost:8080
, type some symbols to input field and/or press counter button to change component’s state. - Open
src/App.vue
and change something in<template>
section.
What is expected?
HMR applies, input field and counter still contain their values as state shouldn’t be changed according to docs: https://vue-loader.vuejs.org/guide/hot-reload.html#state-preservation-rules
What is actually happening?
HMR applies.
State is lost when bundling with webpack 5 if devtool
is set to something with source maps (source-map
, eval-source-map
, etc).
State is preserved when devtool
doesn’t set source maps (false
, eval
), or when bundling with webpack 4 (even with source maps) and almost the same webpack.config.js
.
I see this console output on HMR with webpack 5 and source maps:
log.js:24 [HMR] Updated modules:
log.js:16 [HMR] - ./src/App.vue?vue&type=script&lang=js
log.js:24 [HMR] - ./src/App.vue?vue&type=script&lang=js
log.js:24 [HMR] - ./src/App.vue
log.js:16 [HMR] - ./src/App.vue?vue&type=template&id=7ba5bd90&scoped=true
log.js:24 [HMR] - ./src/App.vue?vue&type=template&id=7ba5bd90&scoped=true
log.js:16 [HMR] - ./src/App.vue?vue&type=style&index=0&id=7ba5bd90&lang=scss&scoped=true
log.js:24 [HMR] App is up to date.
hotModuleReplacement.js:215 [HMR] Reload all css
And this on HMR without source maps:
log.js:24 [HMR] Updated modules:
log.js:16 [HMR] - ./src/App.vue?vue&type=template&id=7ba5bd90&scoped=true
log.js:24 [HMR] - ./src/App.vue?vue&type=template&id=7ba5bd90&scoped=true
log.js:16 [HMR] - ./src/App.vue?vue&type=style&index=0&id=7ba5bd90&lang=scss&scoped=true
log.js:24 [HMR] App is up to date.
hotModuleReplacement.js:215 [HMR] Reload all css
It seems component’s JS recompiles even when there are no changes in <script>
section if source maps are enabled.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:9
- Comments:13
Top Results From Across the Web
Development - webpack
In order to make it easier to track down errors and warnings, JavaScript offers source maps, which map your compiled code back to...
Read more >How I solved and debugged my Webpack issue through trial ...
I made a mistake in src/Hello.js on purpose to see how source maps worked this time. import React from 'react';import PropTypes from 'prop-types ......
Read more >Webpack hot module replacement (HMR) sourcemaps not ...
There is an issue with HMR and updating the source maps in the DevTools. Typically, the source maps are cached by the browsers...
Read more >@non25/svelte-loader - npm
enable sourcemaps in devmode devtool: prod ? false : 'source-map', ... plugins: [ // make separate css bundle new MiniCssExtractPlugin({ ...
Read more >Source Maps - SurviveJS
Source maps solve this problem by providing a mapping between the original and ... Beyond webpack, you also have to enable support for...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
The bug is still reproducible in 17.0.0, even on fresh setup using the newest
@vue/cli
5any solution to this? I’m having the same issue. Hot reload only works with devTool=false.
using this combination: