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鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Bug] Chained redirects triggered via routeWillChange
lead to calling model() hook with wrong params
#20611
Comments
When there is a chain of two redirects triggered via a routeWillChange hook, the destination route model() hook is called twice, and is called with the wrong parameters. Failing test for emberjs#20611
hello @davidtaylorhq would you be able to provide more info on the expected behaviour? a link to a RFC that described that behaviour or documentation to that effect or the use case that you have I can also see the thinking behind the current behaviour where doing a redirect outside the beforeModel hook would end up calling it twice as routeWillChange happens after the model hook is called and the transition is considered settled as per the docs here https://api.emberjs.com/ember/release/classes/routerservice/events/ |
Perhaps you're thinking of My understanding is that Even if we decided the double-call of the The failing test illustrates both the double-call and the incorrect-param issue. ('willchange-to' is logged in the
|
in your example you're never aborting the current transition when redirecting to id 3 or am I missing something? |
That's true. And indeed, if I add manual But still, this requirement is quite unexpected. In the redirection docs it says that calling
So perhaps the bug report here should really be "Transitions are not implicitly aborted when chaining multiple redirects via |
I honestly would never expect that to work from an event but rather via initiating a new transition from a beforeModel hook and someone with knowledge of the intentions of the code here should correct me if what I'm saying is wrong |
I agree that I would have used a hook on the parent route rather than the router service event to accomplish the same thing. I also suspect that this is is a slight different in routerService.transitionTo vs router.transitionTo (but have not verified). We are unlikely to change any router code at this point (any bug we fix breaks someone else relying upon said bug), so for now, I would either refactor to use |
馃悶 Describe the Bug
When there is a chain of two redirects triggered via a
routeWillChange
hook, the destination route model() hook is called twice, and is called with the wrong parameters.馃敩 Minimal Reproduction
Visiting
/dynamic/1
will redirect to/dynamic/3
, but the model hook will be called (twice) withdynamic_id=2
.Failing test case in #20612
馃槙 Actual Behavior
The model hook will be called (twice) with
dynamic_id=2
.馃 Expected Behavior
The model hook should be called once with
dynamic_id=3
馃實 Environment
Tested under Ember 3.28 and 5.6.0.beta2
The text was updated successfully, but these errors were encountered: