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
  • Loading branch information
christopherthielen authored and wawyed committed Mar 3, 2018
1 parent a68f9f2 commit 8ac7466
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 8ac7466

Please sign in to comment.