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

Add guards to decodeEntieties so it is not called with undefined. #6551

Merged
merged 16 commits into from
Aug 1, 2016
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 2 additions & 38 deletions client/my-sites/theme/controller.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,43 +2,25 @@
* External Dependencies
*/
import React from 'react';
import omit from 'lodash/omit';
import debugFactory from 'debug';
import startsWith from 'lodash/startsWith';
import i18n from 'i18n-calypso';

/**
* Internal Dependencies
*/
import ThemeSheetComponent from './main';
import ThemeDetailsComponent from 'components/data/theme-details';
import { getCurrentUser } from 'state/current-user/selectors';
import { getThemeDetails } from 'state/themes/theme-details/selectors';
import {
receiveThemeDetails,
receiveThemeDetailsFailure,
setBackPath
} from 'state/themes/actions';
import wpcom from 'lib/wp';
import config from 'config';
import { decodeEntities } from 'lib/formatting';

const debug = debugFactory( 'calypso:themes' );
let themeDetailsCache = new Map();

export function makeElement( ThemesComponent, Head, store, props ) {
return (
<Head
title={ props.title }
description={ props.description }
type={ 'website' }
canonicalUrl={ props.canonicalUrl }
image={ props.image }
tier={ props.tier || 'all' }>
<ThemesComponent { ...omit( props, [ 'title' ] ) } />
</Head>
);
}
const themeDetailsCache = new Map();

export function fetchThemeDetailsData( context, next ) {
if ( ! config.isEnabled( 'manage/themes/details' ) || ! context.isServerSide ) {
Expand Down Expand Up @@ -76,24 +58,6 @@ export function fetchThemeDetailsData( context, next ) {
export function details( context, next ) {
const { slug } = context.params;
const user = getCurrentUser( context.store.getState() );
const themeDetails = getThemeDetails( context.store.getState(), slug ) || false;
const themeName = themeDetails.name;
const title = i18n.translate( '%(themeName)s Theme', {
args: { themeName }
} );
const Head = user
? require( 'layout/head' )
: require( 'my-sites/themes/head' );

const props = {
themeSlug: slug,
contentSection: context.params.section,
title: decodeEntities( title ) + ' — WordPress.com', // TODO: Use lib/screen-title's buildTitle. Cf. https://github.com/Automattic/wp-calypso/issues/3796
description: decodeEntities( themeDetails.description ),
canonicalUrl: `https://wordpress.com/theme/${ slug }`, // TODO: use getDetailsUrl() When it becomes availavle
image: themeDetails.screenshot,
isLoggedIn: !! user
};

if ( startsWith( context.prevPath, '/design' ) ) {
context.store.dispatch( setBackPath( context.prevPath ) );
Expand All @@ -105,7 +69,7 @@ export function details( context, next ) {
</ThemeDetailsComponent>
);

context.primary = makeElement( ConnectedComponent, Head, context.store, props );
context.primary = ConnectedComponent( { themeSlug: slug, contentSection: context.params.section, isLoggedIn: !! user } );
context.secondary = null; // When we're logged in, we need to remove the sidebar.
next();
}
69 changes: 45 additions & 24 deletions client/my-sites/theme/main.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import { getBackPath } from 'state/themes/themes-ui/selectors';
import EmptyContentComponent from 'components/empty-content';
import ThemePreview from 'my-sites/themes/theme-preview';
import PageViewTracker from 'lib/analytics/page-view-tracker';
import { decodeEntities } from 'lib/formatting';

const ThemeSheet = React.createClass( {
displayName: 'ThemeSheet',
Expand Down Expand Up @@ -345,33 +346,53 @@ const ThemeSheet = React.createClass( {
const analyticsPath = `/theme/:slug${ section ? '/' + section : '' }${ siteID ? '/:site_id' : '' }`;
const analyticsPageTitle = `Themes > Details Sheet${ section ? ' > ' + titlecase( section ) : '' }${ siteID ? ' > Site' : '' }`;

const Head = this.props.isLoggedIn
? require( 'layout/head' )
: require( 'my-sites/themes/head' );
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd really love if we could get rid of the conditional import while we're here; I'm quite sure layout/head is all we ever need here. You can read its source (and compare to what fields we override here in main.jsx) to validate that assumption -- or maybe just try without and compare resulting title and metas. :-)


const themeName = this.props.name;
Copy link
Contributor

Choose a reason for hiding this comment

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

Just FYI, there's a neat shorthand for a construct like this,

const { name: themeName } = this.props;

const title = i18n.translate( '%(themeName)s Theme', {
args: { themeName }
} );

const canonicalUrl = `https://wordpress.com/theme/${ this.props.id }`; // TODO: use getDetailsUrl() When it becomes availavle

return (
<Main className="theme__sheet">
<PageViewTracker path={ analyticsPath } title={ analyticsPageTitle }/>
{ this.renderBar() }
{ siteID && <QueryCurrentTheme siteId={ siteID }/> }
<ThanksModal
site={ this.props.selectedSite }
source={ 'details' }/>
{ this.state.showPreview && this.renderPreview() }
<HeaderCake className="theme__sheet-action-bar"
backHref={ this.props.backPath }
backText={ i18n.translate( 'All Themes' ) }>
{ this.renderButton() }
</HeaderCake>
<div className="theme__sheet-columns">
<div className="theme__sheet-column-left">
<div className="theme__sheet-content">
{ this.renderSectionNav( section ) }
{ this.renderSectionContent( section ) }
<div className="theme__sheet-footer-line"><Gridicon icon="my-sites" /></div>

<Head
title= { decodeEntities( title || '' ) + ' — WordPress.com' }
Copy link
Contributor

Choose a reason for hiding this comment

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

Please retain my TODO comment about using buildTitle somewhere nearby.

description={ decodeEntities( this.props.description || '' ) }
type={ 'website' }
canonicalUrl={ canonicalUrl }
image={ this.props.screenshot }
tier={ this.props.tier || 'all' }>
Copy link
Contributor

Choose a reason for hiding this comment

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

No need for this prop.

<Main className="theme__sheet">
<PageViewTracker path={ analyticsPath } title={ analyticsPageTitle }/>
{ this.renderBar() }
{ siteID && <QueryCurrentTheme siteId={ siteID }/> }
<ThanksModal
site={ this.props.selectedSite }
source={ 'details' }/>
{ this.state.showPreview && this.renderPreview() }
<HeaderCake className="theme__sheet-action-bar"
backHref={ this.props.backPath }
backText={ i18n.translate( 'All Themes' ) }>
{ this.renderButton() }
</HeaderCake>
<div className="theme__sheet-columns">
<div className="theme__sheet-column-left">
<div className="theme__sheet-content">
{ this.renderSectionNav( section ) }
{ this.renderSectionContent( section ) }
<div className="theme__sheet-footer-line"><Gridicon icon="my-sites" /></div>
</div>
</div>
<div className="theme__sheet-column-right">
{ this.renderScreenshot() }
</div>
</div>
<div className="theme__sheet-column-right">
{ this.renderScreenshot() }
</div>
</div>
</Main>
</Main>
</Head>
);
},

Expand Down
17 changes: 16 additions & 1 deletion client/my-sites/themes/controller.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
/**
* External Dependencies
*/
import React from 'react';
import i18n from 'i18n-calypso';
import omit from 'lodash/omit';

/**
* Internal Dependencies
Expand All @@ -12,7 +14,20 @@ import LoggedOutComponent from './logged-out';
import trackScrollPage from 'lib/track-scroll-page';
import buildTitle from 'lib/screen-title/utils';
import { getAnalyticsData } from './helpers';
import { makeElement } from 'my-sites/theme/controller';

function makeElement( ThemesComponent, Head, store, props ) {
return (
<Head
title={ props.title }
description={ props.description }
type={ 'website' }
canonicalUrl={ props.canonicalUrl }
image={ props.image }
tier={ props.tier || 'all' }>
<ThemesComponent { ...omit( props, [ 'title' ] ) } />
</Head>
);
}

function getProps( context ) {
const { tier, site_id: siteId } = context.params;
Expand Down
1 change: 1 addition & 0 deletions server/pragma-checker/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ var SSR_READY = '/** @ssr-ready **/';
var IGNORED_MODULES = [
'config', // Different modules on client & server
'lib/wp', // Different modules on client & server
'lib/formatting', // Different modules on client & server
'lib/analytics', // nooped on the server until we develop an isomorphic version
'lib/route', // nooped on the server until we can extract the isomorphic bits
'lib/upgrades/actions', // nooped on the server as it still uses the singleton Flux architecture
Expand Down