Skip to content

Commit 0a1f518

Browse files
fix(core): Fix leak of old transitions by mutating pathnode*.resolvables*.data
Fixes #55 Fixes angular-ui/ui-router#3603 Fixes ui-router/angular#21
1 parent 4dddd20 commit 0a1f518

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

src/hooks/coreResolvables.ts

+8-9
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { Transition } from '../transition/transition';
33
import { UIRouter } from '../router';
44
import { TransitionService } from '../transition/transitionService';
55
import { Resolvable } from '../resolve';
6-
import { extend, inArray, map, mapObj, unnestR, values } from '../common';
6+
import { extend, inArray, map, mapObj, uniqR, unnestR, values } from '../common';
77
import { PathNode } from '../path';
88
import { TreeChanges } from "../transition";
99

@@ -29,15 +29,14 @@ const isTransition = inArray(TRANSITION_TOKENS);
2929
// This function removes resolves for '$transition$' and `Transition` from the treeChanges.
3030
// Do not use this on current transitions, only on old ones.
3131
export const treeChangesCleanup = (trans: Transition) => {
32+
const nodes = values(trans.treeChanges()).reduce(unnestR, []).reduce(uniqR, []);
33+
3234
// If the resolvable is a Transition, return a new resolvable with null data
33-
const replaceTransitionWithNull = (r: Resolvable): Resolvable =>
34-
isTransition(r.token) ? Resolvable.fromData(r.token, null) : r;
35+
const replaceTransitionWithNull = (r: Resolvable): Resolvable => {
36+
return isTransition(r.token) ? Resolvable.fromData(r.token, null) : r;
37+
};
3538

36-
const cleanPath = (path: PathNode[]) => path.map((node: PathNode) => {
37-
const resolvables = node.resolvables.map(replaceTransitionWithNull);
38-
return extend(node.clone(), { resolvables });
39+
nodes.forEach((node: PathNode) => {
40+
node.resolvables = node.resolvables.map(replaceTransitionWithNull);
3941
});
40-
41-
const treeChanges: TreeChanges = trans.treeChanges();
42-
mapObj(treeChanges, cleanPath, treeChanges);
4342
};

0 commit comments

Comments
 (0)