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

SiteStatsStickyLink: remove shouldComponentUpdate #837

Merged
merged 1 commit into from
Nov 30, 2015

Conversation

artpi
Copy link
Contributor

@artpi artpi commented Nov 26, 2015

Why?

Because shouldComponentUpdate was bound to url, onClick and title,
the whole children subtree was not changed even if props changed there

The problem that occured in #473 was that after creating SECOND site in an account, the masterbar button was still 'My Site'
Screenshot

What consequences does it have?

SiteStatsStickyLink is not so widely used,
the performance shouldnt hit us:

Searching 32113 files for "SiteStatsStickyLink" (case sensitive)

/Users/Artpi/GIT/calypso/client/components/site-stats-sticky-link/index.jsx:
    6  var siteStatsStickyTabStore = require( 'lib/site-stats-sticky-tab/store' );
    7  
    8: var SiteStatsStickyLink = React.createClass( {
    9  
   10   propTypes: {
   ..
   46  } );
   47  
   48: module.exports = SiteStatsStickyLink;
   49  

/Users/Artpi/GIT/calypso/client/components/site-stats-sticky-link/README.md:
   10  ### usage:
   11  ```jsx
   12: var SiteStatsStickyLink = require( 'components/site-stats-sticky-link' );
   13  
   14  /* ...inside component render method: */
   15: <SiteStatsStickyLink
   16   onClick={ callback }
   17   title={ localizedTitle }>{
   18       localizedLinkTextAndOrImagesAsChildNodes
   19: }</SiteStatsStickyLink>
   20  ```
   21  

/Users/Artpi/GIT/calypso/client/layout/masterbar-sections-menu.jsx:
   12   MasterbarNewPost = require( 'layout/masterbar-new-post' ),
   13   layoutFocus = require( 'lib/layout-focus' ),
   14:  SiteStatsStickyLink = require( 'components/site-stats-sticky-link' ),
   15   Gravatar = require( 'components/gravatar' );
   16  
   ..
  109               <ul className="sections-menu">
  110                   <li className={ this.itemLinkClass( 'sites', { 'my-sites': true } ) }>
  111:                      <SiteStatsStickyLink onClick={ this.focusSidebar } title={ this.translate( 'View a list of your sites and access their dashboards', { textOnly: true } ) }>
  112                           { this.wordpressIcon() }
  113                           <span className="section-label">
  ...
  118                               }
  119                           </span>
  120:                      </SiteStatsStickyLink>
  121                   </li>
  122                   <li className={ this.itemLinkClass( 'reader', { home: true, reader: true } ) }>

/Users/Artpi/GIT/calypso/client/my-sites/sidebar/sidebar.jsx:
   16   CurrentSite = require( 'my-sites/current-site' ),
   17   PublishMenu = require( './publish-menu' ),
   18:  SiteStatsStickyLink = require( 'components/site-stats-sticky-link' ),
   19   productsValues = require( 'lib/products-values' ),
   20   getCustomizeUrl = require( 'lib/themes/helpers' ).getCustomizeUrl,
   ..
  113       return (
  114           <li className={ this.itemLinkClass( '/stats', 'stats' ) }>
  115:              <SiteStatsStickyLink onClick={ this.onNavigate }>
  116                   <Gridicon icon="stats-alt" size={ 24 } />
  117                   <span className="menu-link-text">{ this.translate( 'Stats' ) }</span>
  118:              </SiteStatsStickyLink>
  119           </li>
  120       );

Testing

  1. Log into account that has only 1 site (or register a new one)
  2. Click "Create new WordPress"
  3. Go through NUX until plan choice
  4. Just after clicking "Free Plan" notice My Site -> My Sites

Because shouldComponentUpdate was bound to url, onClick and title,
the whole children subtree was not changed even if props changed there
This was premature optimization
Fixes #473
@artpi artpi added [Type] Bug When a feature is broken and / or not performing as intended [Pri] Low Address when resources are available. [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. [Feature] Signup & Account Creation All screens and flows for making a new WordPress.com account. and removed [Feature] Signup & Account Creation All screens and flows for making a new WordPress.com account. labels Nov 26, 2015
@mtias
Copy link
Member

mtias commented Nov 26, 2015

cc @timmyc

@timmyc
Copy link
Contributor

timmyc commented Nov 27, 2015

ping @jblz as he is the original author of the component. That being said though, this change looks okay to me. I suppose comparing the child props in the componentShouldUpdate method would yield the same result, but would be a more costly operation.

@jblz
Copy link
Member

jblz commented Nov 27, 2015

looks good 👍

@timmyc Agreed that comparing child props vs. just re-rendering is probably a wash with how this component is used and removing the shouldComponentUpdate is simpler.

@jblz jblz added [Status] Ready to Merge and removed [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. labels Nov 27, 2015
artpi added a commit that referenced this pull request Nov 30, 2015
SiteStatsStickyLink: remove shouldComponentUpdate
@artpi artpi merged commit 8265f11 into master Nov 30, 2015
@artpi artpi deleted the fix/masterbar-2ndsite-mysites branch November 30, 2015 16:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Pri] Low Address when resources are available. [Type] Bug When a feature is broken and / or not performing as intended
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants