Skip to content

Replace window.location.href with router.push for in-app navigation #1154

@MODSetter

Description

@MODSetter

Description

Several components use window.location.href = "..." for in-app navigation, which triggers a full page reload — destroying React state, re-downloading JS, and re-initializing the entire app. Next.js router.push does client-side navigation without a reload.

Files to change

1. surfsense_web/components/UserDropdown.tsx (lines 44, 51)

window.location.href = "/";

Context: After logout. Since this clears tokens, a full reload may be intentional. Consider router.push("/") + router.refresh() instead.

2. surfsense_web/components/layout/ui/dialogs/CreateSearchSpaceDialog.tsx (line ~69)

window.location.href = `/dashboard/${result.id}/onboard`;

Fix: router.push(\/dashboard/${result.id}/onboard`)`

3. surfsense_web/components/layout/ui/tabs/DocumentTabContent.tsx (line ~193)

window.location.reload();

Fix: router.refresh() to revalidate server data without full reload.

4. surfsense_web/app/(home)/login/page.tsx (line ~82)

window.location.reload();

Fix: router.refresh()

What to do

For each file:

  1. Import useRouter from next/navigation
  2. Replace window.location.href = url with router.push(url)
  3. Replace window.location.reload() with router.refresh()

Exception: Keep window.location for:

  • External URLs (OAuth redirects, Stripe checkout)
  • Full token/session reset after logout (if router.push + refresh isn't sufficient)

Acceptance criteria

  • In-app navigation doesn't cause full page reloads
  • User flow still works (space creation, document reload, login retry)
  • External OAuth flows are unaffected

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions