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

Removed unnecessary className on Link #3288

Merged
merged 1 commit into from
Apr 13, 2016

Conversation

EloB
Copy link
Contributor

@EloB EloB commented Apr 12, 2016

<Link /> always adds the class="" attribute even when it's not defined or is active. When you do server rendering you don't want unnecessary attributes.

@timdorr
Copy link
Member

timdorr commented Apr 13, 2016

LGTM 👍

@@ -119,7 +118,7 @@ const Link = React.createClass({
if (activeClassName || (activeStyle != null && !isEmptyObject(activeStyle))) {
if (router.isActive(location, onlyActiveOnIndex)) {
if (activeClassName)
props.className += props.className === '' ? activeClassName : ` ${activeClassName}`
props.className = `${props.className || ''} ${activeClassName}`.trim()
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there any harm to just pulling in classnames here? I can't imagine anybody doesn't have classnames already installed, so this should dedupe trivially.

Otherwise IMO this is better written as:

if (activeClassName) {
  if (props.className) {
    props.className += ` ${activeClassName}`
  } else {
    props.className = activeClassName
  }
}

Copy link
Member

Choose a reason for hiding this comment

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

Agreed. We can do that after merge. For now, this gets the job done and adds a test so any further fixes are easier.

Copy link
Member

Choose a reason for hiding this comment

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

I haven't used a className in a while.

@EloB
Copy link
Contributor Author

EloB commented Apr 13, 2016

👍

@taion
Copy link
Contributor

taion commented Apr 13, 2016

LGTM as well, then. Thanks!

@taion taion merged commit 0a42723 into remix-run:master Apr 13, 2016
@mxstbr
Copy link
Contributor

mxstbr commented Apr 13, 2016

I don't use class names in react-boilerplate, I've never had a good use for it. (sorry @JedWatson!)

I wouldn't go assuming everybody has it installed!

@EloB EloB deleted the feature/strip-unnecessary-class branch April 13, 2016 21:59
@lock lock bot locked as resolved and limited conversation to collaborators Jan 19, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants