emberjs / ember.js

Ember.js - A JavaScript framework for creating ambitious web applications
https://emberjs.com
MIT License
22.47k stars 4.21k forks source link

`<LinkTo>` without `@route` param but with `@query` breaks when navigating to error route #17963

Closed buschtoens closed 5 years ago

buschtoens commented 5 years ago

While working on https://github.com/ember-engines/ember-engines/pull/642 to make ember-engines compatible with Ember Octane, I noticed that https://github.com/emberjs/ember.js/pull/17772 appears to have broken an edge case for <LinkTo> without a @route argument, but with a @query argument.

I made a reproduction here: https://codesandbox.io/s/p32ozvvz0x

If no explicit @route is passed it will be set to (or remain) UNDEFINED:

https://github.com/emberjs/ember.js/blob/2cc35738f2938e6b9735d0d641214b0721d53a4b/packages/%40ember/-internals/glimmer/lib/components/link-to.ts#L895-L900

In this case _route returns the currently active route:

https://github.com/emberjs/ember.js/blob/2cc35738f2938e6b9735d0d641214b0721d53a4b/packages/%40ember/-internals/glimmer/lib/components/link-to.ts#L490-L493

This then breaks the href computed property in L791, if the router performs an intermediate transition to an error route:

https://github.com/emberjs/ember.js/blob/2cc35738f2938e6b9735d0d641214b0721d53a4b/packages/%40ember/-internals/glimmer/lib/components/link-to.ts#L749-L804

routing.generateURL(route, models, query) is called as:

routing.generateURL("blog.post.error", [], { lang: "Japanese" });

Which misses the error param:

Error: You must provide param `error` to `generate`.

This apparently used to work and while being a weird edge-case, I would still expect it to work.

rwjblue commented 5 years ago

Thank you for reporting!

rwjblue commented 5 years ago

Just to confirm, this is a bug in 3.10.0-beta series right?

buschtoens commented 5 years ago

Correct! AFAICT it's working in 3.9.

buschtoens commented 5 years ago

Awesome! 🎉