Skip to content

[DCV-4208] Fix the React hydration error from the navbar search button, build with Node 22 - #88

Merged
noel merged 4 commits into
mainfrom
DCV-4208-search-hydration-error
Dec 4, 2026
Merged

noel merged 4 commits into
mainfrom
DCV-4208-search-hydration-error

Conversation

@gams87

@gams87 gams87 commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

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-local 0.0.0, unpublished since 2022) worked out the ⌘ / Ctrl hint in a useMemo during render. At build time there is no navigator, 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 a useEffect, after hydration. This is the only behavior change.
  • SearchBar.jsx: a copy, needed only because the plugin imports ./SearchButton relatively. 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.yml and test-deploy.yml now build with Node 22 instead of 18, which reached end of life in April 2025. Node 21+ defines a global navigator during the build (as noted in review), so I checked that it doesn't change the output:

  • npm ci and npm run build pass on Node 22.
  • All 182 generated pages are identical to a build without a global navigator (Node 20), apart from asset hashes.
  • The Playwright checks below pass on the Node 22 build too.

Node 24 builds the same way, but its npm 11 warns that the install scripts of core-js, core-js-pure, husky and nodejieba aren't covered by allowScripts. 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 an allowScripts entry for nodejieba, 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 of main:

  • No console errors on /, /docs/how-tos/dbt/compilation-errors, /docs/how-tos/airflow/use-azure-key-vault and /docs/category/getting-started. On main all four log #418.
  • The navbar shows ⌘K on Apple devices and the Ctrl key elsewhere.
  • The search button opens the modal and returns results.
  • Cmd/Ctrl+K opens the search and Escape closes it.

Checklist

  • [Mandatory] My pull request represents one logical piece of work and my commits are related and look clean.

🤖 Generated with Claude Code

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>
@gams87
gams87 requested a review from fmercadop November 26, 2026 15:00
@noel

noel commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

@fmercadop can you run this test

@fmercadop

Copy link
Copy Markdown
Contributor

Tested locally with production-like builds of this branch and main, on Mac and with the platform set to Windows:

  • main logs React error #418 on every page. This branch logs no errors.
  • The search button shows ⌘K on Mac and Ctrl K on Windows.
  • Search works: the button and Cmd/Ctrl+K open the modal, results show up, and Escape closes it.

Looks good to me.

@gams87 Note: the deploy builds with Node 18, which has no navigator, so every visitor gets the error. Node 21+ has a global navigator, so a local build on a Mac with a newer Node only shows the error in a Windows browser.

@fmercadop fmercadop assigned gams87 and unassigned noel Nov 26, 2026
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>
@gams87 gams87 changed the title [DCV-4208] Fix the React hydration error from the navbar search button [DCV-4208] Fix the React hydration error from the navbar search button, build with Node 22 Nov 26, 2026
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>
@gams87 gams87 changed the title [DCV-4208] Fix the React hydration error from the navbar search button, build with Node 22 [DCV-4208] Fix the React hydration error from the navbar search button, build with Node 24 Nov 26, 2026
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>
@gams87 gams87 changed the title [DCV-4208] Fix the React hydration error from the navbar search button, build with Node 24 [DCV-4208] Fix the React hydration error from the navbar search button, build with Node 22 Nov 26, 2026
@gams87

gams87 commented Nov 26, 2026

Copy link
Copy Markdown
Contributor Author

@fmercadop thanks for testing! After your review I added one more change: CI now builds with Node 22 instead of 18 (deploy.yml and test-deploy.yml; the three Node commits squash into one on merge).

Following your note about Node 21+ having a global navigator, I checked that it doesn't change the server render: all 182 generated pages are identical to a build without navigator (Node 20), apart from asset hashes, and the search checks pass on the Node 22 build. Test deployment passed on Node 22 too.

I tried Node 24 first, but its npm 11 warns about install scripts not covered by allowScripts (including nodejieba, the search plugin's native dependency), so I kept 22 for now. It's supported until April 2027, and moving to 24 can be a follow-up.

Since merging deploys to production, could you take a quick look at the Node change before we merge?

@fmercadop

Copy link
Copy Markdown
Contributor

Tested the Node 22 change: built this branch in a node:22 container (same Node version as CI). npm ci and the build pass, and the pages match a build without navigator. No #418 errors, ⌘K / Ctrl K show correctly, and search works.

@noel
noel merged commit 147d3c1 into main Dec 4, 2026
2 checks passed
@noel
noel deleted the DCV-4208-search-hydration-error branch December 4, 2026 02:06
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.

3 participants