Skip to content

Switch from Net::HTTP to HTTPX for communication with Node renderer#452

Merged
alexeyr-ci merged 14 commits intomasterfrom
alexeyr/httpx
Nov 18, 2024
Merged

Switch from Net::HTTP to HTTPX for communication with Node renderer#452
alexeyr-ci merged 14 commits intomasterfrom
alexeyr/httpx

Conversation

@alexeyr-ci
Copy link
Copy Markdown
Contributor

@alexeyr-ci alexeyr-ci commented Nov 7, 2024

To prepare for HTTP/2 support, we need to switch to a new HTTP client library on the Ruby side.

Extracted from #392.

Summary by CodeRabbit

Release Notes

  • New Features

    • Added support for streaming server rendering, enhancing performance for server-rendered React components.
    • Introduced functionality for replaying console logs during server rendering for improved debugging.
    • Enhanced error handling for server rendering with new configuration options.
    • Improved handling of multipart and form data for file uploads.
  • Bug Fixes

    • Improved handling of HTTP request errors and response status checks.
  • Documentation

    • Updated configuration documentation for clarity on timeout settings.
  • Chores

    • Updated dependencies and removed support for outdated versions.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Nov 7, 2024

Walkthrough

The pull request introduces several significant updates to the react_on_rails_pro gem and its associated components. Key changes include the addition of new helper methods for streaming server rendering, improved error handling during server rendering, and the transition from Net::HTTP to HTTPX for HTTP requests. The documentation has been updated for clarity, and the gemspec reflects changes in dependencies. Additionally, the test suite has been adjusted to accommodate these modifications, ensuring robust testing of the new functionalities.

Changes

File Change Summary
CHANGELOG.md Updated to include new features like stream_view_containing_react_components, improved error handling options, and removal of outdated Ruby and React on Rails versions.
docs/configuration.md Comments updated for clarity on renderer_http_pool_timeout and renderer_http_pool_warn_timeout.
lib/react_on_rails_pro/request.rb Replaced net/http with httpx, updated method signatures for clarity, refined error handling, and improved connection management.
lib/react_on_rails_pro/server_rendering_pool/node_rendering_pool.rb Changed status checks from string to numeric for response handling in eval_js.
package.json Added dependency @fastify/formbody version ^7.4.0.
packages/node-renderer/src/worker.ts Introduced fastifyFormbody plugin for better form data handling and extended MultipartFile interface.
react_on_rails_pro.gemspec Updated dependencies: removed multipart-post and persistent_http, added httpx.
spec/dummy/spec/helpers/react_on_rails_pro_helper_spec.rb Updated to use HTTPX::StreamResponse for streaming HTTP responses and refined error handling in caching methods.
spec/dummy/spec/requests/upload_asset_spec.rb Enhanced test configurations and updated response handling expectations to use numeric status codes.
spec/dummy/spec/spec_helper.rb Added webmock and httpx/adapters/webmock for HTTP request stubbing, updated configuration settings.
lib/react_on_rails_pro/stream_request.rb Refined each_chunk method for better response processing and enhanced error handling.
lib/react_on_rails_pro.rb Updated require statement from react_on_rails_pro/version to react_on_rails_pro/constants.
lib/react_on_rails_pro/constants.rb Introduced constants STATUS_SEND_BUNDLE and STATUS_INCOMPATIBLE for status code handling.

Poem

🐇 In the land of code, where rabbits hop,
New features bloom, and errors stop.
With streams of joy and helpers bright,
We render our dreams, oh what a sight!
From HTTP to HTTPX, we leap with glee,
Celebrating changes, come dance with me! 🎉


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 0ae9bdf and 2535959.

⛔ Files ignored due to path filters (5)
  • Gemfile.lock is excluded by !**/*.lock
  • spec/dummy/Gemfile.lock is excluded by !**/*.lock
  • spec/dummy/yarn.lock is excluded by !**/yarn.lock, !**/*.lock
  • spec/execjs-compatible-dummy/Gemfile.lock is excluded by !**/*.lock
  • yarn.lock is excluded by !**/yarn.lock, !**/*.lock
📒 Files selected for processing (13)
  • CHANGELOG.md (1 hunks)
  • docs/configuration.md (1 hunks)
  • lib/react_on_rails_pro.rb (1 hunks)
  • lib/react_on_rails_pro/constants.rb (1 hunks)
  • lib/react_on_rails_pro/request.rb (4 hunks)
  • lib/react_on_rails_pro/server_rendering_pool/node_rendering_pool.rb (1 hunks)
  • lib/react_on_rails_pro/stream_request.rb (1 hunks)
  • package.json (1 hunks)
  • packages/node-renderer/src/worker.ts (2 hunks)
  • react_on_rails_pro.gemspec (1 hunks)
  • spec/dummy/spec/helpers/react_on_rails_pro_helper_spec.rb (1 hunks)
  • spec/dummy/spec/requests/upload_asset_spec.rb (2 hunks)
  • spec/dummy/spec/spec_helper.rb (2 hunks)

Note

🎁 Summarized by CodeRabbit Free

Your organization is on the Free plan. CodeRabbit will generate a high-level summary and a walkthrough for each pull request. For a comprehensive line-by-line review, please upgrade your subscription to CodeRabbit Pro by visiting https://app.coderabbit.ai/login.

🪧 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 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 changed the title Switch from Net::HTTP to HTTPX for communication with Node renderer [WIP] Switch from Net::HTTP to HTTPX for communication with Node renderer Nov 7, 2024
@alexeyr-ci alexeyr-ci force-pushed the alexeyr/httpx branch 12 times, most recently from 665f102 to 826d57b Compare November 9, 2024 13:25
Comment thread CHANGELOG.md Outdated
Comment thread lib/react_on_rails_pro/request.rb Outdated
# :request_timeout
# :operation_timeout
# :keep_alive_timeout
# TODO: Do we want to add config for them?
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Or set request_timeout (total time to write the request and read the response) instead of read_timeout for ssr_timeout?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We can keep the same timeouts. Do you have a reason to set a timeout for the whole request instead of read_timeout?

Copy link
Copy Markdown
Contributor Author

@alexeyr-ci alexeyr-ci Nov 17, 2024

Choose a reason for hiding this comment

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

It depends on how we count time for SSR: the total time from RoRP, or only the time in the Node renderer? For Net::HTTP it just wasn't an option, I think.

Comment thread lib/react_on_rails_pro/constants.rb
@alexeyr-ci alexeyr-ci mentioned this pull request Nov 10, 2024
@alexeyr-ci
Copy link
Copy Markdown
Contributor Author

@coderabbitai full review

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Nov 10, 2024

✅ Actions performed

Full review triggered.

Comment thread lib/react_on_rails_pro.rb
Comment thread spec/dummy/spec/spec_helper.rb Outdated
end

config.before(:suite) do
ReactOnRailsPro::Request.reset_connection
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Could do both in a single before hook.

end
stream_response = @request_executor.call(send_bundle)
# stream_response.each may yield merged chunks, but the real chunks are separated by newlines.
stream_response.each_line do |chunk|
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

If the chunk separator is changed or if the chunk is allowed to contain new lines, how should we iterate over chunks in this case?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

We can use each instead of each_line to iterate over the (possibly merged?) chunks.

Copy link
Copy Markdown
Contributor Author

@alexeyr-ci alexeyr-ci Nov 17, 2024

Choose a reason for hiding this comment

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

Question because I don't know if HTTPX will actually merge chunks like that or if it keeps track of the original chunks.

Copy link
Copy Markdown
Contributor

@AbanoubGhadban AbanoubGhadban Nov 18, 2024

Choose a reason for hiding this comment

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

Merging chunks is no problem; we use a separator. FYI, the node-renderer already merges chunks when more than one chunk is generated simultaneously.

Comment thread packages/node-renderer/src/worker.ts
Copy link
Copy Markdown
Contributor

@AbanoubGhadban AbanoubGhadban left a comment

Choose a reason for hiding this comment

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

Good work. I just have some questions and a small change request

@alexeyr-ci alexeyr-ci force-pushed the alexeyr/httpx branch 2 times, most recently from fc585d3 to 7912c52 Compare November 17, 2024 17:30
@alexeyr-ci alexeyr-ci merged commit 3463edd into master Nov 18, 2024
@alexeyr-ci alexeyr-ci deleted the alexeyr/httpx branch November 18, 2024 19:11
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.

3 participants