Skip to content
This repository was archived by the owner on Sep 16, 2026. It is now read-only.

feat: Next.js 16 migration with React 19 fixes - #431

Merged
leoisadev1 merged 2 commits into
mainfrom
feat/nextjs-16-migration-fixes
Nov 26, 2025
Merged

leoisadev1 merged 2 commits into
mainfrom
feat/nextjs-16-migration-fixes

Conversation

@leoisadev1

Copy link
Copy Markdown
Member

Summary

  • Migrate middleware.ts to proxy.ts (Next.js 16 deprecation)
  • Add --webpack flag to dev/build scripts (Turbopack lacks absolute path alias support needed for Convex deduplication in monorepo)
  • Fix SSR-safe Convex client initialization in providers (prevents "Could not find Convex client" error during static generation)
  • Fix Maximum update depth exceeded error in chat-messages-panel (React 19's stricter ref handling)
  • Add suppressHydrationWarning for browser extension compatibility
  • Add ChatListProvider context for real-time sidebar streaming indicators
  • Improve mobile dashboard nav with streaming indicators

Test plan

  • Build passes locally (bun run build)
  • Dev server starts without errors
  • Static pages generate successfully
  • Verify chat streaming works in production
  • Verify sidebar streaming indicators update in real-time

🤖 Generated with Claude Code

- Migrate middleware.ts to proxy.ts (Next.js 16 deprecation)
- Add --webpack flag to dev/build (Turbopack lacks absolute path alias support for Convex dedup)
- Fix SSR-safe Convex client initialization in providers
- Fix Maximum update depth exceeded error in chat-messages-panel (React 19 stricter ref handling)
- Add suppressHydrationWarning for browser extension compatibility
- Add ChatListProvider context for real-time sidebar updates
- Improve mobile dashboard nav with streaming indicators

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
@vercel

vercel Bot commented Nov 26, 2025 •

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
openchat-web Ready Ready Preview Comment Nov 26, 2025 9:36pm

@greptile-apps

greptile-apps Bot commented Nov 26, 2025

Copy link
Copy Markdown
Contributor

Greptile Overview

Greptile Summary

This PR successfully migrates the codebase to Next.js 16 and React 19, addressing several critical build and runtime issues while adding real-time streaming indicators.

Key Changes:

  • Renamed middleware.ts to proxy.ts (Next.js 16 requirement)
  • Fixed SSR-safe Convex client initialization to prevent "Could not find Convex client" errors during static generation
  • Added --webpack flags to build scripts (Turbopack doesn't support absolute path aliases needed for Convex deduplication)
  • Implemented real-time streaming indicators in sidebar using new ChatListProvider context
  • Enhanced stream reconnection logic to preserve streaming state across page reloads
  • Added suppressHydrationWarning for browser extension compatibility
  • Created comprehensive test coverage for chat prefetch cache

Issues Found:

  • The status field in the schema uses v.string() instead of a union type, allowing invalid values
  • Error handling in completeStream could leave chats stuck in "streaming" state if message doesn't exist
  • Mobile navigation missing streaming indicators (inconsistent with desktop)
  • Hardcoded chat list limits could get out of sync across components

The migration is well-executed with thorough documentation and proper React 19 compatibility fixes.

Confidence Score: 4/5

  • This PR is mostly safe to merge with a few minor issues that should be addressed
  • Score reflects solid migration work with comprehensive documentation and testing, but deducted 1 point for the schema validation issue (string instead of union type) and error handling gap in completeStream that could cause UI bugs
  • Pay close attention to apps/server/convex/schema.ts (schema validation) and apps/server/convex/streaming.ts (error handling)

Important Files Changed

File Analysis

Filename Score Overview
apps/web/package.json 5/5 Updated Next.js to 16.0.4, React to 19.1.1. Added --webpack flags to scripts and new dependencies (import-in-the-middle, require-in-the-middle, set-cookie-parser).
apps/web/src/components/providers.tsx 5/5 Fixed SSR-safe Convex client initialization by checking typeof window !== 'undefined'. Renders fallback tree during SSG/SSR. Added ChatListProvider.
apps/web/src/contexts/chat-list-context.tsx 5/5 New context provider for real-time chat list updates via Convex subscription. Enables streaming indicators in sidebar.
apps/server/convex/schema.ts 4/5 Added optional status field to chats table for streaming indicators. Field lacks enum constraint - accepts any string value.
apps/server/convex/streaming.ts 4/5 Enhanced stream reconnection logic and added chat status updates (streaming/idle). getStreamBody now uses message status for accurate reconnection handling.
apps/web/src/components/app-sidebar.tsx 5/5 Added streaming indicator dot with real-time status from ChatListProvider. Removed proactive prefetching (was spamming API). Status map uses O(1) lookup.

Sequence Diagram

sequenceDiagram
    participant User
    participant Client
    participant Providers
    participant ConvexClient
    participant ChatListProvider
    participant Sidebar
    participant StreamingMutation

    Note over Client,Providers: SSR/SSG Phase
    Client->>Providers: Initialize (typeof window check)
    alt window is undefined (SSR)
        Providers->>Client: Render fallback tree (no Convex)
    else window exists (Browser)
        Providers->>ConvexClient: new ConvexReactClient(url)
        Providers->>ChatListProvider: Mount with Convex context
        ChatListProvider->>ConvexClient: Subscribe to chats.list
    end

    Note over User,StreamingMutation: Chat Streaming Flow
    User->>Client: Send message
    Client->>StreamingMutation: prepareChat()
    StreamingMutation->>ConvexClient: PATCH chat (status: "streaming")
    ConvexClient-->>ChatListProvider: Real-time update (status: streaming)
    ChatListProvider-->>Sidebar: Update status map
    Sidebar->>Sidebar: Show streaming indicator dot

    Note over Client,StreamingMutation: Stream Completion
    StreamingMutation->>ConvexClient: completeStream()
    ConvexClient->>ConvexClient: PATCH message (status: completed)
    ConvexClient->>ConvexClient: PATCH chat (status: "idle")
    ConvexClient-->>ChatListProvider: Real-time update (status: idle)
    ChatListProvider-->>Sidebar: Update status map
    Sidebar->>Sidebar: Hide streaming indicator

    Note over User,Sidebar: Page Reload During Streaming
    User->>Client: Reload page
    Client->>Providers: Re-initialize
    Providers->>ChatListProvider: Re-mount
    ChatListProvider->>ConvexClient: Subscribe to chats.list
    ConvexClient-->>ChatListProvider: Receive chats (status still "streaming")
    ChatListProvider-->>Sidebar: Update with streaming status
    Sidebar->>Sidebar: Show streaming indicator (reconnected)
Loading

@greptile-apps greptile-apps Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

21 files reviewed, 5 comments

Edit Code Review Agent Settings | Greptile

Comment on lines +37 to +38
// Chat streaming status: "idle" | "streaming" - used to show spinner in sidebar
// and enable stream resumption on page reload

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logic: The status field should use v.union(v.literal("idle"), v.literal("streaming")) instead of v.string() to enforce valid values and prevent typos.

Suggested change
// Chat streaming status: "idle" | "streaming" - used to show spinner in sidebar
// and enable stream resumption on page reload
// Chat streaming status: "idle" | "streaming" - used to show spinner in sidebar
// and enable stream resumption on page reload
status: v.optional(v.union(v.literal("idle"), v.literal("streaming"))),

Comment thread apps/server/convex/streaming.ts Outdated
Comment on lines +184 to +190

// Reset chat status to idle when streaming completes
if (message?.chatId) {
await ctx.db.patch(message.chatId, {
status: "idle",
updatedAt: Date.now(),
});

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logic: If completeStream is called but the message doesn't exist, the chat status won't be reset to "idle". This could leave the sidebar showing a perpetual streaming indicator.

Suggested change
// Reset chat status to idle when streaming completes
if (message?.chatId) {
await ctx.db.patch(message.chatId, {
status: "idle",
updatedAt: Date.now(),
});
// Get the message to find the chatId
const message = await ctx.db.get(args.messageId);
if (!message) {
throw new Error("Message not found");
}
await ctx.db.patch(args.messageId, {
content: args.content,
reasoning: args.reasoning,
thinkingTimeMs: args.thinkingTimeMs,
status: "completed",
});
// Reset chat status to idle when streaming completes
await ctx.db.patch(message.chatId, {
status: "idle",
updatedAt: Date.now(),
});

Comment on lines +265 to +278
type="button"
onClick={() => handleChatClick(chat.id)}
onMouseEnter={() => {
router.prefetch(`/dashboard/chat/${chat.id}`);
void prefetchChat(chat.id);
}}
className={cn(
"w-full text-left truncate rounded-lg px-3 py-2.5 text-sm transition-colors",
isActive
? "bg-accent text-accent-foreground font-medium"
: "text-foreground hover:bg-accent/50"
)}
>
{chat.title || "Untitled"}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: Mobile nav doesn't show streaming indicators like the desktop sidebar does. Consider adding the streaming dot here for consistency:

Suggested change
type="button"
onClick={() => handleChatClick(chat.id)}
onMouseEnter={() => {
router.prefetch(`/dashboard/chat/${chat.id}`);
void prefetchChat(chat.id);
}}
className={cn(
"w-full text-left truncate rounded-lg px-3 py-2.5 text-sm transition-colors",
isActive
? "bg-accent text-accent-foreground font-medium"
: "text-foreground hover:bg-accent/50"
)}
>
{chat.title || "Untitled"}
<button
type="button"
onClick={() => handleChatClick(chat.id)}
onMouseEnter={() => {
router.prefetch(`/dashboard/chat/${chat.id}`);
void prefetchChat(chat.id);
}}
className={cn(
"w-full flex items-center gap-2 text-left truncate rounded-lg px-3 py-2.5 text-sm transition-colors",
isActive
? "bg-accent text-accent-foreground font-medium"
: "text-foreground hover:bg-accent/50"
)}
>
{chat.status === "streaming" && <StreamingDot />}
<span className="truncate">{chat.title || "Untitled"}</span>
</button>

Note: You'd need to import/define StreamingDot component and ensure chat.status is available.

Comment on lines +164 to +175
// REAL-TIME STREAMING STATUS: Use Convex subscription for live status updates
// This enables the streaming indicator dot in the sidebar
const { chats: realtimeChats } = useChatList();

// Create a map of chat statuses from real-time data for O(1) lookup
const realtimeStatusMap = useMemo(() => {
const map = new Map<string, string | undefined>();
for (const chat of realtimeChats) {
map.set(chat._id, chat.status);
}
return map;
}, [realtimeChats]);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: The realtimeChats from useChatList() are fetched separately from initialChats (from server-side rendering). If a chat exists in initialChats but not yet in realtimeChats during initial load, the status map lookup will return undefined. This is fine but could briefly show incorrect status during hydration.

Consider documenting this behavior or ensuring the real-time subscription loads before the component mounts.

Comment on lines +47 to +50
const chatListResult = useQuery(
api.chats.list,
userId ? { userId, limit: 200 } : "skip"
);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: The limit of 200 chats is hardcoded here but may differ from limits used elsewhere in the app (e.g., mobile nav also uses 200, but if changed in one place, they could get out of sync). Consider extracting to a shared constant.

- Use v.union(v.literal("idle"), v.literal("streaming")) for chat status field instead of v.string() to enforce valid values
- Add error handling in completeStream if message doesn't exist to prevent perpetual streaming indicator

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>

This branch was successfully deployed

1 active deployment
Preview — fe80d385 Deployed Nov 26, 2025 by vercel[bot]
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant