Skip to content

SSR in Node.js fails after upgrading to v3.8.0 - is ssrSearch now required? #550

@kiki-ki

Description

@kiki-ki

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

  1. Use wouter v3.8.0
  2. Pre-render a page that uses useSearch or useSearchParams in Node.js
  3. 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

  1. Is explicitly passing ssrSearch now required for SSR? If so, should this be documented as a breaking change?
  2. 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

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions