Skip to content

Commit e5c22b3

Browse files
chris-visserAkryum
authored andcommitted
fix: hmr and reload when needed (#342)
* Fix file watcher to fix HMR * Reload the client when HMR is not possible
1 parent 0c9a221 commit e5c22b3

File tree

2 files changed

+11
-16
lines changed

2 files changed

+11
-16
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,7 @@ exports.reload = tryWrap((id, options) => {
220220
console.warn(
221221
'Root or manually mounted instance modified. Full reload required.'
222222
)
223+
window.location.reload()
223224
}
224225
})
225226
})

packages/vue-component/plugin/vue-compiler.js

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -331,22 +331,16 @@ class ComponentWatcher {
331331
}
332332

333333
_watchPath (filePath) {
334-
if (!this.watcher || filePath !== this.filePath) {
335-
this.filePath = filePath
336-
// Fast file change detection
337-
this._closeWatcher()
338-
this.watcher = fs.watch(filePath, {
339-
persistent: false,
340-
}, _.debounce(event => {
341-
if (event === 'change') {
342-
this.refresh()
343-
}
344-
}, 100, {
345-
leading: false,
346-
trailing: true,
347-
}))
348-
this.watcher.on('error', (error) => console.error(error))
349-
}
334+
this.filePath = filePath
335+
// Fast file change detection
336+
this._closeWatcher()
337+
this.watcher = fs.watch(filePath, {
338+
persistent: false,
339+
})
340+
this.watcher.on('change', _.debounce(event => { // Refresh once
341+
this.refresh()
342+
}, 100))
343+
this.watcher.on('error', (error) => console.error(error))
350344
}
351345
}
352346

0 commit comments

Comments
 (0)