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 an optional prop to DocumentHead to set the raw window title #41803

Merged
merged 12 commits into from
Jun 9, 2020

Conversation

DanReyLop
Copy link
Contributor

Changes proposed in this Pull Request

The <DocumentHead> component has a title prop, to set the tab title in the browser (document.title). However, on top of whatever title is passed, it applies some extra formatting. For example, passing Hello World as a title can result in a window title being Hello World - WordPress.com (3).

This PR adds a new optional prop, formattedTitle. If present, that string will be used as the raw window title, without any additions.

It also adds an optional pageTitle prop to the JetpackConnectMainWrapper component, that makes use of that prop.

How to test

There's no code that calls JetpackConnectMainWrapper with a pageTitle prop, or DocumentHead with a formattedTitle prop, so there's no way to test this.

Note: This is a required refactor for the new "Woo DNA" flow, implemented in #41798

@DanReyLop DanReyLop added the [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. label May 5, 2020
@DanReyLop DanReyLop requested a review from a team May 5, 2020 13:03
@matticbot
Copy link
Contributor

@matticbot
Copy link
Contributor

matticbot commented May 5, 2020

Here is how your PR affects size of JS and CSS bundles shipped to the user's browser:

App Entrypoints (~6 bytes added 📈 [gzipped])

name         parsed_size           gzip_size
entry-login        +58 B  (+0.0%)      +10 B  (+0.0%)
entry-main         +17 B  (+0.0%)       -4 B  (-0.0%)

Common code that is always downloaded and parsed every time the app is loaded, no matter which route is used.

Sections (~159 bytes added 📈 [gzipped])

name             parsed_size           gzip_size
jetpack-connect       +286 B  (+0.1%)     +113 B  (+0.1%)
accept-invite         +166 B  (+0.1%)      +46 B  (+0.1%)

Sections contain code specific for a given set of routes. Is downloaded and parsed only when a particular route is navigated to.

Async-loaded Components (~49 bytes added 📈 [gzipped])

name                          parsed_size           gzip_size
async-load-signup-steps-user       +166 B  (+0.1%)      +46 B  (+0.1%)
async-load-design-blocks            +41 B  (+0.0%)       +3 B  (+0.0%)

React components that are loaded lazily, when a certain part of UI is displayed for the first time.

Legend

What is parsed and gzip size?

Parsed Size: Uncompressed size of the JS and CSS files. This much code needs to be parsed and stored in memory.
Gzip Size: Compressed size of the JS and CSS files. This much data needs to be downloaded over network.

Generated by performance advisor bot at iscalypsofastyet.com.

@@ -81,6 +81,7 @@ class DocumentHead extends Component {

DocumentHead.propTypes = {
title: TranslatableString,
formattedTitle: TranslatableString,
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it may be worth adding this to the existing list of props within the documentation: https://github.com/Automattic/wp-calypso/blob/master/client/components/data/document-head/README.md

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch, I missed that! Done in 5751f65

@DanReyLop DanReyLop force-pushed the woodna/document-title-override branch from 5751f65 to 94ce4c2 Compare May 5, 2020 15:34
Copy link
Contributor

@vbelolapotkov vbelolapotkov 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 @DanReyLop for that refactoring! Changes look good and fine to be merged like this.
However, to be honest, having two competing title props slightly bothers me. What do you think on having a single title prop and a flag, e.g. skipTitleFormatting or titleIsFormatted. This way IMO it's more explicit that title is always a title and flag emphasizes desired behavior. What do you think?

@vbelolapotkov vbelolapotkov added [Status] Needs Author Reply and removed [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. labels Jun 2, 2020
@DanReyLop DanReyLop added [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. and removed [Status] Needs Author Reply labels Jun 8, 2020
@DanReyLop
Copy link
Contributor Author

@vbelolapotkov I implemented your suggestion in 383c41a

I also rebased & force-pushed all the branches that are on top of this one, so woodna/woodna-flow has all the changes included.

@DanReyLop DanReyLop force-pushed the woodna/document-title-override branch from 383c41a to e49a4dd Compare June 8, 2020 12:04
@DanReyLop DanReyLop requested review from oandregal and a team as code owners June 8, 2020 12:04
@DanReyLop DanReyLop requested review from a team as code owners June 8, 2020 12:04
@matticbot
Copy link
Contributor

Caution: This PR affects files in the FSE Plugin on WordPress.com
Please ensure your changes work on WordPress.com before merging.

D44535-code has been created so you can easily test it on your sandbox. See this FieldGuide page about developing in the FSE Plugin for more info: PCYsg-ly5-p2

<DocumentHead title={ translate( 'Jetpack Connect' ) } />
<DocumentHead
title={ pageTitle || translate( 'Jetpack Connect' ) }
skipTitleFormatting={ Boolean( pageTitle ) }
Copy link
Member

Choose a reason for hiding this comment

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

Just to verify: the fallback title, when pageTitle prop is not supplied, is supposed to be formatted? E.g., Jetpack Connect --- WordPress.com (6)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, that's the existing behaviour.

Copy link
Contributor

@vbelolapotkov vbelolapotkov left a comment

Choose a reason for hiding this comment

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

LGTM! Thank you @DanReyLop !

@vbelolapotkov vbelolapotkov 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 Jun 8, 2020
Copy link
Member

@jsnajdr jsnajdr left a comment

Choose a reason for hiding this comment

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

Nice! I also like the skipTitleFormatting API better than the original "raw title" one.

@DanReyLop DanReyLop removed request for a team and oandregal June 8, 2020 20:54
Base automatically changed from woodna/login-url-builder to master June 9, 2020 22:05
@DanReyLop DanReyLop merged commit 81dff78 into master Jun 9, 2020
@DanReyLop DanReyLop deleted the woodna/document-title-override branch June 9, 2020 22:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants