Skip to content

Make RSC tests await act #1734

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

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

Make RSC tests await act #1734

wants to merge 5 commits into from

Conversation

alexeyr-ci2
Copy link
Collaborator

@alexeyr-ci2 alexeyr-ci2 commented Apr 18, 2025

Summary

Tests in node_package/tests/RSCClientRoot.test.jsx were calling act without await, leading to these warnings:

You called act(async () => ...) without await. This could lead to unexpected testing behaviour, interleaving multiple act calls and mixing their scopes. You should - await act(async () => ...);

and

You seem to have overlapping act() calls, this is not supported. Be sure to await previous act() calls before making a new one.

Pull Request checklist


This change is Reviewable

Summary by CodeRabbit

  • New Features
    • Enhanced linting for test files by adding Testing Library's recommended rules for DOM testing.
  • Chores
    • Updated development dependencies, including adding Testing Library's ESLint plugin and upgrading TypeScript ESLint.
    • Improved package removal scripts for easier maintenance.
  • Refactor
    • Updated test suite naming and improved asynchronous handling in test execution for clearer and more reliable tests.
    • Improved test assertions for more precise and efficient element querying.
  • Documentation
    • Improved readability in documentation with spacing and formatting adjustments.

Copy link
Contributor

coderabbitai bot commented Apr 18, 2025

Walkthrough

The updates introduce the eslint-plugin-testing-library to the ESLint configuration for test files, adjust related dependencies in package.json, and streamline package removal logic in a script. Additionally, test files refactor asynchronous rendering logic for clarity and correctness and update test querying methods for better async handling.

Changes

File(s) Summary
eslint.config.ts Adds Testing Library's recommended DOM config to ESLint overrides for test files and disables no-node-access rule.
package.json Adds eslint-plugin-testing-library@7.5.3 and upgrades typescript-eslint to 8.35.0 in devDependencies.
script/convert Consolidates multiple regex-based package removals into broader patterns for ESLint and Testing Library.
node_package/tests/registerServerComponent.client.test.jsx Refactors test suite name and rendering logic to use async/await for component rendering in tests.
node_package/tests/SuspenseHydration.test.tsx Replaces waitFor + queryByText with findByText and getByText for more direct async and sync queries in tests.
docs/react-on-rails-pro/react-on-rails-pro.md Adds blank lines after section headers for improved readability.
docs/react-on-rails-pro/react-server-components.md Removes trailing blank lines and adjusts bullet point spacing without content changes.

Sequence Diagram(s)

sequenceDiagram
    participant TestFile
    participant ESLint
    participant TestingLibraryPlugin

    TestFile->>ESLint: Lint test files (*.test.{js,jsx,ts,tsx})
    ESLint->>TestingLibraryPlugin: Apply Testing Library DOM rules
    TestingLibraryPlugin-->>ESLint: Return linting results
    ESLint-->>TestFile: Report linting results
Loading
sequenceDiagram
    participant Test
    participant RenderFunction
    participant Component

    Test->>RenderFunction: await render()
    RenderFunction->>Component: Render asynchronously
    Component-->>RenderFunction: Rendering complete (Promise resolved)
    RenderFunction-->>Test: Continue test execution
Loading

Possibly related PRs

Suggested reviewers

  • AbanoubGhadban
  • Judahmeek

Poem

In the warren of code, a new plugin appears,
Testing Library hops in, calming linting fears.
Scripts now sweep with regex so wide,
While async tests render, no bugs left to hide.
With dependencies fresh and configs in sync,
This rabbit approves—no need to rethink! 🐇✨

✨ Finishing Touches
  • 📝 Generate Docstrings

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.

@alexeyr-ci alexeyr-ci force-pushed the alexeyr/fix-rsc-tests branch 5 times, most recently from 9ec8d5f to 11d72c2 Compare April 27, 2025 14:57
@alexeyr-ci2 alexeyr-ci2 marked this pull request as ready for review June 6, 2025 11:55
@alexeyr-ci alexeyr-ci force-pushed the alexeyr/fix-rsc-tests branch from e5700dc to a74f298 Compare June 7, 2025 14:27
@alexeyr-ci alexeyr-ci force-pushed the alexeyr/fix-rsc-tests branch from a74f298 to 82cf696 Compare June 29, 2025 09:44
@alexeyr-ci alexeyr-ci force-pushed the alexeyr/fix-rsc-tests branch from bd4c797 to 89593b1 Compare June 29, 2025 10:05
@alexeyr-ci alexeyr-ci force-pushed the alexeyr/fix-rsc-tests branch from 1b743d8 to 40b5df9 Compare June 29, 2025 10:13
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 (1)
docs/react-on-rails-pro/react-on-rails-pro.md (1)

19-21: Replace bare URL with markdown-formatted link to satisfy MD034

markdownlint is flagging the bare URL on line 21. Consistently using markdown links keeps the docs lint-clean and matches the surrounding style.

-See https://www.shakacode.com/react-on-rails-pro/docs/.
+See the full documentation [here](https://www.shakacode.com/react-on-rails-pro/docs/).
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 89593b1 and 40b5df9.

⛔ Files ignored due to path filters (1)
  • yarn.lock is excluded by !**/yarn.lock, !**/*.lock
📒 Files selected for processing (7)
  • docs/react-on-rails-pro/react-on-rails-pro.md (1 hunks)
  • docs/react-on-rails-pro/react-server-components.md (1 hunks)
  • eslint.config.ts (2 hunks)
  • node_package/tests/SuspenseHydration.test.tsx (2 hunks)
  • node_package/tests/registerServerComponent.client.test.jsx (5 hunks)
  • package.json (2 hunks)
  • script/convert (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • docs/react-on-rails-pro/react-server-components.md
🚧 Files skipped from review as they are similar to previous changes (5)
  • package.json
  • eslint.config.ts
  • node_package/tests/registerServerComponent.client.test.jsx
  • script/convert
  • node_package/tests/SuspenseHydration.test.tsx
🧰 Additional context used
🧠 Learnings (2)
📓 Common learnings
Learnt from: alexeyr-ci
PR: shakacode/react_on_rails#1644
File: node_package/src/ReactOnRailsRSC.ts:87-87
Timestamp: 2024-12-12T13:07:09.929Z
Learning: When handling errors in 'node_package/src/ReactOnRailsRSC.ts', include the error stack in error messages in development and test environments to aid debugging.
Learnt from: alexeyr-ci
PR: shakacode/react_on_rails#1687
File: spec/dummy/package.json:0-0
Timestamp: 2025-01-23T18:20:45.824Z
Learning: When adding or updating dependencies in spec/dummy/package.json, maintain version consistency with other package.json files in the codebase to avoid potential version conflicts.
docs/react-on-rails-pro/react-on-rails-pro.md (10)
Learnt from: alexeyr-ci2
PR: shakacode/react_on_rails#1732
File: spec/dummy/client/app-react16/startup/ReduxSharedStoreApp.client.jsx:40-44
Timestamp: 2025-04-26T21:55:55.874Z
Learning: In the react_on_rails project, files under `app-react16` directories are copied/moved to corresponding `/app` directories during the conversion process (removing the `-react16` suffix), which affects their relative import paths at runtime.
Learnt from: Romex91
PR: shakacode/react_on_rails#1697
File: package-scripts.yml:28-28
Timestamp: 2025-02-12T16:38:06.537Z
Learning: The file `node_package/lib/ReactOnRails.full.js` is autogenerated during the build process and should not be present in the repository.
Learnt from: AbanoubGhadban
PR: shakacode/react_on_rails#1644
File: lib/react_on_rails/helper.rb:190-197
Timestamp: 2025-02-18T13:08:01.477Z
Learning: RSC support validation in React on Rails Pro is handled through a chain of validations:
1. Pro version check in `run_stream_inside_fiber`
2. RSC support check during pack generation via `ReactOnRailsPro.configuration.enable_rsc_support`
3. RSC support validation during component registration
This makes additional validation in the helper methods unnecessary.
Learnt from: AbanoubGhadban
PR: shakacode/react_on_rails#1644
File: lib/react_on_rails/helper.rb:190-197
Timestamp: 2025-02-18T13:08:01.477Z
Learning: RSC support validation is handled in deeper level calls of the React on Rails Pro codebase, so it doesn't need to be validated again in the `rsc_payload_react_component` helper method.
Learnt from: AbanoubGhadban
PR: shakacode/react_on_rails#1644
File: node_package/src/clientStartup.ts:18-21
Timestamp: 2025-02-13T16:50:47.848Z
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`.
Learnt from: theforestvn88
PR: shakacode/react_on_rails#1620
File: spec/dummy/client/app/startup/HelloTurboStream.jsx:3-3
Timestamp: 2024-10-08T20:53:47.076Z
Learning: The `RailsContext` import in `spec/dummy/client/app/startup/HelloTurboStream.jsx` is used later in the project, as clarified by the user theforestvn88.
Learnt from: theforestvn88
PR: shakacode/react_on_rails#1620
File: spec/dummy/client/app/startup/HelloTurboStream.jsx:3-3
Timestamp: 2024-07-27T10:08:35.868Z
Learning: The `RailsContext` import in `spec/dummy/client/app/startup/HelloTurboStream.jsx` is used later in the project, as clarified by the user theforestvn88.
Learnt from: AbanoubGhadban
PR: shakacode/react_on_rails#1644
File: node_package/src/turbolinksUtils.ts:34-36
Timestamp: 2025-02-13T16:50:26.861Z
Learning: In React on Rails, when checking for Turbolinks version 5 using `turbolinksVersion5()`, always ensure `Turbolinks` exists first by checking `turbolinksInstalled()` to prevent TypeError when accessing properties.
Learnt from: AbanoubGhadban
PR: shakacode/react_on_rails#1696
File: node_package/src/RSCPayloadContainer.ts:0-0
Timestamp: 2025-04-09T12:56:10.756Z
Learning: In the react_on_rails codebase, RSC payloads are already stringified using `JSON.stringify()` before being processed by the `escapeScript` function, which handles escaping of special characters. The function only needs to handle specific HTML markers like comments and closing script tags.
Learnt from: alexeyr-ci
PR: shakacode/react_on_rails#1644
File: node_package/src/ReactOnRailsRSC.ts:87-87
Timestamp: 2024-12-12T13:07:09.929Z
Learning: When handling errors in 'node_package/src/ReactOnRailsRSC.ts', include the error stack in error messages in development and test environments to aid debugging.
🪛 markdownlint-cli2 (0.17.2)
docs/react-on-rails-pro/react-on-rails-pro.md

21-21: Bare URL used
null

(MD034, no-bare-urls)

⏰ Context from checks skipped due to timeout of 90000ms (5)
  • GitHub Check: dummy-app-integration-tests (oldest)
  • GitHub Check: dummy-app-integration-tests (newest)
  • GitHub Check: rspec-package-tests (newest)
  • GitHub Check: rspec-package-tests (oldest)
  • GitHub Check: build
🔇 Additional comments (1)
docs/react-on-rails-pro/react-on-rails-pro.md (1)

23-24: Spacing tweak looks good

Adding the blank line after the “Pro: React Server Components” header improves readability and keeps heading spacing consistent across the doc.

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.

2 participants