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

SearchControl: refactor to use InputControl internally #56524

Merged
merged 36 commits into from
Feb 8, 2024

Conversation

ciampo
Copy link
Contributor

@ciampo ciampo commented Nov 25, 2023

Part of #56388

What?

Changes the implementation of the SearchControl so that it uses InputControl internally.

The size variants, which were 48px (default), 40px (next default), and 32px (compact); are now just 40px (default) and 32px (compact).

Why?

To improve cohesion across the app, as discussed in #56388.

Testing Instructions

See Storybook stories for SearchControl.

Please review consumer changes in #58014, which is stacked onto this PR.

Screenshots or screencast

Before After
Old search control New search control

Copy link

Flaky tests detected in 0cbc074.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/6985950363
📝 Reported issues:

@jameskoster
Copy link
Contributor

Hey @ciampo do you have any plans to pick this back up? It would be very handy for the data views work. Let me know if I can help at all.

@ciampo
Copy link
Contributor Author

ciampo commented Dec 12, 2023

Apologies for not making much progress here, I've been busy with other tasks. I'll try to look into it soon (or ask for help otherwise)!

@mirka mirka self-assigned this Dec 20, 2023
@mirka
Copy link
Member

mirka commented Feb 6, 2024

After discussing with the design team, we won't be doing any design changes at this time (9c18f1e). I've made some adjustments so the "borderless gray" input can be achieved in a sustainable way (e91440c).

On hold until #58750 lands, so we can do the borderless here.

@ciampo
Copy link
Contributor Author

ciampo commented Feb 7, 2024

Sounds good. Will test again once changes from #58750 are integrated

Comment on lines 68 to 70
// @ts-expect-error The `disabled` prop is not yet supported in the SearchControl component.
// Work with the design team if you need this feature.
delete restProps.disabled;
Copy link
Member

Choose a reason for hiding this comment

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

I added this little safe guard so consumers don't improvise a disabled variant of the SearchControl. Currently, the light gray background of the search box is exactly the same color as a disabled InputControl, so we're going to need some coordinated design work if anyone ever needs a disabled search box.

@mirka
Copy link
Member

mirka commented Feb 7, 2024

Everything is now up to date and working. The screenshot in the PR description is also updated 👍

@mirka mirka requested review from tyxla and t-hamano February 8, 2024 12:24
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.

Tests well and looks good 👍

I think it's worth adding as an Internal entry in the CHANGELOG.

🚀

className
) }
onChange={ ( nextValue?: string ) =>
onChange( nextValue ?? '' )
Copy link
Member

Choose a reason for hiding this comment

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

Nit: sometimes we can see value || '' and sometimes value ?? ''. While for a normal input control, there shouldn't be a big difference, perhaps we can make these consistent.

Copy link
Member

Choose a reason for hiding this comment

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

Good idea, I'll unify to ?? since they're closer to the intent. The only value that it would affect here is an empty string, and since we're falling back to an empty string it shouldn't change the outcome. 62b49c0

);
}
// @ts-expect-error The `disabled` prop is not yet supported in the SearchControl component.
// Work with the design team if you need this feature.
Copy link
Member

Choose a reason for hiding this comment

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

Maybe we should mention the team handle? @WordPress/gutenberg-design?

Copy link
Member

Choose a reason for hiding this comment

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

Nice 👍 5247c85

@ciampo ciampo requested a review from ellatrix as a code owner February 8, 2024 22:22
@mirka mirka merged commit 8fe2508 into trunk Feb 8, 2024
59 checks passed
@mirka mirka deleted the refactor/search-control-input-control branch February 8, 2024 23:39
@github-actions github-actions bot added this to the Gutenberg 17.7 milestone Feb 8, 2024
@youknowriad
Copy link
Contributor

While I can't say for sure 100%, I think this PR impacted the "inserter open" performance metric negatively (I'd say around 6 or 7%). Would be cool to try to debug a bit.

@youknowriad
Copy link
Contributor

Inserter search is impacted as well.

For clarity, we have a gap of 24h where the performance tests were not working, so we can't pin point exactly which commit introduced the regression by looking at the graphs https://www.codevitals.run/project/gutenberg

I tried looking at the commits and this one is the most suspicious for me (looking at the PR performance job, it seems to confirm, although a single performance job run is not sufficient to judge entirely)

@mirka
Copy link
Member

mirka commented Feb 10, 2024

A little bit of performance hit is expected, since we replaced a native input with an InputControl, which simply processes more JS code. It looks like we're adding 1–2 ms to the inserter metrics, which if I were to guess is mostly the difference between input and InputControl.

@youknowriad
Copy link
Contributor

youknowriad commented Feb 10, 2024

For me, That percentage in the increase is too much for a single component added to the react tree. If we had that performance loss everytime we add a new component to the react tree of the inserter, I think we'll be in a very bad position. Just imagine the number of components we have in the inserter. If one of them is responsible of 7% (something like 12ms or something like that in the graph) that seems like a component that we should investigate

@tyxla
Copy link
Member

tyxla commented Feb 12, 2024

Agreed that we should be mindful of performance. I wonder if this is something we can pinpoint, be it in InputControl or the underlying components. Could be a good idea to do some measurements in isolation and see if something will stand out.

@mirka
Copy link
Member

mirka commented Feb 12, 2024

I've been doing some isolated perf testing on the components, benchmarking InputControl against TextControl (which is significantly simpler and about 30–40% more performant). Initial experimentation seems to show that the main drag is Emotion, or at least the specific way we use it to add dynamic prop-based styles. I'll see what I can do.

@mirka
Copy link
Member

mirka commented Feb 13, 2024

I summarized my findings and next steps here.

When we do start migrating, we can start with InputControl since it is widely used, and hopefully we'll be able to validate the gains through Code Vitals.

@youknowriad
Copy link
Contributor

Thanks for diving into this @mirka I appreciate it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Package] Components /packages/components [Type] Enhancement A suggestion for improvement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants