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

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

Closed
buschtoens opened this issue Apr 24, 2019 · 4 comments · Fixed by #17971
Closed
Milestone

Comments

@buschtoens
Copy link
Contributor

buschtoens commented Apr 24, 2019

While working on ember-engines/ember-engines#642 to make ember-engines compatible with Ember Octane, I noticed that #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:

// 3. If there is a `route`, it is now at index 0.
if (params.length === 0) {
this.set('route', UNDEFINED);
} else {
this.set('route', params.shift());
}

In this case _route returns the currently active route:

_route: computed('route', '_currentRoute', function computeLinkToComponentRoute(this: any) {
let { route } = this;
return route === UNDEFINED ? this._currentRoute : route;
}),

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

/**
Sets the element's `href` attribute to the url for
the `LinkComponent`'s targeted route.
If the `LinkComponent`'s `tagName` is changed to a value other
than `a`, this property will be ignored.
@property href
@private
*/
href: computed(
'_currentRouterState',
'_route',
'_models',
'_query',
'tagName',
'loading',
'loadingHref',
function computeLinkToComponentHref(this: any) {
if (this.tagName !== 'a') {
return;
}
if (this.loading) {
return this.loadingHref;
}
let { _route: route, _models: models, _query: query, _routing: routing } = this;
if (DEBUG) {
/*
* Unfortunately, to get decent error messages, we need to do this.
* In some future state we should be able to use a "feature flag"
* which allows us to strip this without needing to call it twice.
*
* if (isDebugBuild()) {
* // Do the useful debug thing, probably including try/catch.
* } else {
* // Do the performant thing.
* }
*/
try {
return routing.generateURL(route, models, query);
} catch (e) {
// tslint:disable-next-line:max-line-length
assert(
`You attempted to generate a link for the "${this.route}" route, but did not ` +
`pass the models required for generating its dynamic segments. ` +
e.message
);
}
} else {
return routing.generateURL(route, models, query);
}
}
),

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.

@buschtoens buschtoens changed the title <LinkTo> without @route param but with @query breaks when navigating to error route <LinkTo> without @route param but with @query breaks when navigating to error route Apr 24, 2019
@rwjblue
Copy link
Member

rwjblue commented Apr 24, 2019

Thank you for reporting!

@rwjblue
Copy link
Member

rwjblue commented Apr 24, 2019

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

@rwjblue rwjblue added this to the 3.10 milestone Apr 24, 2019
@buschtoens
Copy link
Contributor Author

Correct! AFAICT it's working in 3.9.

2hu12 added a commit to 2hu12/ember.js that referenced this issue Apr 25, 2019
Try to fix emberjs#17963, I'm not sure this is the right way and it's weird, but the old "qualifiedRouteName" property works in this way and "_route" is used similarly to "qualifiedRouteName".
2hu12 added a commit to 2hu12/ember.js that referenced this issue May 6, 2019
Try to fix emberjs#17963, I'm not sure this is the right way and it's weird, but the old "qualifiedRouteName" property works in this way and "_route" is used similarly to "qualifiedRouteName".
2hu12 added a commit to 2hu12/ember.js that referenced this issue May 7, 2019
Try to fix emberjs#17963, I'm not sure this is the right way and it's weird, but the old "qualifiedRouteName" property works in this way and "_route" is used similarly to "qualifiedRouteName".
2hu12 added a commit to 2hu12/ember.js that referenced this issue May 7, 2019
Try to fix emberjs#17963, I'm not sure this is the right way and it's weird, but the old "qualifiedRouteName" property works in this way and "_route" is used similarly to "qualifiedRouteName".
2hu12 added a commit to 2hu12/ember.js that referenced this issue May 7, 2019
Try to fix emberjs#17963, I'm not sure this is the right way and it's weird, but the old "qualifiedRouteName" property works in this way and "_route" is used similarly to "qualifiedRouteName".
dgeb added a commit that referenced this issue May 29, 2019
Attempt to reproduce failure in #17963: `<LinkTo>` without `@route` param but with `@query` breaks when navigating to error route
rwjblue added a commit that referenced this issue Jun 14, 2019
Reproduce failure in #17963: `<LinkTo>` without `@route` param but with
`@query` breaks when navigating to error route.

Co-authored-by: Robert Jackson <me@rwjblue.com>
rwjblue pushed a commit to 2hu12/ember.js that referenced this issue Jun 14, 2019
rwjblue added a commit to 2hu12/ember.js that referenced this issue Jun 14, 2019
… route.

Reproduce failure in emberjs#17963: `<LinkTo>` without `@route` param but with
`@query` breaks when navigating to error route.

Co-authored-by: Robert Jackson <me@rwjblue.com>
rwjblue added a commit that referenced this issue Jun 14, 2019
Try to fix #17963

Co-authored-by: Dan Gebhardt <dan@cerebris.com>
@buschtoens
Copy link
Contributor Author

Awesome! 🎉

rwjblue pushed a commit that referenced this issue Jun 17, 2019
rwjblue pushed a commit that referenced this issue Jun 17, 2019
… route.

Reproduce failure in #17963: `<LinkTo>` without `@route` param but with
`@query` breaks when navigating to error route.

Co-authored-by: Robert Jackson <me@rwjblue.com>
(cherry picked from commit efbc937)
rwjblue pushed a commit that referenced this issue Jun 17, 2019
rwjblue pushed a commit that referenced this issue Jun 17, 2019
… route.

Reproduce failure in #17963: `<LinkTo>` without `@route` param but with
`@query` breaks when navigating to error route.

Co-authored-by: Robert Jackson <me@rwjblue.com>
(cherry picked from commit efbc937)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants