Skip to content

Commit

Permalink
fix(core): Fix leak of old transitions by mutating pathnode*.resolvab…
Browse files Browse the repository at this point in the history
…les*.data

Fixes #55
Fixes angular-ui/ui-router#3603
Fixes ui-router/angular#21
  • Loading branch information
christopherthielen committed Feb 12, 2018
1 parent 4dddd20 commit 0a1f518
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions src/hooks/coreResolvables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Transition } from '../transition/transition';
import { UIRouter } from '../router';
import { TransitionService } from '../transition/transitionService';
import { Resolvable } from '../resolve';
import { extend, inArray, map, mapObj, unnestR, values } from '../common';
import { extend, inArray, map, mapObj, uniqR, unnestR, values } from '../common';
import { PathNode } from '../path';
import { TreeChanges } from "../transition";

Expand All @@ -29,15 +29,14 @@ const isTransition = inArray(TRANSITION_TOKENS);
// This function removes resolves for '$transition$' and `Transition` from the treeChanges.
// Do not use this on current transitions, only on old ones.
export const treeChangesCleanup = (trans: Transition) => {
const nodes = values(trans.treeChanges()).reduce(unnestR, []).reduce(uniqR, []);

// If the resolvable is a Transition, return a new resolvable with null data
const replaceTransitionWithNull = (r: Resolvable): Resolvable =>
isTransition(r.token) ? Resolvable.fromData(r.token, null) : r;
const replaceTransitionWithNull = (r: Resolvable): Resolvable => {
return isTransition(r.token) ? Resolvable.fromData(r.token, null) : r;
};

const cleanPath = (path: PathNode[]) => path.map((node: PathNode) => {
const resolvables = node.resolvables.map(replaceTransitionWithNull);
return extend(node.clone(), { resolvables });
nodes.forEach((node: PathNode) => {
node.resolvables = node.resolvables.map(replaceTransitionWithNull);
});

const treeChanges: TreeChanges = trans.treeChanges();
mapObj(treeChanges, cleanPath, treeChanges);
};

0 comments on commit 0a1f518

Please sign in to comment.