-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Replace window.location.href with router.push for in-app navigation #1154
Copy link
Copy link
Open
Labels
Description
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:
- Import
useRouterfromnext/navigation - Replace
window.location.href = urlwithrouter.push(url) - Replace
window.location.reload()withrouter.refresh()
Exception: Keep window.location for:
- External URLs (OAuth redirects, Stripe checkout)
- Full token/session reset after logout (if
router.push+refreshisn'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
Reactions are currently unavailable