Skip to content

Commit

Permalink
[BUGFIX] don't alter queryParam argument in RouterService#isActive
Browse files Browse the repository at this point in the history
  • Loading branch information
bekzod committed Feb 6, 2019
1 parent 299693e commit 041ee8b
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
3 changes: 3 additions & 0 deletions packages/@ember/-internals/routing/lib/services/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Evented } from '@ember/-internals/runtime';
import { EMBER_ROUTING_ROUTER_SERVICE } from '@ember/canary-features';
import { assert } from '@ember/debug';
import { readOnly } from '@ember/object/computed';
import { assign } from '@ember/polyfills';
import Service from '@ember/service';
import { DEBUG } from '@glimmer/env';
import { Transition } from 'router_js';
Expand Down Expand Up @@ -148,12 +149,14 @@ export default class RouterService extends Service {
let hasQueryParams = Object.keys(queryParams).length > 0;

if (hasQueryParams) {
queryParams = assign({}, queryParams);
this._router._prepareQueryParams(
routeName,
models,
queryParams,
true /* fromRouterService */
);

return shallowEqual(queryParams, routerMicrolib.state!.queryParams);
}

Expand Down
25 changes: 25 additions & 0 deletions packages/ember/tests/routing/router_service_test/isActive_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,5 +105,30 @@ moduleFor(
);
});
}

['@test RouterService#isActive does not alter query params hash'](assert) {
assert.expect(2);

this.add(
'controller:parent.child',
Controller.extend({
queryParams: ['sort', 'page'],
sort: 'ASC',
page: 1,
})
);

let qp = this.buildQueryParams({ sort: 'ascending' });

return this.visit('/')
.then(() => {
return this.routerService.transitionTo('parent.child', qp);
})
.then(() => {
assert.ok(this.routerService.isActive('parent.child', qp));
assert.ok(this.routerService.isActive('parent.child', qp)); // using same qp second time should not fail
assert.deepEqual(qp.queryParams, { sort: 'ascending' });
});
}
}
);

0 comments on commit 041ee8b

Please sign in to comment.