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

fix: eliminate keyboard shortcuts UI flash #1021

Merged
merged 5 commits into from Jul 21, 2021

Conversation

chenxsan
Copy link
Contributor

There's a flash of unstyled content regarding the search box:

Screen.Recording.2021-07-16.at.7.28.47.PM.mov

You can check it on https://docsearch.algolia.com/

Setting a width would eliminate the problem, you can check it on https://webpack.js.org/ for how it looks.

@codesandbox-ci
Copy link

codesandbox-ci bot commented Jul 16, 2021

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 55b9e7a:

Sandbox Source
Vanilla Configuration

Copy link
Member

@shortcuts shortcuts left a comment

Choose a reason for hiding this comment

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

Thanks for your PR, It indeed looks better! Small comment, I think using min-width might be safer

packages/docsearch-css/src/button.css Outdated Show resolved Hide resolved
packages/docsearch-css/src/button.css Outdated Show resolved Hide resolved
Co-authored-by: Clément Vannicatte <20689156+shortcuts@users.noreply.github.com>
@@ -12,6 +12,7 @@
margin: 0 0 0 16px;
padding: 0 8px;
user-select: none;
min-width: 155px;
Copy link
Contributor

Choose a reason for hiding this comment

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

how do we know the value is 155px?

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 just inspected the element for the value:

CleanShot 2021-07-16 at 21 08 30@2x

Not a exact one, but it works in the webpack site case.

Copy link
Member

Choose a reason for hiding this comment

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

The computed size of the component loaded is 155.359px, I assume that's where @chenxsan also found it.

Copy link
Contributor

Choose a reason for hiding this comment

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

What if a different font, placeholder or zoom level is used? I guess it's still a safe default, but I think in some cases it will still flash

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 users could always customize it to their own use cases. We're just providing a default one which should hopefully eliminate the flash for most of the cases. For instance, the value would work for https://docusaurus.io/ as well.

Copy link
Member

Choose a reason for hiding this comment

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

What if a different font, placeholder or zoom level is used?

Most of these won't have effect unless the user is already overriding the provided styles. I think this could be a safe default and it is requested quite frequently.

wdyt? @Haroenv

Copy link
Member

Choose a reason for hiding this comment

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

It's safer with the min- change IMO.

But I agree with Haroen. I feel like setting the constraint on .DocSearch-Button-Keys is better because that's ultimately what we want as constant.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@francoischalifour I don't think it would work on .DocSearch-Button-Keys considering it's controlled by a state value

Copy link
Member

Choose a reason for hiding this comment

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

Ah right, we can still move that check one line below to always render that element though?

Copy link
Contributor Author

@chenxsan chenxsan Jul 21, 2021

Choose a reason for hiding this comment

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

Thanks for bringing up this as I found a problem with my solution.

Depending on the key state, we have two cases :

  1. a search box with the keys

CleanShot 2021-07-21 at 16 05 27@2x

  1. a search box without the keys

CleanShot 2021-07-21 at 16 05 07@2x

When there's no keys, the current solution would be deficient, as it results in a wide search box:
CleanShot 2021-07-21 at 16 10 17@2x

I'll see what I can do with it.

Haroenv
Haroenv previously approved these changes Jul 20, 2021
Copy link
Contributor

@Haroenv Haroenv left a comment

Choose a reason for hiding this comment

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

overall we rely on px too much, but this is a sensible default

@chenxsan chenxsan changed the title fix(css): set width for .DocSearch-Button fix(DocSearch): eliminate flash Jul 21, 2021
@Haroenv Haroenv dismissed their stale review July 21, 2021 11:54

code has changed

@chenxsan
Copy link
Contributor Author

chenxsan commented Jul 21, 2021

I've refactor the code as the former proposal won't cover all use cases, see #1021 (comment) for detail.

Screen.Recording.2021-07-21.at.8.07.24.PM.mov

I've also set up a demo here https://stackblitz.com/edit/nextjs-vxz1zj?file=pages%2Findex.js so you can check.

Let me know what you think about the new code.

@francoischalifour
Copy link
Member

francoischalifour commented Jul 21, 2021

@chenxsan Unfortunately we cannot change the DocSearchButton API since it's public API (and therefore will break the Docusaurus implementation). However we can still use your strategy but move the lazy state evaluation in the DocSearchButton component.

@chenxsan
Copy link
Contributor Author

@francoischalifour You are right! I didn't notice it's public API. I've updated the code.

Copy link
Member

@francoischalifour francoischalifour left a comment

Choose a reason for hiding this comment

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

Much simpler now, thank you @chenxsan!

@francoischalifour francoischalifour changed the title fix(DocSearch): eliminate flash fix: eliminate keyboard shortcuts UI flash Jul 21, 2021
@francoischalifour francoischalifour merged commit c8e0c27 into algolia:next Jul 21, 2021
@chenxsan chenxsan deleted the patch-1 branch July 21, 2021 15:06
@chenxsan
Copy link
Contributor Author

@francoischalifour @shortcuts Unfortunately it doesn't fix the flashing problem. I've filed a pull request on webpack documentation here webpack/webpack.js.org#5224, and here's the preview url https://webpack-js-org-git-fork-chenxsan-upgrade-do-a4186d-webpack-docs.vercel.app/, you can compare it with https://webpack.js.org/ which has the width set for the search box.

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

4 participants