8000 fix(ssr): memory leak in poll method by ronald-d-rogers · Pull Request #2875 · vuejs/vue-router · GitHub
[go: up one dir, main page]

Skip to content

fix(ssr): memory leak in poll method #2875

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Oct 6, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix: cb called before data init in keep-alive view and mixin guards n…
…ot being called
  • Loading branch information
ronald-d-rogers committed Aug 10, 2019
commit 062a5aa29c2b1dae5b08d585608f82fb62c5dede
2 changes: 1 addition & 1 deletion flow/declarations.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ declare type RouteRecord = {
regex: RouteRegExp;
components: Dictionary<any>;
instances: Dictionary<any>;
pendingCbs: Dictionary<Function>;
pendingCbs: Dictionary<Array<Function>>;
name: ?string;
parent: ?RouteRecord;
redirect: ?RedirectOption;
Expand Down
9 changes: 4 additions & 5 deletions src/components/view.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { warn } from '../util/warn'
import { extend } from '../util/misc'
import { tryFinalizeTransition } from '../history/base'
import { tryFinalizeTransition } from '../util/route'

export default {
name: 'RouterView',
Expand Down Expand Up @@ -64,17 +64,16 @@ export default {
(!val && current === vm)
) {
matched.instances[name] = val
// if the route transition has already been confirmed then we weren't
// able to call the cb during confirmation as the component was not
// registered yet, so we call it here.
tryFinalizeTransition(matched, name)
}
}

// also register instance in prepatch hook
// in case the same component instance is reused across different routes
;(data.hook || (data.hook = {})).prepatch = (_, vnode) => {
matched.instances[name] = vnode.componentInstance
// if the route transition has already been confirmed then we weren't
// able to call the cb during confirmation as the component was not
// registered yet, so we call it here.
tryFinalizeTransition(matched, name)
}

Expand Down
16 changes: 5 additions & 11 deletions src/history/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type Router from '../index'
import { inBrowser } from '../util/dom'
import { runQueue } from '../util/async'
import { warn, isError, isExtendedError } from '../util/warn'
import { START, isSameRoute } from '../util/route'
import { START, isSameRoute, tryFinalizeTransition } from '../util/route'
import {
flatten, 8000
flatMapComponents,
Expand Down Expand Up @@ -317,7 +317,10 @@ function bindEnterGuard (
return function routeEnterGuard (to, from, next) {
return guard(to, from, cb => {
if (typeof cb === 'function') {
match.pendingCbs[key] = cb
if (!match.pendingCbs[key]) {
match.pendingCbs[key] = []
}
match.pendingCbs[key].push(cb)
cbs.push(() => {
// if the instance is registered call the cb here, otherwise it will
// get called when it is registered in the component's lifecycle hooks
Expand All @@ -328,12 +331,3 @@ function bindEnterGuard (
})
}
}

export function tryFinalizeTransition (record: RouteRecord, name: string) {
if (record.instances[name] && record.pendingCbs[name]) {
const instance = record.instances[name]
const cb = record.pendingCbs[name]
delete record.pendingCbs[name]
cb(instance)
}
}
11 changes: 11 additions & 0 deletions src/util/route.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,3 +130,14 @@ function queryIncludes (current: Dictionary<string>, target: Dictionary<string>)
}
return true
}

export function tryFinalizeTransition (record: RouteRecord, name: string) {
if (record.instances[name] && record.pendingCbs[name]) {
const instance = record.instances[name]
const cbs = record.pendingCbs[name]
delete record.pendingCbs[name]
for (let i = 0; i < cbs.length; i++) {
cbs[i](instance)
}
}
}
0