fix: replace outdated Next.js integration patterns#15
Conversation
Remove dynamic import with ssr: false from page.js (Pattern A) and move Ably client creation from component body into useEffect (Pattern C). This prevents unnecessary server-side connection attempts and stops new WebSocket connections being created on every render. References: AIT-540, ably/ably-nextjs-fundamentals-kit#11 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
The demo was migrated from Ably Pub/Sub to the Ably Chat SDK but the README still described the old approach. This removes the misleading Pub/Sub migration banner, updates the description and tech stack to reference the Chat SDK and its React hooks, corrects the Node version requirement to 18+, updates the architecture description to reference Route Handlers instead of serverless functions, and removes the "add message history" suggestion since the app already loads the last 50 messages. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
History is still not part of the demo, keep the section as-is. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Upgrades @ably/chat from 0.6.0 (pre-release) to 1.3.1 and ably from 2.8.0 to 2.21.0 (required peer dependency). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- useMessages() returns `sendMessage` instead of `send` - ChatRoomProvider takes `name` prop instead of `id` - Remove invalid `history` room option (no longer part of RoomOptions) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Message.isSameAs() and Message.after() were removed in Chat SDK v1.x. Use serial string comparison for deduplication instead. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Move title and favicon from next/head in page.js to the metadata export in layout.js, which is the correct approach for the App Router. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
splindsay-92
left a comment
There was a problem hiding this comment.
Some minor comments, but looks good! Ping me and I'll approve the PR when you're ready :)
| if (index === -1) { | ||
| newMessages.push(newMessage); | ||
| } else { | ||
| newMessages.splice(index, 0, newMessage); |
There was a problem hiding this comment.
This code ensured the message is placed in the correct order. While messages publish in region are guaranteed to be in order, cross region publishes might not be. Since this just a demo, it's probably enough to call .sort() on the new array each time (in production we do more complex binary search to find the correct insert position in an efficient way and always keep the array ordered)
There was a problem hiding this comment.
Overenthusiastic rewrite from Claude when handling a changed Chat SDK API, I've reworked.
| - **An Ably account** for sending messages: [Create an account with Ably for free](https://ably.com/signup). | ||
| - **A Vercel Account** for hosting on production: [Create an account with Vercel for free](https://vercel.com/signup). | ||
| - **Node 16** or greater: [Install Node](https://nodejs.org/en/). | ||
| - **Node 18** or greater: [Install Node](https://nodejs.org/en/). |
There was a problem hiding this comment.
Can we bump this to Node 20 please? Chat-js generally aims for V20 support onwards now :)
There was a problem hiding this comment.
Done, I've also added it to package.json to make sure it's enforced
Reimplement the sorted insertion logic that was removed in 050a702 using serial string comparison, so messages arriving out of order during reconnection are placed in the correct chronological position. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Add .nvmrc, engines field in package.json, and update README prerequisites. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Sort messages by serial using comparison operators as shown in the Chat SDK documentation, rather than findIndex/splice insertion. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Replace manual splice-based insertion with a simpler sort approach, matching the pattern used in ably-labs/NextJS-chat-app#15. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Summary
Aim is to update all Vercel-related demos, blogs and tutorials to match the current Vercel recommendations and versions.
Moved demo to latest Chat SDK
@ably/chatfrom 0.6.0 to 1.3.1 andablyfrom 2.8.0 to 2.21.0Replace outdated Next.js patterns
dynamic+ssr: falsefromapp/page.jsand replace with a direct importuseEffect+useStateincomponents/Chat.jsxto prevent new connections on every renderThese are the same fixes applied in ably/ably-nextjs-fundamentals-kit#11
Fix runtime warnings
next/headto the Next.js Metadata APIGeneral housekeeping
References: AIT-540
Test plan
npm run build— confirms no compilation errorsnpm run devwith a validABLY_API_KEYand verify the chat demo worksdynamicorssr: falsereferences remain in the codebasenext/headruntime warning🤖 Generated with Claude Code