Issue
After upgrading from v3.7.1 to v3.8.0, our SSR (pre-rendering) started failing with ReferenceError: location is not defined in Node.js environment.
I'd like to understand if this is expected behavior or a regression.
To Reproduce
- Use wouter v3.8.0
- Pre-render a page that uses
useSearch or useSearchParams in Node.js
- Error:
ReferenceError: location is not defined
// prerender.tsx (Node.js)
import { renderToString } from "react-dom/server";
import { Router } from "wouter";
const html = renderToString(
<Router ssrPath="/some/path">
<App /> {/* App uses useSearchParams() */}
</Router>
);
What I found
It seems PR #549 changed the default behavior of useSearch:
v3.7.1:
export const useSearch = ({ ssrSearch = "" } = {}) =>
useLocationProperty(currentSearch, () => ssrSearch);
v3.8.0:
export const useSearch = ({ ssrSearch } = {}) =>
useLocationProperty(
currentSearch,
ssrSearch != null ? () => ssrSearch : currentSearch
);
#446
this change causes issues in Node.js SSR environments where location doesn't exist.
I also noticed that passing ssrSearch="" to <Router> doesn't help because of the || operator in Router:
const option = props[k] || parent[k]; // "" is falsy
Questions
- Is explicitly passing
ssrSearch now required for SSR? If so, should this be documented as a breaking change?
- Is there a recommended workaround for pre-rendering scenarios?
Environment
- wouter version: 3.8.0
- Node.js version: v24.x
- React version: 19.x
Issue
After upgrading from v3.7.1 to v3.8.0, our SSR (pre-rendering) started failing with
ReferenceError: location is not definedin Node.js environment.I'd like to understand if this is expected behavior or a regression.
To Reproduce
useSearchoruseSearchParamsin Node.jsReferenceError: location is not definedWhat I found
It seems PR #549 changed the default behavior of
useSearch:v3.7.1:
v3.8.0:
#446
this change causes issues in Node.js SSR environments where
locationdoesn't exist.I also noticed that passing
ssrSearch=""to<Router>doesn't help because of the||operator in Router:Questions
ssrSearchnow required for SSR? If so, should this be documented as a breaking change?Environment