Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Calling recognize should not affect the transition.from query params for subsequent transitions #336

Merged
merged 3 commits into from Mar 6, 2024

Conversation

chbonser
Copy link
Contributor

@chbonser chbonser commented Nov 27, 2023

Problem Statement
Calling router.recognize with a URL which matches the current route affects the transition.from.queryParams for subsequent transitions. I've created a failing test here.

Root Cause
The root cause appears to be caused by the fact that toReadOnlyRouteInfo (source) closes over a WeakMap for ROUTE_INFOS which is then mutated on subsequent calls (including calls from router.recognize).

Proposed Solution
This PR adds a new argument to toReadOnlyRouteInfo, localizeMapUpdates, which allows the function to conditionally use a locally scoped map instead of the map from the parent scope. Interestingly, always using a locally scoped map in toReadOnlyRouteInfo causes a number of tests to fail.

recognize was then updated to enable the new option (see here).

This proposal passes this project's test suite and a large production Ember app's test suite.

…nally using a local map for toReadOnlyRouteInfo. Always using a local map for toReadOnlyRouteInfo causes many tests to fail so apparently it is expected to polute state in many instances.
})
.then(() => {
secondParam = true;
router.recognize('/search?term=foo');

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test isn't actually convincing me that the query params aren't mutated, because they use the same qp.

If recognize was used with a query param that wasn't term, then I would be convinced!

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@NullVoxPopuli query param has been updated

Copy link

@NullVoxPopuli NullVoxPopuli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a ton for working on this, I think the change is fine, and given that folks will / should be using recognize for determining "active" state for their links, this is a great fix.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New file?

Copy link

@NullVoxPopuli NullVoxPopuli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have access to merge and release, but this seems fine

@acorncom
Copy link

@NullVoxPopuli looks like @wagenet had release on this a few years back, might be worth seeing if he could?

@wagenet wagenet merged commit f39f2df into tildeio:master Mar 6, 2024
4 checks passed
@wagenet
Copy link
Collaborator

wagenet commented Mar 6, 2024

I also released this as 8.0.4.

@wagenet
Copy link
Collaborator

wagenet commented Mar 6, 2024

Update to Ember: emberjs/ember.js#20656

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants