Skip to content

Commit 65cceec

Browse files
fix(web): remove router.refresh() after router.push() to fix Next.js 16 navigation (#974)
* fix(web): remove router.refresh() after router.push() to fix Next.js 16 navigation In Next.js 16, the prefetch cache and navigation system was completely rewritten. Calling router.refresh() immediately after router.push() creates a race condition where the cache invalidation interrupts the in-flight navigation, causing the page to not load. Removed the router.refresh() calls from: - useCreateNewChatThread.ts - chatName.tsx - chatSidePanel.tsx - inviteMemberCard.tsx Also documents this pattern in CLAUDE.md to prevent future regressions. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * chore: update CHANGELOG for #974 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> --------- Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 4004933 commit 65cceec

File tree

6 files changed

+16
-4
lines changed

6 files changed

+16
-4
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1414

1515
### Fixed
1616
- Preserve regex and case sensitivity query parameters when loading more search results. [#972](https://github.com/sourcebot-dev/sourcebot/pull/972)
17+
- Fixed page navigation failing after Next.js 16 upgrade by removing `router.refresh()` calls immediately following `router.push()`. [#974](https://github.com/sourcebot-dev/sourcebot/pull/974)
1718

1819
## [4.13.1] - 2026-02-28
1920

CLAUDE.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,21 @@ export const GET = apiHandler(async (request: NextRequest) => {
182182
});
183183
```
184184

185+
## Next.js Router Navigation
186+
187+
Do NOT call `router.refresh()` immediately after `router.push()`. In Next.js 16, the prefetch cache and navigation system was completely rewritten, and calling `router.refresh()` right after `router.push()` creates a race condition — the refresh invalidates the cache and can interrupt the in-flight navigation, leaving the page stuck or not loading.
188+
189+
```ts
190+
// Bad - router.refresh() races with router.push() in Next.js 16
191+
router.push(url);
192+
router.refresh(); // ❌ can cancel the navigation
193+
194+
// Good - if navigating to a new route, the page will fetch fresh data on load
195+
router.push(url); //
196+
```
197+
198+
If you need to refresh server component data after a mutation, use the server-side `refresh()` from `next/cache` in a Server Action instead of `router.refresh()` on the client.
199+
185200
## Docs Images
186201

187202
Images added to `.mdx` files in `docs/` should be wrapped in a `<Frame>` component:

packages/web/src/app/[domain]/chat/components/chatName.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ export const ChatName = ({ name, id, isOwner = false, isAuthenticated = false }:
6161
description: `✅ Chat deleted successfully`
6262
});
6363
router.push(`/${SINGLE_TENANT_ORG_DOMAIN}/chat`);
64-
router.refresh();
6564
return true;
6665
}
6766
}, [id, toast, router]);

packages/web/src/app/[domain]/chat/components/chatSidePanel.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,6 @@ export const ChatSidePanel = ({
115115
router.push(`/${SINGLE_TENANT_ORG_DOMAIN}/chat`);
116116
}
117117

118-
router.refresh();
119118
return true;
120119
}
121120
}, [chatId, router, toast]);

packages/web/src/app/[domain]/settings/members/components/inviteMemberCard.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ export const InviteMemberCard = ({ currentUserRole, isBillingEnabled, seatsAvail
6868
} else {
6969
form.reset();
7070
router.push(`?tab=invites`);
71-
router.refresh();
7271
toast({
7372
description: `✅ Successfully invited ${data.emails.length} members`
7473
});

packages/web/src/features/chat/useCreateNewChatThread.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ export const useCreateNewChatThread = ({ isAuthenticated = false }: UseCreateNew
5454
const url = createPathWithQueryParams(`/${SINGLE_TENANT_ORG_DOMAIN}/chat/${response.id}`);
5555

5656
router.push(url);
57-
router.refresh();
5857
}, [router, toast, setChatState]);
5958

6059
const createNewChatThread = useCallback(async (children: Descendant[], selectedSearchScopes: SearchScope[]) => {

0 commit comments

Comments
 (0)