Skip to content

Commit 4c4e5cc

Browse files
author
Guillaume Chau
committed
fix(hmr): double reload requests from meteor shouldn't reload if it was suppressed by HMR
1 parent 3ce7e4d commit 4c4e5cc

File tree

1 file changed

+20
-14
lines changed

1 file changed

+20
-14
lines changed

packages/vue-component-dev-client/client/dev-client.js

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,10 @@ if (window.__vue_hot_pending__) {
4242
}
4343

4444
// Reload override
45-
var _suppressNextReload = false
45+
let _suppressNextReload = false
46+
let _suppressTimer
4647
let _deferReload = 0
47-
var _reload = Reload._reload
48+
const _reload = Reload._reload
4849
Reload._reload = function (options) {
4950
// Disable original reload for autoupdate package
5051
if (Reload._reload.caller.name !== '' && Reload._reload.caller.name !== 'checkNewVersionDocument') {
@@ -54,17 +55,22 @@ Reload._reload = function (options) {
5455

5556
// Custom reload method
5657
function reload (options) {
57-
console.log('%cHMR', tagStyle, 'Reload request received')
5858
if (_deferReload !== 0) {
5959
setTimeout(_reload, _deferReload)
6060
console.log(`%cHMR`, tagStyle, `Client reload defered, will reload in ${_deferReload} ms`)
6161
} else if (_suppressNextReload) {
62-
console.log(`%cHMR%c ⥁ Client version changed, reload suppressed because of a recent HMR update. You may need to reload the page.`, tagStyle, 'color: #F36E00;')
62+
if (!_suppressTimer) {
63+
console.log(`%cHMR%c ⥁ Client version changed, reload suppressed because of a recent HMR update. You may need to reload the page.`, tagStyle, 'color: #F36E00;')
64+
}
65+
clearTimeout(_suppressTimer)
66+
_suppressTimer = setTimeout(() => {
67+
_suppressNextReload = false
68+
_suppressTimer = undefined
69+
})
6370
} else {
6471
console.log(`%cHMR`, tagStyle, `Reloading app...`)
6572
_reload.call(Reload, options)
6673
}
67-
_suppressNextReload = false
6874
_deferReload = 0
6975
}
7076

@@ -77,7 +83,7 @@ function checkNewVersionDocument (doc) {
7783
}
7884
}
7985

80-
var ClientVersions = Autoupdate._ClientVersions
86+
const ClientVersions = Autoupdate._ClientVersions
8187
if (ClientVersions) {
8288
ClientVersions.find().observe({
8389
added: checkNewVersionDocument,
@@ -89,14 +95,14 @@ if (ClientVersions) {
8995

9096
Meteor.startup(function () {
9197
// Dev client
92-
let devUrl = __meteor_runtime_config__.VUE_DEV_SERVER_URL
98+
const devUrl = __meteor_runtime_config__.VUE_DEV_SERVER_URL
9399

94100
console.log('%cHMR%c Dev server URL: %c' + devUrl, tagStyle, '', 'font-weight: bold;')
95101

96-
console.log(`%cIf you have issues connecting to the dev server, set the 'HMR_URL' env variable to the URL of the dev server displayed in the meteor console.`, infoStyle)
102+
console.log(`%cIf you have issues connecting to the dev server, set the 'HMR_URL' env letiable to the URL of the dev server displayed in the meteor console.`, infoStyle)
97103

98104
// NOTE: Socket lib don't allow mix HTTP and HTTPS servers URLs on client!
99-
let _socket = require('socket.io-client')(devUrl)
105+
const _socket = require('socket.io-client')(devUrl)
100106
window.__dev_client__ = _socket
101107

102108
_socket.on('connect', function () {
@@ -124,7 +130,7 @@ Meteor.startup(function () {
124130
}
125131
})
126132

127-
let id = `${path + Math.round(new Date().getTime())}.js`
133+
const id = `${path + Math.round(new Date().getTime())}.js`
128134
const files = id.split('/')
129135
const fileObj = {}
130136
let currentObj = fileObj
@@ -137,8 +143,8 @@ Meteor.startup(function () {
137143
}
138144
})
139145

140-
let require = meteorInstall(fileObj)
141-
let result = require('./' + id)
146+
const require = meteorInstall(fileObj)
147+
const result = require('./' + id)
142148

143149
let needsReload = false
144150
if (!error) {
@@ -169,7 +175,7 @@ Meteor.startup(function () {
169175
console.log('%cHMR', tagStyle, 'Rerendering ' + path)
170176
let error = false
171177
try {
172-
var obj
178+
let obj
173179
// eslint-disable-next-line no-eval
174180
eval(`obj = ${template};`)
175181
// console.log(obj)
@@ -182,7 +188,7 @@ Meteor.startup(function () {
182188
})
183189

184190
// CSS
185-
let _styleNodes = {}
191+
const _styleNodes = {}
186192
_socket.on('css', function ({hash, css, path}) {
187193
// console.log('css', hash, css.length)
188194
let style = _styleNodes[hash]

0 commit comments

Comments
 (0)