examples/with-ably: update to App Router + Ably v2#94600
Open
owenpearson wants to merge 1 commit into
Open
Conversation
Replaces Pages Router with App Router, upgrades to ably v2 (hooks bundled into ably/react), and creates the Realtime client inside useEffect so no connection is attempted during SSR. Additional cleanups: - Bump React, react-dom and their @types to v19 to match other recently-modernized examples. - Run pub/sub and presence on a single channel rather than splitting them across two channels. - Return 400 from /api/createTokenRequest when the clientId query parameter is missing, instead of coalescing to a shared "NO_CLIENT_ID" string. - Various cleanups in README.md Tracks ably/ably-nextjs-fundamentals-kit#11.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Modernizes the
examples/with-ablyexample off the deprecated Pages Router and@ably-labs/react-hookspackage, onto the App Router and the React hooks that ship with ably-js v2.The previous example created the Realtime client at module scope inside
pages/_app.tsx, which caused connections to be created during SSR. The rewrite creates it inside auseEffectin a client component (app/ably-client-provider.tsx), gated by anAblyReadyContextso consumer components don't try to callably/reacthooks before the provider is in place.Notable changes
ablyto v2; drop@ably-labs/react-hooks(hooks now ship asably/react).@typesto v19 to match recently-modernized examples likewith-supabase.app/api/createTokenRequest/route.tsnow returns 400 whenclientIdis missing rather than coalescing to a shared"NO_CLIENT_ID"value.How I tested these changes
Ran the example with Chrome and Firefox. Verified in two browser windows:
POST /api/send-messageround-trips and broadcasts.