Skip to content

[PUB-1552] Add Pub/Sub React getting started guide #2534

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jun 10, 2025

Conversation

VeskeR
Copy link
Contributor

@VeskeR VeskeR commented Apr 15, 2025

Description

This PR adds a new getting started guide for Ably Pub/Sub with React.

This getting started guide is intended to replace the existing one at https://ably.com/docs/getting-started/react, which can be found at content/getting-started/react.textile. Due to some issues explained in this comment currently this PR adds a new file react-new.textile for the Pub/Sub React getting started guide.

Resolves PUB-1552

Checklist

Copy link

coderabbitai bot commented Apr 15, 2025

Important

Review skipped

Auto reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.


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.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@VeskeR VeskeR force-pushed the PUB-1552/pubsub-react-start branch from 92e5e98 to a74cbf9 Compare April 15, 2025 08:05
@VeskeR VeskeR changed the title Add Pub/Sub React getting started guide [PUB-1552] Add Pub/Sub React getting started guide Apr 15, 2025
@VeskeR VeskeR marked this pull request as ready for review April 15, 2025 08:07
@VeskeR
Copy link
Contributor Author

VeskeR commented Apr 15, 2025

So there already exists content/getting-started/react.textile file which renders at https://ably.com/docs/getting-started/react. I couldn't straight up replace it with the new content as there are a bunch of places in the docs that reference that file:

30 results - 12 files

content\getting-started\quickstart.textile:
  53:     The JavaScript SDK can be used with React and React Native. We also provide a dedicated "React Hooks package.":/docs/getting-started/react

content\getting-started\setup.textile:
  42:     The JavaScript SDK can be used with React and React Native. We also provide a dedicated "React Hooks package.":/docs/getting-started/react

examples\pub-sub-channel-messages\react\README.md:
  15: - [`AblyProvider`](/docs/getting-started/react#ably-provider): initializes and manages a shared pub/sub client instance, passing it down through React context to enable realtime pub/sub functionality across the application.
  16: - [`ChannelProvider`](/docs/getting-started/react#channel-provider): manages the state and functionality of a specific channel, providing access to messages, members, and realtime interactions within that channel via React context.
  17: - [`useChannel()`](/docs/getting-started/react#useChannel) hook: a hook to manage the state and interaction for a channel, allowing users to join, send messages, and listen for messages.
  18: - [`publish()`](/docs/getting-started/react#useChannel) function: a function to publish messages to the specified channel.

examples\pub-sub-channel-state\react\README.md:
  13: - [`AblyProvider`](/docs/getting-started/react#ably-provider): initializes and manages a shared pub/sub client instance, passing it down through React context to enable realtime pub/sub functionality across the application.
  14: - [`ChannelProvider`](/docs/getting-started/react#channel-provider): initializes and manages a shared channel instance, passing it down through React context to enable realtime pub/sub functionality across the application.
  15: - [`useChannelStateListener`](/docs/getting-started/react#useChannelStateListener): creates a subscriber to be notified of channel state changes.

examples\pub-sub-connection-state\react\README.md:
  13: - [`AblyProvider`](/docs/getting-started/react#ably-provider): initializes and manages a shared pub/sub client instance, passing it down through React context to enable realtime pub/sub functionality across the application.

examples\pub-sub-history\react\README.md:
  15: - [`AblyProvider`](/docs/getting-started/react#ably-provider): initializes and manages a shared pub/sub client instance, passing it down through React context to enable realtime pub/sub functionality across the application.
  16: - [`ChannelProvider`](/docs/getting-started/react#channel-provider): manages the state and functionality of a specific channel, providing access to messages, history, presence, and realtime interactions within that channel via React context.
  17: - [`useChannel()`](/docs/getting-started/react#useChannel) hook: a hook enabling users to subscribe to a channel and receive its messages.

examples\pub-sub-message-encryption\react\README.md:
  15: - [`AblyProvider`](/docs/getting-started/react#ably-provider): initializes and manages a shared pub/sub client instance, passing it down through React context to enable realtime pub/sub functionality across the application.
  16: - [`ChannelProvider`](/docs/getting-started/react#channel-provider): manages the state and functionality of a specific channel, providing access to messages, members, and realtime interactions within that channel via React context. Options are optional with `ChannelProvider`, options such as `cipher` to enable encryption.
  17: - [`useChannel()`](/docs/getting-started/react#useChannel) hook: a hook to manage the state and interaction for a channel, allowing users to join, send messages, and listen for messages.
  18: - [`publish()`](/docs/getting-started/react#useChannel) function: a function to publish messages to the specified channel.

examples\pub-sub-occupancy\react\README.md:
  13: - [`AblyProvider`](/docs/getting-started/react#ably-provider): initializes and manages a shared pub/sub client instance, passing it down through React context to enable realtime pub/sub functionality across the application.
  14: - [`ChannelProvider`](/docs/getting-started/react#channel-provider): manages the state and functionality of a specific channel, providing access to messages, history, presence, and realtime interactions within that channel via React context. By using channel options to enable occupancy, the channel will automatically update occupancy information.
  15: - [`useChannel()`](/docs/getting-started/react#useChannel) hook: a hook enabling users to subscribe to a channel and receive its messages. Whenever the occupancy is updated, the `useChannel()` hook will update the occupancy information.

examples\pub-sub-presence\react\README.md:
  15: - [`AblyProvider`](/docs/getting-started/react#ably-provider): initializes and manages a shared pub/sub client instance, passing it down through React context to enable realtime pub/sub functionality across the application.
  16: - [`ChannelProvider`](/docs/getting-started/react#channel-provider): manages the state and functionality of a specific channel, providing access to messages, presence, and realtime interactions within that channel via React context.
  17: - [`usePresenceListener()`](/docs/getting-started/react#useChannel) hook: a hook to subscribe to presence events on a channel, notifying users when other users enter or leave a presence set, or updates their member data.
  18: - [`usePresence()`](/docs/getting-started/react#usePresenceListener) hook: a hook enabling users to enter the presence set.

examples\spaces-component-locking\react\README.md:
  21: This example also uses the [`ChannelProvider`](/docs/getting-started/react#channel-provider) and [`useChannel()`](/docs/getting-started/react#useChannel) hook from the core Pub/Sub product in order to publish and subscribe to the changing values of each component.

src\components\SDKsPage\data.ts:
   58:           setupLink: 'getting-started/react',
  163:           setupLink: 'getting-started/react',

src\data\nav\pubsub.ts:
  41:           link: '/docs/getting-started/react',

And even the new Chat getting started guide for React has a reference to it: https://github.com/ably/docs/pull/2521/files#diff-7236fae23c5195699eddce94eb3f8c2f307b171b5f7035c85f974f86db02e9c7R77.

By looking at these references, I can see that the existing React documentation is mostly used as an API reference for hooks and the AblyProvider/ChannelProvider components.

The Chat getting started guide handles similar cases nicely - it provides links such as "ChatClientProvider":https://sdk.ably.com/builds/ably/ably-chat-js/main/typedoc/functions/chat-react.ChatClientProvider.html that point directly to the TypeDoc documentation for Chat React hooks.

Currently, we don't publish ably-js React hooks to TypeDoc (see the latest TypeDoc for v2, which includes only ably and modular). However, if we start generating TypeDoc documentation for ably-js React hooks, we can replace all existing references to the current React guide with links to the new TypeDoc API references. Then, the React guide itself could be replaced with the new content added in this PR.

@ttypic @m-hulbert wdyt?

Copy link
Contributor

@mschristensen mschristensen left a comment

Choose a reason for hiding this comment

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

Thanks for this! Overall it looks really great. I have stepped through the guide myself and left some comments on where I think we could make the end to end journey a bit more seamless/fewer gotchas.

I do also wonder whether for this type of getting staerted guide it's worth having e.g. a repo in e.g. Ably labs that walks through each step commit by commit? cc @m-hulbert what do you think?


Once installed, remove any existing styles from your @src/index.css@ file and ensure that it contains only the Tailwind CSS import:

```[css]
Copy link
Contributor

Choose a reason for hiding this comment

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

Using [css] here means that it doesn't play nicely with the language selector:

image

@m-hulbert do you have any suggestions on how to handle this?

Copy link
Contributor Author

@VeskeR VeskeR Apr 24, 2025

Choose a reason for hiding this comment

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

probably fixed in #2545.
the base branch for this PR (https://github.com/ably/docs/tree/edu-1845-pubsub-js-start) would need to be rebased on latest main to see if that fixed an issue

that PR won't help in this case: we need to display a code block for css which will never match currently selected language for the docs

@paddybyers
Copy link
Member

I do also wonder whether for this type of getting staerted guide it's worth having e.g. a repo in e.g. Ably labs that walks through each step commit by commit?

We used to do this for tutorials but they became unmaintainable. Do you think many people would go through commit-by-commit in this way?

@VeskeR VeskeR force-pushed the PUB-1552/pubsub-react-start branch from 3fff3bd to 2b46717 Compare April 23, 2025 21:24
@VeskeR VeskeR requested a review from mschristensen April 24, 2025 09:02
@VeskeR
Copy link
Contributor Author

VeskeR commented Apr 24, 2025

I also removed notes about AblyProvider and ChannelProvider being updated/added in ably-js 2.0 that are currently visible on https://ably.com/docs/getting-started/react:
image
image

ably-js 2.0 has been out for a ~year now, I don't think we should still have "new" and "updated" flags

Copy link
Contributor

@mschristensen mschristensen left a comment

Choose a reason for hiding this comment

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

Looks brilliant, really well put together, super clear and easy to follow. Minor comment but approving ahead of those small fixes. Thank you for this!


h2(#next). Next steps

Continue to explore the Ably Pub/Sub documentation with React as the selected language:
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we can remove this line

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The next steps section is basically identical across getting started guides and includes this line. No big reason to remove it I think

@m-hulbert m-hulbert force-pushed the edu-1845-pubsub-js-start branch 2 times, most recently from 80a3b87 to d6aeb8a Compare April 29, 2025 15:05
Base automatically changed from edu-1845-pubsub-js-start to main April 29, 2025 15:10
@VeskeR VeskeR force-pushed the PUB-1552/pubsub-react-start branch from 2b46717 to 40623ea Compare May 2, 2025 08:47
@jamienewcomb
Copy link
Member

@VeskeR @m-hulbert do we plan to do anything with this?

@m-hulbert
Copy link
Contributor

@jamienewcomb Andrii was going to update to move to Tailwind to match with what we decided with Chat. I don't think he had the chance before vacation.

@jamienewcomb
Copy link
Member

@jamienewcomb Andrii was going to update to move to Tailwind to match with what we decided with Chat. I don't think he had the chance before vacation.

@m-hulbert I can't see any acknowledgement that he is going to do that on this PR. is that a hard requirement?

@m-hulbert
Copy link
Contributor

@jamienewcomb Andrii was going to update to move to Tailwind to match with what we decided with Chat. I don't think he had the chance before vacation.

@m-hulbert I can't see any acknowledgement that he is going to do that on this PR. is that a hard requirement?

@jamienewcomb to keep them consistent, yes. There's a Slack thread where we've agreed this.

@VeskeR VeskeR force-pushed the PUB-1552/pubsub-react-start branch 3 times, most recently from e3755c9 to 33835a1 Compare June 3, 2025 04:56
@VeskeR
Copy link
Contributor Author

VeskeR commented Jun 3, 2025

@m-hulbert went back to using Tailwind in 33835a1.

There is last outstanding question regarding existing content/getting-started/react.textile file

@GregHolmes GregHolmes force-pushed the PUB-1552/pubsub-react-start branch from 33835a1 to b35cd82 Compare June 3, 2025 14:44
@m-hulbert m-hulbert temporarily deployed to ably-docs-pub-1552-pubs-73cbtu June 4, 2025 09:22 Inactive
@GregHolmes GregHolmes force-pushed the PUB-1552/pubsub-react-start branch from b35cd82 to 7a0b321 Compare June 9, 2025 08:49
@GregHolmes GregHolmes temporarily deployed to ably-docs-pub-1552-pubs-73cbtu June 9, 2025 08:49 Inactive
@GregHolmes GregHolmes temporarily deployed to ably-docs-pub-1552-pubs-73cbtu June 9, 2025 12:24 Inactive
@GregHolmes GregHolmes temporarily deployed to ably-docs-pub-1552-pubs-73cbtu June 9, 2025 12:24 Inactive
@GregHolmes GregHolmes force-pushed the PUB-1552/pubsub-react-start branch from af68b20 to 792fc22 Compare June 9, 2025 12:24
@GregHolmes GregHolmes temporarily deployed to ably-docs-pub-1552-pubs-73cbtu June 9, 2025 12:25 Inactive
@GregHolmes
Copy link
Contributor

I've made small changes to this getting started to bring things more inline with the existing JS getting started guide in terms of layout etc.

I've also moved our react hooks page to react-hooks and renamed the react getting started to react. We will in the near future be updating the docs so there's no need for the react-hooks page.

I would advise we don't merge just yet as need to discuss with marketing and other depts to determine any other links that link to the react hooks page.

Copy link
Contributor

@GregHolmes GregHolmes left a comment

Choose a reason for hiding this comment

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

Approved, but not to be merged today.

@mschristensen
Copy link
Contributor

@GregHolmes we will leave this with you in that case and mark this ticket as done on our side if that's okay, thanks

VeskeR and others added 5 commits June 10, 2025 13:48
Use raw css instead of tailwind, split components into separate files,
and provide full contents for files that can be copied and pasted as is.

Co-authored-by: Mike Christensen <[email protected]>
@GregHolmes GregHolmes force-pushed the PUB-1552/pubsub-react-start branch from 7602c8d to 5006227 Compare June 10, 2025 12:48
@GregHolmes GregHolmes merged commit 8004d3e into main Jun 10, 2025
6 checks passed
@GregHolmes GregHolmes deleted the PUB-1552/pubsub-react-start branch June 10, 2025 12:54
@GregHolmes GregHolmes temporarily deployed to ably-docs-pub-1552-pubs-73cbtu June 10, 2025 14:34 Inactive
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

6 participants