Skip to content

Commit

Permalink
fix undefined routeInfo in routeInfos.find's callback
Browse files Browse the repository at this point in the history
  • Loading branch information
sly7-7 committed Aug 26, 2022
1 parent 8a55b2e commit ba914f8
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/router/route-info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ export default class InternalRouteInfo<R extends Route> {

if (cached !== undefined) {
// SAFETY: This is potentially a bit risker, but for what we're doing, it should be ok.
ROUTE_INFOS.set((this as unknown) as InternalRouteInfo<Route>, cached);
ROUTE_INFOS.set((resolved as unknown) as InternalRouteInfo<Route>, cached);
}

return resolved;
Expand Down
29 changes: 29 additions & 0 deletions tests/router_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2385,6 +2385,35 @@ scenarios.forEach(function (scenario) {
transitionTo(router, '/posts/admin/1/posts');
});

test(`transition.to.find's callback is always called with defined routeInfo`, function (assert) {
type Application = { app: boolean } & IModel;

assert.expect(3);

map(assert, function (match) {
match('/').to('application', function (match) {
match('/peter').to('peter', function (match) {
match('/wagenet').to('wagenet');
});
});
});

routes = {
application: createHandler<Application>('application'),
peter: createHandler('peter'),
wagenet: createHandler('wagenet', {
model: function (_params: Dict<unknown>, transition: Transition) {
transition.to!.find((routeInfo) => {
assert.ok(routeInfo, 'routeInfo is defined');
return false;
});
},
}),
};

transitionTo(router, '/peter/wagenet');
});

test('Moving to the same route with a different parent dynamic segment re-runs model', function (assert) {
let admins: Dict<any> = { 1: { id: 1 }, 2: { id: 2 } },
adminPosts: Dict<any> = { 1: { id: 1 }, 2: { id: 2 } };
Expand Down

0 comments on commit ba914f8

Please sign in to comment.