From c7aceb5392df60c7816dc497dced093a696adc92 Mon Sep 17 00:00:00 2001 From: Alexey Taktarov Date: Tue, 25 Nov 2025 03:22:50 +0100 Subject: [PATCH] fix: resolve SSR hydration mismatch when ssrPath/ssrSearch not provided When rendering on the client without ssrPath/ssrSearch props, usePathname and useSearch now use location.pathname and location.search as the SSR snapshot instead of defaulting to empty strings. This ensures the client-side hydration matches what was rendered on the server. --- packages/wouter/src/use-browser-location.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/packages/wouter/src/use-browser-location.js b/packages/wouter/src/use-browser-location.js index 22ffb8ec..6d91a497 100644 --- a/packages/wouter/src/use-browser-location.js +++ b/packages/wouter/src/use-browser-location.js @@ -30,15 +30,18 @@ export const useLocationProperty = (fn, ssrFn) => const currentSearch = () => location.search; -export const useSearch = ({ ssrSearch = "" } = {}) => - useLocationProperty(currentSearch, () => ssrSearch); +export const useSearch = ({ ssrSearch } = {}) => + useLocationProperty( + currentSearch, + ssrSearch != null ? () => ssrSearch : currentSearch + ); const currentPathname = () => location.pathname; export const usePathname = ({ ssrPath } = {}) => useLocationProperty( currentPathname, - ssrPath ? () => ssrPath : currentPathname + ssrPath != null ? () => ssrPath : currentPathname ); const currentHistoryState = () => history.state;