Conversation
… layout - Replace module-level client creation with useEffect to avoid SSR hydration mismatches - Add null guard and cleanup (ably.close()) in AblyProvider - Update Step 1 prose to reference useEffect approach - Move ConnectionState inside ChannelProvider in Step 3 page.tsx - Replace em dash with hyphen in PresenceStatus member status display Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
nextjs is not registered in @ably/ui CodeSnippet languages registry, causing highlight.js to throw "Unknown language: nextjs" during SSR. react works because it has a syntaxHighlighterKey mapping to javascript. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
… app - Add globals.css subsection with font-size reset and box-sizing rules - Style ConnectionState with grey pill background and bold state - Style page.tsx with centred title and max-width container - Style Messages with scrollable bordered box, blue left-border per message, clientId label, and Publish button - Style PresenceStatus with grey pill, green dot indicator, and h3 heading - Add two-column flex layout to final page.tsx Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
Adds a new Pub/Sub “getting started” guide tailored for Next.js (App Router) and wires Next.js in as a selectable language across the docs language system and Pub/Sub navigation.
Changes:
- Adds a new MDX guide at
/docs/getting-started/nextjscovering connection, pub/sub, presence, and history withably/react. - Adds
nextjsto docs language metadata (keys, labels, and Pub/Sub version mapping). - Adds a Pub/Sub sidebar nav entry and includes a screenshot asset for the guide.
Reviewed changes
Copilot reviewed 5 out of 6 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| src/pages/docs/getting-started/nextjs.mdx | New Next.js App Router Pub/Sub getting-started guide content and code samples |
| src/images/content/screenshots/getting-started/pub-sub-nextjs-getting-started-guide.png | Screenshot used by the new guide |
| src/data/nav/pubsub.ts | Adds “Next.js” link under Pub/Sub getting started |
| src/data/languages/types.ts | Adds nextjs to LanguageKey union |
| src/data/languages/languageInfo.ts | Adds label/syntax metadata for nextjs |
| src/data/languages/languageData.ts | Adds nextjs version entry for Pub/Sub language selector |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| import { AblyProvider } from './AblyProvider'; | ||
|
|
||
| export default function RootLayout({ children }: { children: React.ReactNode }) { |
There was a problem hiding this comment.
In the layout.tsx snippet, children is typed as React.ReactNode but React isn’t imported. In a typical Next.js + TypeScript setup this will fail type-checking. Prefer importing ReactNode as a type (or PropsWithChildren) from react and using that instead of the React. namespace.
| import { AblyProvider } from './AblyProvider'; | |
| export default function RootLayout({ children }: { children: React.ReactNode }) { | |
| import type { ReactNode } from 'react'; | |
| import { AblyProvider } from './AblyProvider'; | |
| export default function RootLayout({ children }: { children: ReactNode }) { |
| useEffect(() => { | ||
| async function loadHistory() { | ||
| const history = await channel.history({ limit: 5 }); | ||
| setMessages(history.items.reverse()); | ||
| } | ||
| loadHistory().catch(console.error); | ||
| }, [channel]); |
There was a problem hiding this comment.
The history-loading effect replaces the entire messages state with history.items.reverse(). Because the realtime subscription callback is active at the same time, any messages received between mount and the history request resolving can be dropped (overwritten). Consider merging history into the existing state (and optionally de-duping) rather than replacing it.
| - nextjs | ||
| --- | ||
|
|
||
| This guide will get you started with Ably Pub/Sub in a new Next.js application using the App Router. |
There was a problem hiding this comment.
| This guide will get you started with Ably Pub/Sub in a new Next.js application using the App Router. | |
| This guide will get you started with Ably Pub/Sub in a new Next.js application. |
| Because the Ably Realtime client uses browser APIs such as WebSocket, it cannot run during server-side rendering. Create a new file `src/app/AblyProvider.tsx` that initializes the client inside a `useEffect` and wraps children in the `AblyProvider`: | ||
|
|
||
| <Code> | ||
| ```javascript |
There was a problem hiding this comment.
This should be React throughout.
|
|
||
| The Ably Pub/Sub SDK provides React hooks and context providers that make it easy to use Pub/Sub features in your components. | ||
|
|
||
| Because the Ably Realtime client uses browser APIs such as WebSocket, it cannot run during server-side rendering. Create a new file `src/app/AblyProvider.tsx` that initializes the client inside a `useEffect` and wraps children in the `AblyProvider`: |
There was a problem hiding this comment.
Same comment as the others on 'Ably realtime client' vs Pub/Sub SDK.
|
|
||
| ## Step 2: Subscribe to a channel and publish a message <a id="step-2"/> | ||
|
|
||
| Messages contain the data that a client is communicating. Channels are named message streams — clients only receive messages published to channels they are subscribed to. |
There was a problem hiding this comment.
Channels are named message streams I'm not sure about this terminology.
| Update `src/app/page.tsx` to include the `ChannelProvider`: | ||
|
|
||
| <Code> | ||
| ```javascript |
There was a problem hiding this comment.
You could use the syntax highlighting of code blocks for items where we're adding lines in.
| ``` | ||
| </Code> | ||
|
|
||
| Your client ID will appear in the presence list. Test with another client joining via the CLI: |
There was a problem hiding this comment.
| Your client ID will appear in the presence list. Test with another client joining via the CLI: | |
| Your client ID will appear in the presence list. Join presence via the CLI to see another client joining: |
|
|
||
| Your completed application should look like this: | ||
|
|
||
|  |
There was a problem hiding this comment.
That's a very long description of the image :-)
splindsay-92
left a comment
There was a problem hiding this comment.
Code looks good, just a few minor points :)
|
|
||
| ## Step 2: Subscribe to a channel and publish a message <a id="step-2"/> | ||
|
|
||
| Messages contain the data that a client is communicating. Channels are named message streams — clients only receive messages published to channels they are subscribed to. |
There was a problem hiding this comment.
I don't really see the utility in this statement, perhaps it's enough to say.. You can use the ChannelProvider to access the underlying channel, this enables you to publish and subscribe to messages on that channel. The the sections below just detail this?
|
|
||
| <Code> | ||
| ```shell | ||
| ably channels publish my-first-channel 'Hello from CLI!' |
There was a problem hiding this comment.
Would it be better to mention subscribe here instead, since you're testing publishing via the component now?
|
|
||
| ### Update globals.css <a id="step-4-globals-css"/> | ||
|
|
||
| Replace the contents of `src/app/globals.css` with the following to reset browser defaults and ensure consistent font sizing across all elements including inputs and buttons: |
There was a problem hiding this comment.
Should this be at the end or at the start? Considering it affects the look of the app as you build it, perhaps starting from the correct style state is better
Summary
src/pages/docs/getting-started/nextjs.mdx)ably/reacthooksuseEffectfor Ably client creation to avoid SSR hydration mismatches in the App Routernextjsas a new language entry acrosslanguageData.ts,languageInfo.ts, andtypes.tspubsub.tshttps://ably.atlassian.net/browse/DX-1001
Test plan
/docs/getting-started/nextjsnextjslanguage selector appears and is selected by default🤖 Generated with Claude Code