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

[Bug] LinkTo with incomplete model failing in rendering tests #19364

Closed
Turbo87 opened this issue Jan 30, 2021 · 3 comments
Closed

[Bug] LinkTo with incomplete model failing in rendering tests #19364

Turbo87 opened this issue Jan 30, 2021 · 3 comments

Comments

@Turbo87
Copy link
Member

Turbo87 commented Jan 30, 2021

🐞 Describe the Bug

We have a few components that use LinkTo components but are only used on subroutes with dynamic segments and have not explicitly added @model (e.g. only used within /organizations/:org_id). This works fine in production and up until Ember 3.24 this also worked fine in application and rendering tests.

With 3.24 Ember now automatically starts the routing layer whenever something on the router service is accessed, and now the LinkTo component is complaining that we did not pass the necessary models when any previous thing in the template for example accesses router.currentRouteName.

🔬 Minimal Reproduction

Describe steps to reproduce. If possible, please, share a link with a minimal reproduction.

// router.js

Router.map(function() {
  this.route('parent', { path: 'parent/:parent_id' }, function () {
    this.route('child');
  });
});
test('broken', async function(assert) {
  // access a property on the router
  this.owner.lookup('service:router').currentRouteName;

  // render a LinkTo with incomplete model
  await render(hbs`<LinkTo @route="parent.child">Link</LinkTo>`);
});

😕 Actual Behavior

Assertion Failed: You attempted to generate a link for the "parent.child" route, but did not pass the models required for generating its dynamic segments. Cannot read property 'shouldSupercede' of undefined

🤔 Expected Behavior

The LinkTo should render without an href like it did prior to Ember 3.24, or the router.currentRouteName access should not have the side-effect of automatically starting the routing layer, which is causing these issues.

🌍 Environment

  • Ember: 3.24

➕ Additional Context

somewhat related:

/cc @rwjblue @xg-wang

@xg-wang
Copy link
Contributor

xg-wang commented Feb 4, 2021

Sorry for the delay, I won't have much time until the weekend to look into the fix

@rwjblue
Copy link
Member

rwjblue commented Feb 8, 2021

Chatted about this with @xg-wang earlier, I think what we should do is to change this guard:

// return early when the router microlib is not present, which is the case for {{link-to}} in integration tests
if (!router._routerMicrolib) {
return;
}

To be something like:

    let router = this.router;
    // return early when the router microlib is not present, which is the case for {{link-to}} in integration tests
    if (!router._hasBeganInitialRouting) {
      return;
    }

Then update:

startRouting() {
if (this.setupRouter()) {
let initialURL = get(this, 'initialURL');
if (initialURL === undefined) {
initialURL = get(this, 'location').getURL();
}
let initialTransition = this.handleURL(initialURL);
if (initialTransition && initialTransition.error) {
throw initialTransition.error;
}
}
}

To set that flag.

@rwjblue
Copy link
Member

rwjblue commented Feb 10, 2021

Fixed by #19387, released in 3.25.1 and 3.24.2.

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

No branches or pull requests

3 participants