Skip to content

Commit

Permalink
fix: generate unique client id (#423)
Browse files Browse the repository at this point in the history
  • Loading branch information
egoist authored Sep 8, 2019
1 parent d9b86ae commit cf85e81
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
6 changes: 5 additions & 1 deletion packages/saber/vue-renderer/app/dev-client.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import client from 'webpack-hot-middleware/client'

export const init = ({ router }) => {
window.__SABER_DEV_CLIENT_ID__ = Math.random()
.toString(36)
.substring(7)

client.subscribe(obj => {
if (obj.action === 'router:push') {
if (obj.action === 'router:push' && obj.id === __SABER_DEV_CLIENT_ID__) {
if (obj.error) {
console.error(`You need to refresh the page when the error is fixed!`)
}
Expand Down
2 changes: 1 addition & 1 deletion packages/saber/vue-renderer/app/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export default () => {
next(false)

visitedRoutes[to.path] = true
fetch('/_saber/visit-page?route=' + encodeURIComponent(to.fullPath))
fetch(`/_saber/visit-page?id=${window.__SABER_DEV_CLIENT_ID__}&route=${encodeURIComponent(to.fullPath)}`)
})

router.afterEach(() => {
Expand Down
7 changes: 6 additions & 1 deletion packages/saber/vue-renderer/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -432,13 +432,18 @@ class VueRenderer {
res.end()

if (this.builtRoutes.has(pathname)) {
hotMiddleware.publish({ action: 'router:push', route: fullPath })
hotMiddleware.publish({
action: 'router:push',
route: fullPath,
id: req.query.id
})
} else {
event.once('done', error => {
this.builtRoutes.add(pathname)
hotMiddleware.publish({
action: 'router:push',
route: fullPath,
id: req.query.id,
error
})
})
Expand Down

0 comments on commit cf85e81

Please sign in to comment.