-
Notifications
You must be signed in to change notification settings - Fork 2k
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
SSR: Use document-head to populate title
, meta
s, and link
s; drop Helmet
#7600
Conversation
@@ -348,46 +348,58 @@ const ThemeSheet = React.createClass( { | |||
const analyticsPageTitle = `Themes > Details Sheet${ section ? ' > ' + titlecase( section ) : '' }${ siteID ? ' > Site' : '' }`; | |||
|
|||
const { name: themeName, description } = this.props; | |||
const title = i18n.translate( '%(themeName)s Theme', { | |||
const title = themeName && i18n.translate( '%(themeName)s Theme', { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What was the reason for the themeName &&
change? This won't prevent the <DocumentHead />
from dispatching the title, will it?
Per:
wp-calypso/client/components/data/document-head/index.jsx
Lines 29 to 31 in 9923003
if ( 'title' in this.props ) { | |
this.props.setTitle( title ); | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What was the reason for the
themeName &&
change?
Basically to retain logic that was previously here.
Looking forward to this 🎉 |
9407ab7
to
8bccbf2
Compare
033a4b0
to
0a7221d
Compare
return ( | ||
<Main className="themes"> | ||
<DocumentHead title={ themesMeta[ tier ].title } metas={ metas } /> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The prop for metas is meta
, not metas
.
* @param {Object} state Global state tree | ||
* @return {Object[]} Array of meta objects | ||
*/ | ||
export function getMeta( state ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, in the context of global selectors, should they come to reality, would getMeta
be sufficiently unique? Seems less so than getTitle
, though a similar argument could be made there.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, I'll rename them to be in line with the setters (i.e. actions).
const title = getFormattedTitle( context.store.getState() ); | ||
const metas = getMeta( context.store.getState() ); | ||
const links = getLink( context.store.getState() ); | ||
context.head = { title, metas, links }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We wrap this in context.store
condition, but the Jade template assumes head.title
will always exist. Do we need to be safer there too? Or remove the context.store
check?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can't just remove the context.store
check or context.store.getState()
might fail. Fixing this with f7ffb39 by falling back to undefined
attrs.
Okay, addressed feedback, including renaming of all selectors. Some have pretty long names now... |
@@ -19,7 +21,7 @@ const UNREAD_COUNT_CAP = 40; | |||
* @param {Object} state Global state tree | |||
* @return {?String} Document title | |||
*/ | |||
export function getTitle( state ) { | |||
export function getDocumentHeadTitle( state ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
client/reader/full-post/controller.js
still imports as getTitle
in this branch.
context.initialReduxState = pick( context.store.getState(), 'documentHead', 'ui', 'themes' ); | ||
} | ||
|
||
context.head = { title, metas, links }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do the defaults and context.head
assignment need to be outside of the config
/ context.user
condition block too to ensure it's always set?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good call. This might've gone unnoticed in testing since the feature flag is on in all environments, and context.user
is notoriously unset on the server in development
.
Description meta can be handled by just using addMeta, so I don't think it's worthwhile having specialized functions around.
…[Capped]UnreadCount
This PR:
DocumentHead
instead ofHead
(which was a rather specialized component tailored to the theme showcase's SEO needs, based on `react-helmet``Head
, and thereact-helmet
dependencyserver/render
to use data from thedocument-head
state to populate SEO relevant fields (title
,meta
,link
) for SSRdescription
related reducer and actions.addMeta
, so I don't think it's worthwhile having specialized functions around.To test:
title
,meta
,link
). (Compare withmaster
orproduction
.)TODO (separate PR):
title
et al for/design
(this isn't currently done onmaster
, so not a regression)Fixes #3795
Test live: https://calypso.live/?branch=remove/head