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

Search: i18nify the component #46825

Merged
merged 5 commits into from
Dec 24, 2020
Merged

Conversation

sarayourfriend
Copy link
Contributor

@sarayourfriend sarayourfriend commented Oct 27, 2020

Changes proposed in this Pull Request

  • Use withI18n rather than using wp/i18n directly. Aligns with how we're doing things in the LanguagePicker component.

Testing instructions

  • Run the storybook and ensure the component still renders and works correctly
  • Use the language picker in Calypso at /me/account and ensure search still behaves as expected on desktop and mobile

Fixes #

@matticbot
Copy link
Contributor

@matticbot matticbot added the [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. label Oct 27, 2020
@sarayourfriend sarayourfriend self-assigned this Oct 27, 2020
@matticbot
Copy link
Contributor

matticbot commented Oct 28, 2020

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

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

name                 parsed_size           gzip_size
entry-gutenboarding       +507 B  (+0.0%)     +167 B  (+0.0%)
entry-main                +282 B  (+0.0%)     +101 B  (+0.0%)

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

Sections (~168 bytes added 📈 [gzipped])

name         parsed_size           gzip_size
woocommerce       +225 B  (+0.0%)      +50 B  (+0.0%)
settings          +225 B  (+0.0%)      +52 B  (+0.0%)
account           +225 B  (+0.0%)      +66 B  (+0.0%)

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 (~244 bytes added 📈 [gzipped])

name                                parsed_size           gzip_size
async-load-quick-language-switcher       +225 B  (+0.2%)      +66 B  (+0.2%)
async-load-design-playground             +225 B  (+0.0%)      +57 B  (+0.0%)
async-load-design-blocks                 +225 B  (+0.0%)      +60 B  (+0.0%)
async-load-design                        +225 B  (+0.0%)      +61 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.

Copy link
Collaborator

@wp-desktop wp-desktop left a comment

Choose a reason for hiding this comment

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

WordPress Desktop CI Failure for job "wp-desktop-mac".

@saramarcondes please inspect this job's build steps for breaking changes at this link. For temporal failures, you may try to "Rerun Workflow from Failed".

Please also ensure this branch is rebased off latest Calypso.

Copy link
Member

@tyxla tyxla left a comment

Choose a reason for hiding this comment

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

Hey @saramarcondes is this ready for review or are you still working on it?

@@ -310,7 +311,7 @@ class Search extends React.Component< Props, State > {

render() {
const searchValue = this.state.keyword;
const placeholder = this.props.placeholder || __( 'Search…' );
const placeholder = this.props.placeholder || this.props.__( 'Search…', __i18n_text_domain__ );
Copy link
Member

Choose a reason for hiding this comment

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

I was wondering why we need the textdomain argument now.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think we need it in case the search component is used outside of the default context. And in this case we're receiving __ from withI18n so we need to still supply a context, right?

@sarayourfriend sarayourfriend marked this pull request as ready for review October 29, 2020 18:19
@wp-desktop wp-desktop dismissed their stale review October 29, 2020 18:22

wp-desktop ci passing, closing review

Copy link
Member

@tyxla tyxla left a comment

Choose a reason for hiding this comment

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

I seem to be getting an error when trying to start search's storybook:

Any idea what might be going on?

@sarayourfriend
Copy link
Contributor Author

@tyxla I'm having the same issue. I have no idea why that is happening 🤔 Maybe @scinos could help?

@tyxla
Copy link
Member

tyxla commented Nov 3, 2020

Maybe we need to add ts-loader and react-docgen-typescript-loader as dependencies, too?

@sarayourfriend
Copy link
Contributor Author

sarayourfriend commented Nov 3, 2020

I'll try that but storybook worked before these changes, why should we need new dependencies based on these changes? 🤔

By the way, where did react-docgen-typescript-loader come from? I'm not seeing that in the error at all.

@tyxla
Copy link
Member

tyxla commented Nov 4, 2020

I'll try that but storybook worked before these changes, why should we need new dependencies based on these changes? 🤔

Not sure, perhaps another dependency or peer dependency that was updated needs those. Or we changed something with our TS config along the way. But the fact that storybook doesn't work for components package either means that it's not related to any of the component work done here.

By the way, where did react-docgen-typescript-loader come from? I'm not seeing that in the error at all.

I saw an error message that it's missing when I added ts-loader as dependency. I didn't go any further, but wanted to point that out.

@tyxla
Copy link
Member

tyxla commented Nov 4, 2020

I've tinkered with fixing storybook in #47098

@tyxla
Copy link
Member

tyxla commented Nov 6, 2020

Storybook builds, but I'm getting an error when opening the example in the browser 😬 :

@tyxla
Copy link
Member

tyxla commented Nov 6, 2020

Is it possible this is something coming from the withI18n HoC?

@sarayourfriend
Copy link
Contributor Author

@tyxla yes. This is the same issue we ran into with the LanguagePicker which led me to delete the storybook sigh. is-shallow-equal is for whatever reason not compatible with Storybook's build process.

@tyxla
Copy link
Member

tyxla commented Nov 9, 2020

@tyxla yes. This is the same issue we ran into with the LanguagePicker which led me to delete the storybook sigh. is-shallow-equal is for whatever reason not compatible with Storybook's build process.

Is this because @wordpress/is-shallow-equal uses CJS module.export? Can this be fixed if we change those to ESM there? Do you know if there's a specific reason why we're using CJS in @wordpress/is-shallow-equal? cc @sirreal

@sirreal
Copy link
Member

sirreal commented Nov 9, 2020

is-shallow-equal doesn't require build or compilation. Its source is designed to be used via node or bundled for the browser without modification. There's some conversation about that here: WordPress/gutenberg#18942 (comment)

I'm sure Gutenberg would be open to revisiting that decision especially as ES Modules mature (specifically in node).

@tyxla
Copy link
Member

tyxla commented Nov 9, 2020

is-shallow-equal doesn't require build or compilation. Its source is designed to be used via node or bundled for the browser without modification. There's some conversation about that here: WordPress/gutenberg#18942 (comment)

That makes sense, thanks for the context @sirreal 🙌

I'm sure Gutenberg would be open to revisiting that decision especially as ES Modules mature (specifically in node).

That would be an interesting avenue to explore, @saramarcondes.

Alternatively, we could update react-i18n to manually create the withI18n HoC instead of using createHigherOrderComponent() from @wordpress/compose, which seems to be what needs is-shallow-equal right now.

@sarayourfriend
Copy link
Contributor Author

@tyxla and @sirreal Thanks for the suggestions and information. I've opened a PR here (WordPress/gutenberg#26833) to convert is-shallow-equal to ESM.

@sarayourfriend sarayourfriend changed the base branch from master to trunk November 20, 2020 16:11
@sarayourfriend
Copy link
Contributor Author

@tyxla Any chance you could re-review this? Thanks!

Copy link
Member

@tyxla tyxla left a comment

Choose a reason for hiding this comment

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

Storybook builds now, but I'm getting this error when trying to run it in the browser:

Furthermore, the @automattic/search package is now used in the language picker. Perhaps this PR needs to be rebased, and test instructions expanded to account for that usage?

Copy link
Member

@tyxla tyxla left a comment

Choose a reason for hiding this comment

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

Looks good and works well 👍 (noting that I rebased it locally before testing)

@sarayourfriend sarayourfriend merged commit 8909f2e into trunk Dec 24, 2020
@sarayourfriend sarayourfriend deleted the add/i18nify-search-component branch December 24, 2020 16:01
@matticbot matticbot removed the [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. label Dec 24, 2020
@tjcafferkey tjcafferkey mentioned this pull request Jan 6, 2021
23 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants