Repository navigation
[DCV-4208] Fix the React hydration error from the navbar search button, build with Node 22 - #88
Conversation
docusaurus-search-local's SearchButton worked out the ⌘ / Ctrl hint in a useMemo during render: null on the server (no navigator), the key on the client's first render. React threw #418 on every page. Shadow SearchBar and SearchButton in src/theme and set the key after mount instead. SearchBar is copied only because it imports ./SearchButton relatively; apart from import paths it is unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
@fmercadop can you run this test |
|
Tested locally with production-like builds of this branch and
Looks good to me. @gams87 Note: the deploy builds with Node 18, which has no |
Node 18 reached end of life in April 2025. Node 22 is the LTS line the site was checked against: npm ci and npm run build pass, and all 182 generated pages match a build without a global navigator (Node 20), so Node 21+'s navigator changes nothing in the server render. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Node 24 is the active LTS line; 22 is in maintenance until April 2027. Checked the same way: npm ci and npm run build pass, and all 182 generated pages match a build without a global navigator (Node 20). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
npm 11, bundled with Node 24, warns that the install scripts of core-js, core-js-pure, husky and nodejieba aren't covered by allowScripts. They still run, but if npm starts enforcing it, nodejieba (the search plugin's native dependency) won't build. Node 22 (npm 10) has no such warning and is supported until April 2027; moving to 24 can come with an allowScripts entry for nodejieba. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
@fmercadop thanks for testing! After your review I added one more change: CI now builds with Node 22 instead of 18 ( Following your note about Node 21+ having a global I tried Node 24 first, but its npm 11 warns about install scripts not covered by Since merging deploys to production, could you take a quick look at the Node change before we merge? |
|
Tested the Node 22 change: built this branch in a |
Summary
Every page of the docs logged
Minified React error #418(a hydration mismatch) on load. React recovered on its own, so readers saw nothing broken, but the console showed an error on every page and React re-rendered that part of the page on load.Cause: the search plugin's
SearchButton(docusaurus-search-local0.0.0, unpublished since 2022) worked out the ⌘ / Ctrl hint in auseMemoduring render. At build time there is nonavigator, so the HTML had an empty<span class="DocSearch-Button-Keys">. In the browser the first render already added the ⌘ and K keys, so the DOM didn't match.Fix: shadow the component in
src/theme/SearchBar/:SearchButton.jsx: sets the key in auseEffect, after hydration. This is the only behavior change.SearchBar.jsx: a copy, needed only because the plugin imports./SearchButtonrelatively. Apart from import paths it is unchanged.index.js: the entry point.The search modal, its index loading and its styles still come from the plugin. The copied files keep the plugin's MIT notice.
Node 22 in CI
deploy.ymlandtest-deploy.ymlnow build with Node 22 instead of 18, which reached end of life in April 2025. Node 21+ defines a globalnavigatorduring the build (as noted in review), so I checked that it doesn't change the output:npm ciandnpm run buildpass on Node 22.navigator(Node 20), apart from asset hashes.Node 24 builds the same way, but its npm 11 warns that the install scripts of
core-js,core-js-pure,huskyandnodejiebaaren't covered byallowScripts. If npm starts enforcing that,nodejieba(the search plugin's native dependency) won't build. Node 22 is supported until April 2027, so moving to 24, together with anallowScriptsentry fornodejieba, can be a follow-up.Jira: DCV-4208
Testing
Ran Playwright against local production builds (
npm run build) of this branch, on Node 20 and on Node 22, and ofmain:/,/docs/how-tos/dbt/compilation-errors,/docs/how-tos/airflow/use-azure-key-vaultand/docs/category/getting-started. Onmainall four log #418.Checklist
🤖 Generated with Claude Code