This content is likely not relevant anymore. Try searching or browse recent questions.
Google Custom Search Box doesn't appear on first load in my Gatsby project, only appears second load 1 Recommended Answer 9 Replies 1 Upvote
Goal:
when site is loaded it should have the search box together with menu items in the navigation bar.

Problem:
Currently on first load the google custom search box doesn't appear. However, when you reload/refresh the page, it will appear as normal and functions as normal. But this is annoying as people might not know I have the search box until they refresh or reload the page. This is what it appears like on first load.

I have tried:
According to google's instruction, I have done things like below: In my gatsby project's nav component,
import { Helmet } from "react-helmet"
... <Helmet>
<script async src="https://cse.google.com/cse.js?cx=123:456"></script>
</Helmet>
<nav className="nav" >
<div className="nav-container">
<Link to="/">Home</Link>
<Link to="/blog">All</Link>
<Link to="/tags/food">Food</Link>
<Link to="/tags/style">Style</Link>
<Link to="/tags/living">Living</Link>
<Link to="/tags/travel">Travel</Link>
<Link to="/about">About</Link>
<div className="gcse-search">
</div>
</div>
</nav>
{/* mobile only nav */}
<nav className="menu-mobile">
<div role="button" tabIndex={0} onClick={handleClick} onKeyDown={handleClick}>
<img src={menuIcon} className="hamburger-menu-icon" alt="hamburger menu icon" title="menu" />
</div>
<div className={isMobile}>
<Link to="/">Home</Link>
<Link to="/blog">All</Link>
<Link to="/tags/food">Food</Link>
<Link to="/tags/style">Style</Link>
<Link to="/tags/living">Living</Link>
<Link to="/tags/travel">Travel</Link>
<Link to="/about">About</Link>
<div className="gcse-search">
</div>
</div>
</nav>
</>
I did use devtool and saw there seems to be nothing loaded into the div where search box is supposed to appear. I have no idea why is that.
You can test the problem on website live here.
Question:
- Why is this happening?
- How can I debug and fix it?
This question is locked and replying has been disabled.
Link to post
Delete post?
This will remove the reply from the Answers section.
Notifications are off
Your notifications are currently off and you won't receive subscription updates. To turn them on, go to Notifications preferences on your Profile page.