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

[LTS fix] only return empty href when LinkTo href generation throws error #19395

Merged
merged 2 commits into from
Feb 11, 2021

Conversation

xg-wang
Copy link
Contributor

@xg-wang xg-wang commented Feb 10, 2021

Summary

In 3.24.0-3.24.2 we made changes to let LinkTo href generation returns
empty when initial transition is not started. This is not true and
causing regression on the super-rental tutorial ember-learn/super-rentals-tutorial#176.

In previous tutorials, the LinkTo component will return empty href when
this.owner.setupRouter() is not called. It generates valid href if
setupRouter() is called and complete model are passed for dynamic
segments.

In our previous changes, we removed the requirement to call
setupRouter, and always return empty href when initial transition is
not started. This is not expected when passing complete dynamic segments
without initial transition.

Test done

I linked the fix and super-rentals-tutorials pass test

In 3.24.0-3.24.2 we made changes to let LinkTo href generation returns
empty when initial transition is not started. This is not true and
causing regression on the super-rental tutorial.

In previous tutorials, the LinkTo component will return empty href when
`this.owner.setupRouter()` is not called. It generates valid href if
`setupRouter()` is called and complete model are passed for dynamic
segments.

In our previous changes, we removed the requirement to call
`setupRouter`, and always return empty href when initial transition is
not started. This is not expected when passing complete dynamic segments
without initial transition.
@xg-wang xg-wang changed the title fix: only return empty href when LinkTo href generation throws error [LTS fix] only return empty href when LinkTo href generation throws error Feb 10, 2021
Comment on lines 57 to 74
try {
let visibleQueryParams = {};
if (queryParams) {
assign(visibleQueryParams, queryParams);
this.normalizeQueryParams(routeName, models, visibleQueryParams as QueryParam);
}

return router.generate(routeName, ...models, {
queryParams: visibleQueryParams,
});
} catch (e) {
// Swallow error when transition has not started.
// When rendering in tests without visit(), we cannot infer the route context which <LinkTo/> needs be aware of
if (!router._initialTransitionStarted) {
return;
} else {
throw e;
}
Copy link
Member

Choose a reason for hiding this comment

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

Let's avoid the try/catch when we have started a transition, if we don't do that we break the ability to use the "break on uncaught exception" in the devtools.

I think a plausible solution here is something like:

_generateURL(routeName: string, models: {}[], queryParams: {}) {

}

generateURL(routeName: string, models: {}[], queryParams: {}) {
  let router = this.router;

  if (router._initialTransitionStarted) {
    try {
      return this._generateURL(routeName, models, queryParams);
    } catch (error) {
      return;
    }
  } else {
    return this._generateURL(routeName, models, queryParams);
  }
}

@rwjblue
Copy link
Member

rwjblue commented Feb 10, 2021

Very bizarre failure on IE11:

not ok 8 IE 11.0 - [98 ms] - Components test: <Input @type='checkbox' />:  sends an action with `<Input EVENT={{action "foo"}} />` for native DOM events
    ---
        actual: >
            touchstart,touchmove,touchend,touchcancel,keydown,keyup,keypress,mousedown,mouseup,contextmenu,change,click,dblclick,submit,input,change,dragstart,drag,dragenter,dragleave,dragover,drop,dragend,focusin
        expected: >
            touchstart,touchmove,touchend,touchcancel,keydown,keyup,keypress,mousedown,mouseup,contextmenu,change,click,dblclick,submit,input,change,dragstart,drag,dragenter,dragleave,dragover,drop,dragend
        stack: >

I'm going to restart CI as I don't think any code in <LinkTo /> should affect <Input /> tests..

@rwjblue rwjblue merged commit f5ffa06 into emberjs:master Feb 11, 2021
@rwjblue rwjblue added the Bug label Feb 11, 2021
@xg-wang xg-wang deleted the link-to-render-regression branch February 11, 2021 16:30
@chancancode
Copy link
Member

@xg-wang @rwjblue Is this what's causing the tutorial build to fail? https://github.com/ember-learn/super-rentals-tutorial/runs/1891443801?check_suite_focus=true#step:11:2684

If so, do you mind triggering a build on the tutorial after this went out to release/beta (Monday probably?) to confirm that it fixed the issue? You can go find the latest cron job that failed (e.g. https://github.com/ember-learn/super-rentals-tutorial/actions/runs/562659205) and click "Re-run jobs". If it won't let you, you can open a PR with an empty or trivial commit to force a build on the PR itself and close it after it ran successfully.

/cc @kategengler as well

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

Successfully merging this pull request may close these issues.

None yet

3 participants