Skip to content

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

@Turbo87

Description

@Turbo87

🐞 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions