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 Transition Bug #16983

Merged
merged 4 commits into from Sep 1, 2022
Merged

LinkTo Transition Bug #16983

merged 4 commits into from Sep 1, 2022

Conversation

zofskeez
Copy link
Contributor

@zofskeez zofskeez commented Sep 1, 2022

It was discovered that in production builds of Ember, LinkTo elements that used the on click modifier were transitioning to the incorrect route. During the latest Ember upgrade a new lint rule was alerting of unsupported arguments being used on the LinkTo component. In this case, invokeAction was being provided by the ember-link-action addon which was removed in favor of using the on modifier.

Since it works as expected in development builds it seems like it could be a bug in Ember, but it also seems like a link that has a click event is maybe not the best pattern. After attempting to find a way to make a click event work it was decided to use the button element instead along with the router service to transition inside the event handler.

Migrations Details

A script was created for ember-template-recast to identify any template files that had LinkTo elements with the on modifier. The UI elements impacted were:

  • secret version links in version menu
  • secret View version history in version menu
  • all links in nav bar status menu (License, Client count etc.)
  • Sign out link in nav bar user menu
  • Nav drawer links (mobile only)

Where feasible, the LinkTo elements were changed to buttons and the router service was used to transition. In other cases where a link was appropriate the on modifier was added to the parent element.

Update

In the interests of accessibility the updates to use the button element over LinkTo were reverted. After further testing, the issue was not with the on click modifier but specifically with closing the dropdown in the event handler. To work around this the dropdown is now being closed in the next tick of the run loop which allows for the transition to complete as expected.

@zofskeez zofskeez added ui bug Used to indicate a potential bug backport/1.11.x labels Sep 1, 2022
@zofskeez zofskeez added this to the 1.12.0-rc1 milestone Sep 1, 2022
&.active {
&.is-active {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

While attempting to test that the nav drawer closed when clicking a link on smaller screens I noticed that it wasn't appearing on screen in the first place. Updating the class name to match the template fixed the issue.

@vercel
Copy link

vercel bot commented Sep 1, 2022

Deployment failed with the following error:

Invalid website/vercel.json file provided

@models={{this.link.models}}
@query={{this.query}}
@disabled={{@disabled}}
{{on "click" this.onLinkClick}}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was only being used in the SecretVersionMenu component to close the menu but since a new route is transitioned to the menu is torn down making it unnecessary.

@@ -113,7 +113,6 @@
"ember-export-application-global": "^2.0.1",
"ember-fetch": "^8.1.1",
"ember-inflector": "4.0.2",
"ember-link-action": "^1.0.0",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was no longer used as of 1.11

}
},
};
};
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This probably won't be used again but it might be good to keep all of the recast scripts around for examples to help with future codemods.

Copy link
Collaborator

Choose a reason for hiding this comment

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

This is great to see, as someone who's never written a codemod!

Copy link
Collaborator

@hashishaw hashishaw left a comment

Choose a reason for hiding this comment

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

I wonder if we could keep leveraging LinkTo but use a different method to trigger callbacks?

@@ -12,48 +12,52 @@
<NamespacePicker @class="navbar-item" @namespace={{this.namespaceQueryParam}} />
</li>
{{/if}}
<li class={{if (is-active-route "vault.cluster.secrets") "is-active"}}>
<li class={{if (is-active-route "vault.cluster.secrets") "is-active"}} role="button" {{on "click" Nav.closeDrawer}}>
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think I like this pattern better, where we add the "side effects" click event on the event outside the element, which just has the @route link. I'm concerned that making these links technically buttons violates some A11y concerns, except of course in cases when the button is triggering a save or submit, and then redirecting.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I wondered about that too and ultimately followed the suggestions from the linter. I think since the li is the parent element it's not actually the link so the role of button might be ok? Basically the li is acting as a button to close the nav drawer. The nested link functions as a link to transition routes.

}
},
};
};
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is great to see, as someone who's never written a codemod!

@zofskeez
Copy link
Contributor Author

zofskeez commented Sep 1, 2022

I wonder if we could keep leveraging LinkTo but use a different method to trigger callbacks?

I had some success using {{action}} rather than {{on}} but it didn't always work. For example it seemed to work in the status menu but not for the secrets version links so that's when I decided it was too unreliable. Since action is being deprecated that also pushed me to refactor.

@action
closeDropdown(dropdown) {
// strange issue where closing dropdown triggers full transition which redirects to auth screen in production builds
// closing dropdown in next tick of run loop fixes it
Copy link
Collaborator

Choose a reason for hiding this comment

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

🤯

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Haha yes! I noticed that a full page reload was happening when only a partial transition should have been taking place. I wonder if closing the dropdown in the same tick was throwing an error behind the scenes which caused issues with the transition?

Copy link
Collaborator

@hashishaw hashishaw left a comment

Choose a reason for hiding this comment

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

Thank you for your diligence! 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Used to indicate a potential bug ui
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants