Skip to content
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

Move JS API docs to the interface #1716

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

alexeyr-ci2
Copy link
Collaborator

@alexeyr-ci2 alexeyr-ci2 commented Mar 20, 2025

Summary

Move JS docs to the interface so clients can see them and improve them where needed

Pull Request checklist

  • [ ] Add/update test to cover these changes
  • Update documentation
  • [ ] Update CHANGELOG file

This change is Reviewable

Summary by CodeRabbit

  • Documentation

    • Updated API guides with refined references and naming conventions to improve clarity.
    • Removed outdated references to certain methods in the documentation.
  • New Features

    • Introduced flexible configuration options for enhanced integration.
    • Expanded API capabilities delivering broader functionality and improved customization, including new methods for store management and rendering.
  • Bug Fixes

    • Removed unnecessary documentation comments for cleaner code, without changing functionality.

Sorry, something went wrong.

Copy link
Contributor

coderabbitai bot commented Mar 20, 2025

Walkthrough

This pull request updates the ReactOnRails API documentation and source code. The documentation now references the ReactOnRails interface in the types module, and the registerStore method has been renamed to registerStoreGenerators. In the client code, inline comments have been removed, and method signatures have been updated to use a new ReactOnRailsOptions type for flexible option settings. Additionally, the import in the context file has been modified to use ReactOnRailsInternal, and the types file has been extended with new methods and updated interfaces.

Changes

File(s) Change Summary
docs/api/javascript-api.md Updated documentation to reference interface ReactOnRails in types/index.ts, renamed registerStore to registerStoreGenerators, and removed references to authenticityToken and authenticityHeaders.
node_package/src/ReactOnRails.client.ts Removed inline documentation comments; updated method signatures to use a new generic and flexible ReactOnRailsOptions type.
node_package/src/context.ts Updated import from ReactOnRails to ReactOnRailsInternal.
node_package/src/types/index.ts Added new interface ReactOnRailsOptions; expanded and updated the ReactOnRails and ReactOnRailsInternal interfaces with new methods and revised signatures.
node_package/src/ReactOnRails.full.ts Removed JSDoc comments for Client.handleError and Client.serverRenderReactComponent methods without altering their functionality.

Sequence Diagram(s)

Loading
sequenceDiagram
    participant App
    participant ReactOnRails
    App->>ReactOnRails: registerStoreGenerators(storeGenerators)
    ReactOnRails-->>ReactOnRails: Store generator registered
    App->>ReactOnRails: getOrWaitForStoreGenerator(name)
    ReactOnRails-->>App: Returns store generator promise
Loading
sequenceDiagram
    participant App
    participant ReactOnRails
    App->>ReactOnRails: reactHydrateOrRender(domNode, reactElement, [hydrate])
    ReactOnRails-->>App: Render result returned

Possibly related PRs

Suggested reviewers

  • Judahmeek

Poem

I'm a bunny coding through the night,
Hopping over changes, all merry and bright.
Methods renamed and types redefined,
Clean code and docs now perfectly aligned.
With a twitch of my nose and a joyful leap,
I celebrate these updates in bounds so deep!
🐇✨

✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 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.
    • Generate unit testing code for this file.
    • 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 generate unit testing code for this file.
    • @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 generate unit testing code.
    • @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.

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 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.

Sorry, something went wrong.

@alexeyr-ci2 alexeyr-ci2 changed the title Move JS docs to the interface Move JS API docs to the interface Mar 20, 2025
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (3)
docs/api/javascript-api.md (1)

21-21: Consider linking directly to the relevant interface section.
The reference to interface ReactOnRails is helpful, but adding a direct anchor to the interface within index.ts (e.g. #L172) or relevant docs section can improve discoverability.

node_package/src/ReactOnRails.client.ts (1)

80-80: Enhanced flexibility with partial options.
Updating setOptions to accept a Partial<ReactOnRailsOptions> is a great approach for future scalability. However, ensure each provided option is validated to prevent misconfigurations.

Consider adding custom validations or logging warnings if unrecognized properties are passed.

node_package/src/types/index.ts (1)

245-348: Significant internal interface enhancements.
The ReactOnRailsInternal interface appears comprehensive, including advanced methods for store manipulation, server rendering, and RSC (React Server Components). Ensure that all internal logic aligns with these definitions, and consider any potential stability or security implications of exposing them.

Do you want me to open a new issue to outline best practices for safe usage of these internal methods?

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1fc6ce0 and 5029972.

📒 Files selected for processing (4)
  • docs/api/javascript-api.md (2 hunks)
  • node_package/src/ReactOnRails.client.ts (4 hunks)
  • node_package/src/context.ts (1 hunks)
  • node_package/src/types/index.ts (1 hunks)
🧰 Additional context used
🧠 Learnings (1)
node_package/src/ReactOnRails.client.ts (1)
Learnt from: AbanoubGhadban
PR: shakacode/react_on_rails#1644
File: node_package/src/clientStartup.ts:18-21
Timestamp: 2025-03-19T19:37:56.366Z
Learning: In the react_on_rails module, the `reactOnRailsPageUnloaded` function in clientStartup.ts is intentionally kept private as it's only used internally as a callback for `onPageUnloaded`.
🧬 Code Definitions (1)
node_package/src/ReactOnRails.client.ts (1)
node_package/src/types/index.ts (1) (1)
  • ReactOnRailsOptions (172-177)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: dummy-app-integration-tests (newest)
  • GitHub Check: dummy-app-integration-tests (oldest)
🔇 Additional comments (6)
node_package/src/context.ts (1)

1-1: Confirm correct usage of the internal interface.
The import now references ReactOnRailsInternal rather than ReactOnRails. While this might be necessary for deeper integration, ensure that the internal interface is indeed intended for broader usage. Internal APIs can introduce breaking changes more frequently.

Would you like to verify all references to this new import and confirm they match the intended interface usage?

node_package/src/ReactOnRails.client.ts (3)

18-18: Good addition of the explicit options type import.
Importing ReactOnRailsOptions clarifies type usage. Make sure to document or handle any future new fields in the ReactOnRailsOptions interface to avoid silent failures.


44-44: Removal of documentation comments.
The method signature is unchanged, but the in-code documentation may have been removed. If the doc removal is intentional, ensure the external docs provide adequate details.

Would you like to validate that developers can still find usage notes for this API in the updated docs?


124-124: Type-safe retrieval of options.
Using a generic to fetch typed options is a clean solution. Good improvement for type safety!

node_package/src/types/index.ts (2)

172-177: Well-defined interface for ReactOnRailsOptions.
Introducing ReactOnRailsOptions increases clarity around configurable properties. If new fields are added, ensure the rest of the code (like setOptions) is equipped to handle them.


180-243: Extended public interface documentation.
The expanded docstrings help clarify how to register components, stores, and generate or retrieve them. This is beneficial for developers interacting with ReactOnRails at a higher level.

@alexeyr-ci alexeyr-ci force-pushed the alexeyr/document-interface branch from 5029972 to 24603c3 Compare March 20, 2025 09:19
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (2)
node_package/src/types/index.ts (2)

186-194: Improved deprecation handling for registerStore

Good job marking the old method as deprecated while providing a new, more descriptive registerStoreGenerators method. Consider adding a @since tag to the JSDoc comment to indicate when this deprecation occurred.

-  /** @deprecated Use registerStoreGenerators instead */
+  /** 
+   * @deprecated Use registerStoreGenerators instead
+   * @since version X.Y.Z
+   */

205-210: New asynchronous store methods need more documentation

The new asynchronous methods getOrWaitForStore and getOrWaitForStoreGenerator would benefit from more detailed documentation about their timeout behavior, error handling, and how long they will wait.

  /**
   * Get a store by name, or wait for it to be registered.
+  * @param name The name of the store to retrieve
+  * @returns A Promise that resolves with the store or rejects if the store cannot be found after a timeout
+  * @throws Error if the store cannot be found after the timeout period
   */
  getOrWaitForStore(name: string): Promise<Store>;
  /**
   * Get a store generator by name, or wait for it to be registered.
+  * @param name The name of the store generator to retrieve
+  * @returns A Promise that resolves with the store generator or rejects if the generator cannot be found after a timeout
+  * @throws Error if the store generator cannot be found after the timeout period
   */
  getOrWaitForStoreGenerator(name: string): Promise<StoreGenerator>;
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5029972 and 24603c3.

📒 Files selected for processing (5)
  • docs/api/javascript-api.md (2 hunks)
  • node_package/src/ReactOnRails.client.ts (4 hunks)
  • node_package/src/ReactOnRails.full.ts (0 hunks)
  • node_package/src/context.ts (1 hunks)
  • node_package/src/types/index.ts (1 hunks)
💤 Files with no reviewable changes (1)
  • node_package/src/ReactOnRails.full.ts
🚧 Files skipped from review as they are similar to previous changes (3)
  • docs/api/javascript-api.md
  • node_package/src/context.ts
  • node_package/src/ReactOnRails.client.ts
🧰 Additional context used
🧬 Code Definitions (1)
node_package/src/types/index.ts (2)
node_package/src/StoreRegistry.ts (2) (2)
  • stores (94-96)
  • storeGenerators (86-88)
node_package/src/ReactOnRails.client.ts (2) (2)
  • stores (193-195)
  • storeGenerators (189-191)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: dummy-app-integration-tests (newest)
  • GitHub Check: dummy-app-integration-tests (oldest)
🔇 Additional comments (7)
node_package/src/types/index.ts (7)

172-177: Good addition of a dedicated options interface

Creating a dedicated ReactOnRailsOptions interface with proper documentation improves type safety and makes the configuration options more discoverable for developers.


214-215: Improved options API with Partial type

Updating setOptions to accept Partial<ReactOnRailsOptions> is a good change that allows for more flexible option updates without requiring all options to be specified.


245-246: Clear separation between public and internal APIs

Good job clearly documenting that the ReactOnRailsInternal interface is intended for internal use only. This helps developers understand which parts of the API are stable for external consumption.


251-253: Type-safe option getter with generics

The option<K extends keyof ReactOnRailsOptions> method is well-designed with generics to ensure type safety when retrieving specific options.


298-298: Making hydrate parameter optional is a good usability improvement

Updating the render method to make the hydrate parameter optional improves the API's usability while maintaining backward compatibility.


269-340: Comprehensive JSDoc documentation for internal methods

The addition of detailed JSDoc comments for internal methods significantly improves the codebase's maintainability. This aligns well with the PR objective of moving JS docs to the interface.


348-348:

✅ Verification successful

Updated options property type

Changing the options property from a generic record to the specific ReactOnRailsOptions type improves type safety and documentation.

Let's verify that this change is consistent with the implementation:


🏁 Script executed:

#!/bin/bash
# Check if the options property in ReactOnRails.client.ts has been updated to match
rg -A 2 "options\s*[:=]" --glob "*.ts" | grep -v "interface"

Length of output: 6057


Options Property Type Update Verified

The verification confirms that the change in the options property to use the specific ReactOnRailsOptions type in node_package/src/types/index.ts is consistent with the overall implementation. Usage in other files such as ReactOnRails.client.ts (where options are initialized via DEFAULT_OPTIONS) aligns with this updated type, ensuring improved type safety and documentation.

@alexeyr-ci alexeyr-ci force-pushed the alexeyr/document-interface branch from 24603c3 to a540c60 Compare March 20, 2025 09:26
@alexeyr-ci alexeyr-ci force-pushed the alexeyr/document-interface branch from a540c60 to 8d1cbd4 Compare March 20, 2025 09:32
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (2)
node_package/src/types/index.ts (2)

301-301: Consider adding railsContext parameter to render method

The render method doesn't include a railsContext parameter, which might be useful for consistency with other methods that accept railsContext.

- render(name: string, props: Record<string, string>, domNodeId: string, hydrate?: boolean): RenderReturnType;
+ render(name: string, props: Record<string, string>, domNodeId: string, hydrate?: boolean, railsContext?: RailsContext): RenderReturnType;

315-319: Document return values for server rendering methods

The serverRenderReactComponent and streamServerRenderedReactComponent methods would benefit from more detailed documentation about their return values.

Add return value documentation to these methods:

/**
 * Used by server rendering by Rails
+ * @returns null, string, or Promise<RenderResult> depending on the component and rendering process
 */
serverRenderReactComponent(options: RenderParams): null | string | Promise<RenderResult>;

/**
 * Used by server rendering by Rails
+ * @returns A Readable stream containing the rendered component
 */
streamServerRenderedReactComponent(options: RenderParams): Readable;
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a540c60 and 8d1cbd4.

📒 Files selected for processing (5)
  • docs/api/javascript-api.md (2 hunks)
  • node_package/src/ReactOnRails.client.ts (4 hunks)
  • node_package/src/ReactOnRails.full.ts (0 hunks)
  • node_package/src/context.ts (1 hunks)
  • node_package/src/types/index.ts (2 hunks)
💤 Files with no reviewable changes (1)
  • node_package/src/ReactOnRails.full.ts
🚧 Files skipped from review as they are similar to previous changes (3)
  • node_package/src/context.ts
  • node_package/src/ReactOnRails.client.ts
  • docs/api/javascript-api.md
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: dummy-app-integration-tests (oldest)
  • GitHub Check: dummy-app-integration-tests (newest)
🔇 Additional comments (12)
node_package/src/types/index.ts (12)

7-12: Great addition of JSDoc for the Store type

The JSDoc comment clearly explains why Redux isn't imported directly and provides helpful links to related issues and official Redux documentation.


175-180: Well-designed ReactOnRailsOptions interface

This new interface properly encapsulates configuration options with clear documentation for each property. The optional nature of these properties allows for backward compatibility.


183-188: Good JSDoc documentation for register method

The documentation clearly explains the purpose of this method and includes parameter information.


189-197: Appropriate method deprecation and replacement

The code correctly marks registerStore as deprecated and provides registerStoreGenerators as the alternative with detailed documentation.


198-205: Clear documentation for getStore method

The JSDoc comment effectively explains the purpose and return value of this method, with detailed parameter descriptions including optional parameters and their default values.


206-213: Well-documented Promise-based store methods

Both getOrWaitForStore and getOrWaitForStoreGenerator methods include concise documentation that clearly explains their asynchronous nature.


214-218: Good documentation for setOptions method

The JSDoc comment provides a clear explanation of the method's purpose and includes a reference to the options interface using @see.


219-226: Comprehensive documentation for reactHydrateOrRender

The documentation effectively explains the purpose of this method, includes parameter descriptions, and specifies the return type with version-specific behavior.


227-233: Helpful documentation for reactOnRailsPageLoaded

The documentation provides important context about when this method might be needed and includes a link to additional reading.


236-240: Clear documentation for authenticityToken method

Good JSDoc comment that explains the purpose of the method and its possible return values.


241-245: Well-documented authenticityHeaders method

The documentation clearly explains the method's purpose and parameters.


248-352: Well-structured ReactOnRailsInternal interface

The interface extends ReactOnRails and clearly identifies itself as intended for internal use. The documentation for each method is comprehensive and follows a consistent style. The included examples for the render method are particularly helpful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants