Skip to content

Disable Search Box if CDN is down (#9) #186

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

Merged
merged 4 commits into from
Oct 20, 2017
Merged

Conversation

SadPandaBear
Copy link
Contributor

@SadPandaBear SadPandaBear commented Oct 19, 2017

Should help fixing #9 and be a potentially help for #14.

@facebook-github-bot
Copy link
Collaborator

Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. In order for us to review and merge your code, please sign up at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need the corporate CLA signed.

If you have received this in error or have any questions, please contact us at [email protected]. Thanks!

@reactjs-bot
Copy link

reactjs-bot commented Oct 19, 2017

Deploy preview ready!

Built with commit 1d1656c

https://deploy-preview-186--reactjs.netlify.com

@facebook-github-bot
Copy link
Collaborator

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks!

@@ -13,6 +13,7 @@ import React from 'react';
import {colors, fonts, media} from 'theme';
import {version} from 'site-constants';
import ExternalLinkSvg from 'templates/components/ExternalLinkSvg';
import DocSearch from 'components/DocSearch';
Copy link
Contributor

Choose a reason for hiding this comment

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

Organizational nit: This new DocSearch component can just live within the src/components/LayoutHeader folder since it's only referenced there.

Particularly since there are styles defined on the DocSearch component (eg flex: '0 0 auto') that are dependent on its parent.

componentDidMount() {
// Initialize Algolia search.
// TODO Is this expensive? Should it be deferred until a user is about to search?
// eslint-disable-next-line no-undef
Copy link
Contributor

Choose a reason for hiding this comment

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

Might be nice but might also be unnecessary. Feel free to leave it for a follow-up, or if you're interested in maybe doing it- measure the perf first to see if it's actually worth doing?

Copy link
Contributor Author

@SadPandaBear SadPandaBear Oct 19, 2017

Choose a reason for hiding this comment

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

Maybe not, I just thought of removing all that complexity from the Template component and just let the DocSearch do everything, mostly because of its own setState behavior.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, I think moving the initialization here makes sense. 👍

I'm not sure we need to defer the initialization until it's used though. (I actually tried it locally really quick to see if it was simple to just defer until the first "focus" event, but it didn't work without a double click and I don't see any mention to a complete-callback in Algolia's docs so... 😄

}

render() {
const {disabled} = this.state;
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 we should just render null if search is unavailable. That's less confusing than a disabled search input I think. What do you think?

Copy link
Contributor Author

@SadPandaBear SadPandaBear Oct 19, 2017

Choose a reason for hiding this comment

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

Oh, sorry, I thought you meant to disable the input when you said "3. Render the component in a disabled state if so". 😥 😃

Copy link
Contributor

Choose a reason for hiding this comment

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

No worries at all. I was originally thinking the same, but then I tried this out and thought it might be better just to not show the input at all 😁

inputSelector: '#algolia-doc-search',
});
} else {
this.setState({disabled: true});
Copy link
Contributor

Choose a reason for hiding this comment

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

Might be nice to add a console.warn that search failed to load and so it's being disabled.

@SadPandaBear
Copy link
Contributor Author

SadPandaBear commented Oct 19, 2017

Turns out this PR is more related to #9, since #14 is still happening.

@bvaughn
Copy link
Contributor

bvaughn commented Oct 19, 2017

since #14 is still happening.

What's the error / stack trace you're seeing in the console after these changes have been made?

@SadPandaBear
Copy link
Contributor Author

What's the error / stack trace you're seeing in the console after these changes have been made?

The same from before:

screenshot_1

@bvaughn
Copy link
Contributor

bvaughn commented Oct 19, 2017

Ah, I see. I thought before that you were getting an error about docsearch being undefined but I see that was actually reported by another person.

@SadPandaBear
Copy link
Contributor Author

SadPandaBear commented Oct 19, 2017

Turning the Cookie button "On" works for me, (which is bizarre since #14 is related to enabling it).

I'm not sure if it helps, but it's good to consider that Cookie Whitelist is actually a Legacy add-on:

screenshot_1

@SadPandaBear
Copy link
Contributor Author

I'm changing the PR name to point to #9.

@SadPandaBear SadPandaBear changed the title Disable Search Box if CDN is down (#14, #9) Disable Search Box if CDN is down (#9) Oct 19, 2017
Copy link
Contributor

@bvaughn bvaughn left a comment

Choose a reason for hiding this comment

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

Cool. This is a nice improvement. Thanks 👍

@bvaughn bvaughn merged commit d370d00 into reactjs:master Oct 20, 2017
jhonmike pushed a commit to jhonmike/reactjs.org that referenced this pull request Jul 1, 2020
BetterZxx pushed a commit to BetterZxx/react.dev that referenced this pull request Mar 21, 2023
In English:
For example, this code will not behave as you might expect because** 0 will be printed **when props.messages is an empty array:

是 ** 0会被渲染  ** 而不是 ~~<MessageList />会被渲染~~
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.

4 participants