[Bug] `RouterService.isActive` always returns false with default query param
🐞 Describe the Bug
If controller:a has a query param 'qp' with default value 'qp_default_value', then
router.isActive('a', { queryParams: { qp: 'qp_default_value' } }) returns false, when this state is actually active.
<LinkTo @route="a" @query={{hash qp="qp_default_value"}}> is active as expected.
🔬 Minimal Reproduction
https://ember-twiddle.com/b1ec63ecf5137028438feede3189f621?openFiles=templates.application%5C.hbs%2C&route=%2Fa%3Fqp%3Dfoo
🌍 Environment
- Ember: any, from the moment
service:routeris implemented.
I've wanted this behavior too. I think I read somewhere that it wasn't implement for performance reasons, but I don't think we need to worry about that -- we wouldn't be doing deep equality checking or anything
I believe this issue was fixed in a more recent version of Ember. Just had a look to fix this in the isActive method in the Router service.
In the version that's used in the Ember Twiddle, this shallowEqual returned in isActive used to compare queryParams to routerMicrolib.state!.queryParams, while only pruning the default QP values from queryParams (the pruning happens as part of _prepareQueryParams). Since the default values were pruned in queryParams but not in routerMicrolib.state!.queryParams, the shallowEqual resolved to false.
Currently, the shallowEqual compares queryParams to currentQueryParams, after pruning the default QP values by doing _prepareQueryParams on both of them.