-
-
Notifications
You must be signed in to change notification settings - Fork 177
Closed
Description
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
useSearchoruseSearchParamsin 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
);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 falsyQuestions
- Is explicitly passing
ssrSearchnow 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
Metadata
Metadata
Assignees
Labels
No labels