You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In Ember, while transitioning between routes, the function getChangelist is used to compare the state between transitions. You can find its implementation here:
The problem with this function is that, when comparing old and new queryParams, it mutates the parameters by stringifying them, which I believe should be immutable. The issue arises from this code:
For example, if the query parameters contain an array of objects, the result becomes ['[object Object]']. A current workaround to this problem is to avoid using arrays as values, as it wont get stringified by lack of cases in the stringifier function
Complex QueryParams Example:
In our Ember app, we use a complex structure for queryParams when transitioning between routes. For instance:
However, we don't really map all this data to the URL, some of these is read and thats it.
classSomeRouteextendsRoute{model(_,transition){const{ to }=transition;// Here, reports is an array of ['object object']transition.to.reports.forEach();// This will has an issue, all of the elements are now `['[object Object]']`}}
Observations:
Immutability: The parameters shouldn't be mutated at all, especially since it's only for comparison purposes. An alternative approach should be used.
Comparison Logic: When comparing objects, a more robust library like deepEquals or fastEquals should be used? Because there are too many edge cases that can't be properly handled by simply coercing values to strings.
The text was updated successfully, but these errors were encountered:
betocantu93
changed the title
Why does the transition queryParams values get stringified
Issue with getChangelist in Router.js
Oct 23, 2024
betocantu93
changed the title
Issue with getChangelist in Router.js
Issue with getChangelist
Oct 23, 2024
betocantu93
changed the title
Issue with getChangelist
Issue with getChangelist, queryParams getting stringified
Oct 23, 2024
betocantu93
changed the title
Issue with getChangelist, queryParams getting stringified
Issue with getChangelist, transition.queryParams getting mutated by stringified
Oct 23, 2024
Issue with
getChangelist
in Router.jsIn Ember, while transitioning between routes, the function
getChangelist
is used to compare the state between transitions. You can find its implementation here:getChangelist
functionThe problem with this function is that, when comparing old and new
queryParams
, it mutates the parameters by stringifying them, which I believe should be immutable. The issue arises from this code:getChangelist
For example, if the query parameters contain an array of objects, the result becomes
['[object Object]']
. A current workaround to this problem is to avoid using arrays as values, as it wont get stringified by lack of cases in the stringifier functionComplex QueryParams Example:
In our Ember app, we use a complex structure for
queryParams
when transitioning between routes. For instance:However, we don't really map all this data to the URL, some of these is read and thats it.
Observations:
Immutability: The parameters shouldn't be mutated at all, especially since it's only for comparison purposes. An alternative approach should be used.
Comparison Logic: When comparing objects, a more robust library like
deepEquals
orfastEquals
should be used? Because there are too many edge cases that can't be properly handled by simply coercing values to strings.The text was updated successfully, but these errors were encountered: