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

Add configurable loading strategy for generated component packs #1712

Merged

Conversation

AbanoubGhadban
Copy link
Collaborator

@AbanoubGhadban AbanoubGhadban commented Mar 9, 2025

  • Depreciate defer_generated_component_packs and added more flexible generated_component_packs_loading_strategy
  • Add support for :async, :defer, and :sync loading strategies
  • Validate loading strategy based on Shakapacker version
  • Update helper to support new loading strategy configuration
  • Add comprehensive specs for the new configuration option

Summary

Remove this paragraph and provide a general description of the code changes in your pull
request... were there any bugs you had fixed? If so, mention them. If
these bugs have open GitHub issues, be sure to tag them here as well,
to keep the conversation linked together.

Pull Request checklist

Remove this line after checking all the items here. If the item is not applicable to the PR, both check it out and wrap it by ~.

  • Add/update test to cover these changes
  • Update documentation
  • Update CHANGELOG file
    Add the CHANGELOG entry at the top of the file.

Other Information

Remove this paragraph and mention any other important and relevant information such as benchmarks.


This change is Reviewable

Summary by CodeRabbit

  • New Features

    • Introduced a new configuration option to control component script loading strategies (supporting synchronous, defer, and asynchronous modes) that replaces the previous legacy setting.
    • Enhanced component hydration by enabling immediate load by default.
  • Chores

    • Upgraded key dependencies for improved performance and compatibility.
  • Documentation

    • Updated release notes with detailed migration guidance for the new loading strategy configuration.

Copy link
Contributor

coderabbitai bot commented Mar 9, 2025

Walkthrough

This pull request adds a new step to several GitHub Actions workflows to set the CI_PACKER_VERSION environment variable by appending the current matrix version. It removes conditional logic for assigning packer versions in workflows, updates configuration options by replacing defer_generated_component_packs with generated_component_packs_loading_strategy, and adjusts related defaults and validations. Additionally, the PR upgrades the Shakapacker dependency from 8.0.0 to 8.2.0, updates documentation for these changes, and expands the test suite to cover the new behaviors.

Changes

Files Change Summary
.github/workflows/examples.yml, .github/workflows/main.yml, .github/workflows/rspec-package-specs.yml Added/updated a step to set CI_PACKER_VERSION based on the matrix version; removed conditional logic for its assignment.
CHANGELOG.md, docs/release-notes/15.0.0.md Added documentation for a new configuration option generated_component_packs_loading_strategy and removed defer_generated_component_packs with updated defaults and migration instructions.
Gemfile.development_dependencies, spec/dummy/package.json Upgraded the Shakapacker dependency version from 8.0.0 to 8.2.0.
lib/…/configuration.rb, lib/…/controller.rb, lib/…/helper.rb Refactored code by removing the deprecated option and adding generated_component_packs_loading_strategy, updated the redux_store method to include a force_load parameter, and adjusted script tag generation.
spec/dummy/spec/helpers/react_on_rails_helper_spec.rb, spec/react_on_rails/configuration_spec.rb, spec/react_on_rails/utils_spec.rb Expanded and adjusted tests to cover the new loading strategies, validate configuration changes, and update conditional logic for the CI_PACKER_VERSION variable.

Sequence Diagram(s)

Loading
sequenceDiagram
    participant Workflow as GitHub Actions Workflow
    participant Env as $GITHUB_ENV
    participant Test as RSpec Test Step

    Workflow->>Env: Append "CI_PACKER_VERSION=${{ matrix.versions }}"
    Env-->>Workflow: Updated environment variable
    Workflow->>Test: Execute tests using CI_PACKER_VERSION
Loading
sequenceDiagram
    participant Helper as ReactOnRails Helper
    participant Config as Configuration
    participant Renderer as JavaScript Pack Renderer

    Helper->>Config: Retrieve generated_component_packs_loading_strategy
    alt Strategy is :async
        Helper->>Renderer: Append pack tag with async attribute
    else Strategy is :defer
        Helper->>Renderer: Append pack tag with defer attribute
    else Strategy is :sync
        Helper->>Renderer: Append pack tag without async/defer attributes
    end

Possibly related PRs

Suggested reviewers

  • alexeyr-ci
  • Judahmeek

Poem

In the fields of code I hop along,
Setting variables with a cheerful song.
Packer versions dance in matrix light,
New strategies make my heart feel bright.
I nibble through changes with a playful bound,
Celebrating updates in leaps and bounds! 🐇🎉

✨ 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 plan to trigger planning for file edits and PR creation.
  • @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.

@AbanoubGhadban AbanoubGhadban requested review from Judahmeek, alexeyr-ci and justin808 and removed request for Judahmeek, alexeyr-ci and justin808 March 10, 2025 13:35
@AbanoubGhadban AbanoubGhadban force-pushed the abanoubghadban/pro521-add-support-for-async-scripts-in-the-view branch from c3eae47 to 781c2c1 Compare March 13, 2025 08:58
@AbanoubGhadban AbanoubGhadban changed the title [WIP] Add configurable loading strategy for generated component packs Add configurable loading strategy for generated component packs Mar 13, 2025
@AbanoubGhadban AbanoubGhadban marked this pull request as ready for review March 13, 2025 09:22
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)
script/convert (1)

24-24: Consider using a variable for version number.

The version "6.6.0" appears in multiple places in the script. Consider extracting this to a variable at the top of the file to make future version updates easier to maintain.

-gsub_file_content("../spec/dummy/package.json", /"shakapacker": "[^"]*",/, '"shakapacker": "6.6.0",')
+# At the top of the file
+SHAKAPACKER_VERSION = "6.6.0"
+
+# Then use it here
+gsub_file_content("../spec/dummy/package.json", /"shakapacker": "[^"]*",/, "\"shakapacker\": \"#{SHAKAPACKER_VERSION}\",")
CHANGELOG.md (1)

21-29: Well-documented breaking change.

The CHANGELOG clearly describes the new generated_component_packs_loading_strategy configuration option and marks the removal of defer_generated_component_packs as a breaking change. This provides users with clear migration instructions.

One suggestion: Consider adding a brief example of how to migrate from the old configuration to the new one to make the transition easier for users.

 - Removed `defer_generated_component_packs` configuration option. You can use `generated_component_packs_loading_strategy` instead. [PR 1712](https://github.com/shakacode/react_on_rails/pull/1712) by [AbanoubGhadban](https://github.com/AbanoubGhadban).
+
+#### Migration Example
+
+```ruby
+# Before
+config.defer_generated_component_packs = true
+
+# After
+config.generated_component_packs_loading_strategy = :defer # Or :async or :sync
+```
docs/release-notes/15.0.0.md (1)

43-43: Fix verb agreement in the configuration explanation.

There's a minor grammatical error in the sentence.

-  - The `force_load` configuration make `react-on-rails` hydrate components immediately as soon as their server-rendered HTML reaches the client, without waiting for the full page load.
+  - The `force_load` configuration makes `react-on-rails` hydrate components immediately as soon as their server-rendered HTML reaches the client, without waiting for the full-page load.
🧰 Tools
🪛 LanguageTool

[uncategorized] ~43-~43: This verb does not appear to agree with the subject. Consider using a different form.
Context: ...ded. - The force_load configuration make react-on-rails hydrate components imm...

(AI_EN_LECTOR_REPLACEMENT_VERB_AGREEMENT)


[uncategorized] ~43-~43: If this is a compound adjective that modifies the following noun, use a hyphen.
Context: ...hes the client, without waiting for the full page load. - If you want to keep the previ...

(EN_COMPOUND_ADJECTIVE_INTERNAL)

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 25ec8a9 and f8bee7e.

⛔ Files ignored due to path filters (3)
  • Gemfile.lock is excluded by !**/*.lock
  • spec/dummy/Gemfile.lock is excluded by !**/*.lock
  • spec/dummy/yarn.lock is excluded by !**/yarn.lock, !**/*.lock
📒 Files selected for processing (14)
  • .github/workflows/examples.yml (1 hunks)
  • .github/workflows/main.yml (1 hunks)
  • .github/workflows/rspec-package-specs.yml (1 hunks)
  • CHANGELOG.md (1 hunks)
  • Gemfile.development_dependencies (1 hunks)
  • docs/release-notes/15.0.0.md (2 hunks)
  • lib/react_on_rails/configuration.rb (6 hunks)
  • lib/react_on_rails/controller.rb (1 hunks)
  • lib/react_on_rails/helper.rb (1 hunks)
  • script/convert (1 hunks)
  • spec/dummy/package.json (1 hunks)
  • spec/dummy/spec/helpers/react_on_rails_helper_spec.rb (1 hunks)
  • spec/react_on_rails/configuration_spec.rb (2 hunks)
  • spec/react_on_rails/utils_spec.rb (1 hunks)
🧰 Additional context used
🪛 LanguageTool
docs/release-notes/15.0.0.md

[uncategorized] ~29-~29: If this is a compound adjective that modifies the following noun, use a hyphen.
Context: ...h Streamed HTML as it will wait for the full page load before hydrating the components) ...

(EN_COMPOUND_ADJECTIVE_INTERNAL)


[uncategorized] ~43-~43: This verb does not appear to agree with the subject. Consider using a different form.
Context: ...ded. - The force_load configuration make react-on-rails hydrate components imm...

(AI_EN_LECTOR_REPLACEMENT_VERB_AGREEMENT)


[uncategorized] ~43-~43: If this is a compound adjective that modifies the following noun, use a hyphen.
Context: ...hes the client, without waiting for the full page load. - If you want to keep the previ...

(EN_COMPOUND_ADJECTIVE_INTERNAL)

⏰ 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 (23)
Gemfile.development_dependencies (1)

3-3: Shakapacker version upgrade looks good

This update to shakapacker 8.2.0 aligns with the introduction of the new generated_component_packs_loading_strategy configuration option mentioned in the PR description.

spec/dummy/package.json (1)

53-53: Shakapacker version upgrade is consistent

The shakapacker NPM package update to version 8.2.0 correctly matches the version update in the Gemfile, ensuring consistency between Ruby and JavaScript dependencies.

.github/workflows/examples.yml (1)

91-93: Environment variable step simplification suggestion

The step for setting the CI_PACKER_VERSION environment variable looks good and ensures the appropriate packer version is available in the CI environment.

Consider simplifying to just:

- echo "CI_PACKER_VERSION=${{ matrix.versions }}" >> $GITHUB_ENV
+ CI_PACKER_VERSION=${{ matrix.versions }} >> $GITHUB_ENV
.github/workflows/rspec-package-specs.yml (1)

52-52: Improved environment variable setting

Using the matrix version directly as the CI_PACKER_VERSION is a good simplification from the previous conditional approach.

.github/workflows/main.yml (1)

193-195: Adding environment variable for Shakapacker version testing - good approach.

The addition of this step sets the CI_PACKER_VERSION environment variable based on the matrix version, which will be used to validate loading strategies against different Shakapacker versions. This is a clean implementation that properly integrates with the GitHub Actions workflow.

script/convert (1)

16-16: Improved version matching flexibility.

The updated regex pattern matches any version string rather than a hardcoded version, making the script more maintainable when the Shakapacker version changes in the future.

lib/react_on_rails/controller.rb (1)

15-19: Good enhancement to redux_store method.

Adding the force_load parameter with proper default handling improves the flexibility of the method. This change complements the new loading strategy configuration and maintains backward compatibility by defaulting to the global configuration when not specified.

spec/react_on_rails/utils_spec.rb (1)

13-15: Looks consistent with naming changes.

Renaming the environment condition to "oldest" and "newest" aligns with the updated workflows. The logic remains clear, and no issues stand out.

spec/dummy/spec/helpers/react_on_rails_helper_spec.rb (2)

53-59: Ensure test scenario coverage for other loading strategies.

This test checks "oldest" vs. everything else, implicitly treating all non-"oldest" versions as async. If you also support :sync or :defer in other contexts, consider adding a separate test branch here to solidify coverage of those scenarios.


63-105: Good approach to testing async and defer modes.

Redefining append_javascript_pack_tag to accept async: ensures backward compatibility checks with older Shakapacker versions. Restoring the original method within an ensure block prevents negative side effects on subsequent tests. No concerns here.

lib/react_on_rails/helper.rb (1)

425-430: Well-structured conditional assignment for script loading strategy.

Assigning defer and async based on generated_component_packs_loading_strategy is clear and maintains backward compatibility. The inline remark about older Shakapacker versions is helpful. Nothing to fix.

docs/release-notes/15.0.0.md (4)

24-32: Well-structured documentation for the new loading strategies feature.

The documentation clearly explains the three available loading strategies and their use cases. This will help users understand when to use each strategy based on their Shakapacker version.

🧰 Tools
🪛 LanguageTool

[uncategorized] ~29-~29: If this is a compound adjective that modifies the following noun, use a hyphen.
Context: ...h Streamed HTML as it will wait for the full page load before hydrating the components) ...

(EN_COMPOUND_ADJECTIVE_INTERNAL)


29-29: Consider updating the description of the :defer strategy.

There is a grammar issue with the description of the streamed HTML support.

-  - `:defer` - Defers script execution until after page load (Doesn't work well with Streamed HTML as it will wait for the full page load before hydrating the components)
+  - `:defer` - Defers script execution until after page load (Doesn't work well with Streamed HTML as it will wait for the full-page load before hydrating the components)
🧰 Tools
🪛 LanguageTool

[uncategorized] ~29-~29: If this is a compound adjective that modifies the following noun, use a hyphen.
Context: ...h Streamed HTML as it will wait for the full page load before hydrating the components) ...

(EN_COMPOUND_ADJECTIVE_INTERNAL)


37-40: Clear explanation of the breaking changes.

The documentation effectively communicates the removal of the deprecated option and the introduction of the new configuration option with its default values.


62-67: Clear migration instructions.

The migration section provides straightforward guidance for users transitioning from the old configuration to the new one. The recommendation to use :async for optimal performance with newer Shakapacker versions is helpful.

lib/react_on_rails/configuration.rb (6)

51-52: Good configuration structure for the new option.

Adding the new configuration option with a trailing comma for the previous option maintains consistent formatting.


67-68: Proper attribute accessibility for the new configuration option.

The attribute has been correctly added to the accessor list, maintaining alphabetical ordering.


79-80: Correctly replaced deprecated parameter in the initializer.

The defer_generated_component_packs parameter has been properly replaced with generated_component_packs_loading_strategy.


126-127: Added initialization for the new configuration option.

The new option is correctly initialized from the constructor parameter.


142-143: Added validation call for the new option.

The call to validate the new option has been properly added to the setup_config_values method.


155-179: Well-implemented validation for the loading strategy.

The validation logic is thorough, handling different Shakapacker versions appropriately:

  1. Sets :async as default for newer versions
  2. Sets :sync as default for older versions with a helpful warning
  3. Prevents using :async with older versions
  4. Validates that the strategy is one of the supported values

The error messages are clear and actionable, making it easy for users to fix configuration issues.

spec/react_on_rails/configuration_spec.rb (2)

268-269: Updated expectation count for method calls.

The expectation for shakapacker_version_requirement_met? has been updated from thrice to twice, which likely reflects changes in how this method is called due to the new configuration option.


281-368: Comprehensive test coverage for the new configuration option.

The tests thoroughly cover all aspects of the new loading strategy option:

  1. Defaults based on Shakapacker version
  2. Validation of accepted values
  3. Error handling for invalid values
  4. Warning messages for older Shakapacker versions

This ensures the configuration logic works correctly across different scenarios and version combinations.

@@ -12,9 +12,11 @@ module Controller
#
# Be sure to include view helper `redux_store_hydration_data` at the end of your layout or view
# or else there will be no client side hydration of your stores.
def redux_store(store_name, props: {})
def redux_store(store_name, props: {}, force_load: nil)
force_load = ReactOnRails.configuration.force_load if force_load.nil?
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This change should be part of #1644 PR, but seems we missed it

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: 1

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between f8bee7e and 4037425.

📒 Files selected for processing (1)
  • docs/release-notes/15.0.0.md (2 hunks)
🧰 Additional context used
🪛 LanguageTool
docs/release-notes/15.0.0.md

[uncategorized] ~29-~29: If this is a compound adjective that modifies the following noun, use a hyphen.
Context: ...h Streamed HTML as it will wait for the full page load before hydrating the components) ...

(EN_COMPOUND_ADJECTIVE_INTERNAL)


[uncategorized] ~43-~43: This verb does not appear to agree with the subject. Consider using a different form.
Context: ...ded. - The force_load configuration make react-on-rails hydrate components imm...

(AI_EN_LECTOR_REPLACEMENT_VERB_AGREEMENT)


[uncategorized] ~43-~43: If this is a compound adjective that modifies the following noun, use a hyphen.
Context: ...hes the client, without waiting for the full page load. - If you want to keep the previ...

(EN_COMPOUND_ADJECTIVE_INTERNAL)

⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: dummy-app-integration-tests (newest)
  • GitHub Check: dummy-app-integration-tests (oldest)
  • GitHub Check: rspec-package-tests (oldest)
  • GitHub Check: rspec-package-tests (newest)
🔇 Additional comments (2)
docs/release-notes/15.0.0.md (2)

24-32: Enhanced Script Loading Strategies Section: Clarity and Consistency
This new section clearly introduces the generated_component_packs_loading_strategy configuration and lists the three supported loading strategies. The bullet-point descriptions are informative.

  • Nitpick: Consider reviewing the phrase “Streamed HTML” in the description for :defer (line 29). Using a hyphen (e.g. “streamed-HTML”) might improve clarity when functioning as a compound adjective.
🧰 Tools
🪛 LanguageTool

[uncategorized] ~29-~29: If this is a compound adjective that modifies the following noun, use a hyphen.
Context: ...h Streamed HTML as it will wait for the full page load before hydrating the components) ...

(EN_COMPOUND_ADJECTIVE_INTERNAL)


62-67: Script Loading Strategy Migration Section: Clear Migration Guidelines
The migration instructions for users transitioning from defer_generated_component_packs to generated_component_packs_loading_strategy are concise and unambiguous. The mapping of previous boolean values to the new symbolic strategies is clearly outlined.

Copy link
Contributor

@Judahmeek Judahmeek left a comment

Choose a reason for hiding this comment

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

I'm pretty sure that Justin would prefer that you deprecate the defer configuration option instead of just replacing it, which would be a breaking change.

@alexeyr-ci2
Copy link
Collaborator

@Judahmeek

I'm pretty sure that Justin would prefer that you deprecate the defer configuration option instead of just replacing it, which would be a breaking change.

We are in 15.0 pre-release. Though it may indeed be preferable to deprecate it (and set _strategy from it if it is present) and remove in 16.0.0 instead.

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 (4)
CHANGELOG.md (1)

21-26: New Configuration Option Added: generated_component_packs_loading_strategy
The “Added” section now clearly documents that the new configuration option supports sync, async, and defer strategies. Please double-check that the wording is consistent with its usage throughout the codebase and consider including a brief example or note on why one should prefer the new option over the removed one.

docs/release-notes/15.0.0.md (3)

26-32: Detailed Explanation of New Loading Strategies
The bullet list thoroughly explains that the new generated_component_packs_loading_strategy replaces the deprecated option, and it enumerates the three strategies available:

  • :async for asynchronous loading (default on Shakapacker ≥ 8.2.0),
  • :defer (with a note about its suboptimal behavior with streamed HTML), and
  • :sync for synchronous loading (default on Shakapacker < 8.2.0).

A couple of minor suggestions:
• Consider rephrasing the description of the :defer option to clarify that its behavior—waiting until the full page load—may delay hydration on streamed pages.
• Verify whether any compound adjectives (such as “Streamed HTML”) require hyphenation for internal consistency, as flagged by static analysis.

🧰 Tools
🪛 LanguageTool

[uncategorized] ~29-~29: If this is a compound adjective that modifies the following noun, use a hyphen.
Context: ...h Streamed HTML as it will wait for the full page load before hydrating the components) ...

(EN_COMPOUND_ADJECTIVE_INTERNAL)


40-43: Explanation of Optimized Hydration Behavior
The explanation here elaborates how the new defaults (generated_component_packs_loading_strategy: :async and force_load: true) allow components to hydrate as soon as their code and server-rendered HTML are available. This detailed rationale is very helpful. For improved readability, consider splitting some of the longer sentences into shorter ones and reviewing any flagged compound adjective constructions for proper hyphenation.

🧰 Tools
🪛 LanguageTool

[uncategorized] ~43-~43: If this is a compound adjective that modifies the following noun, use a hyphen.
Context: ...hes the client, without waiting for the full page load. - If you want to keep the previ...

(EN_COMPOUND_ADJECTIVE_INTERNAL)


44-46: Migration Options for Preserving Previous Behavior
This section provides guidance for users wishing to replicate the old behavior by setting generated_component_packs_loading_strategy: :defer or toggling force_load to false. A few stylistic tweaks might improve clarity:
• Replace “If we want to keep” with “If you want to retain” for consistency.
• For the Redux store note, consider rephrasing to clarify that Redux stores now adopt the global force_load configuration by default, but you can override this on a per-store basis via the redux_store helper.

🧰 Tools
🪛 LanguageTool

[style] ~45-~45: You have already used this phrasing in nearby sentences. Consider replacing it to add variety to your writing.
Context: ...zers/react_on_rails.rbfile. - If we want to keep the original behavior offorce_lo...

(REP_WANT_TO_VB)


[uncategorized] ~46-~46: The grammatical number of this noun doesn’t look right. Consider replacing it.
Context: ...ce_loadconfiguration. - Redux store supportforce_loadoption now and it usesco...

(AI_EN_LECTOR_REPLACEMENT_NOUN_NUMBER)


[uncategorized] ~46-~46: Use a comma before ‘and’ if it connects two independent clauses (unless they are closely connected and short).
Context: ...ux store support force_load option now and it uses config.force_load value as th...

(COMMA_COMPOUND_SENTENCE)

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 4037425 and 27c7033.

📒 Files selected for processing (3)
  • CHANGELOG.md (1 hunks)
  • docs/release-notes/15.0.0.md (2 hunks)
  • lib/react_on_rails/configuration.rb (5 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • lib/react_on_rails/configuration.rb
🧰 Additional context used
🪛 LanguageTool
docs/release-notes/15.0.0.md

[uncategorized] ~29-~29: If this is a compound adjective that modifies the following noun, use a hyphen.
Context: ...h Streamed HTML as it will wait for the full page load before hydrating the components) ...

(EN_COMPOUND_ADJECTIVE_INTERNAL)


[uncategorized] ~43-~43: If this is a compound adjective that modifies the following noun, use a hyphen.
Context: ...hes the client, without waiting for the full page load. - If you want to keep the previ...

(EN_COMPOUND_ADJECTIVE_INTERNAL)

🔇 Additional comments (5)
CHANGELOG.md (1)

27-29: Deprecated Option Removed
The “Removed (Breaking Changes)” section effectively informs users that the deprecated defer_generated_component_packs option has been replaced. This is clear and well-documented—but ensure that the migration notes elsewhere (and in the release notes) explicitly guide users on what values to use as replacements.

docs/release-notes/15.0.0.md (4)

24-24: New Section Heading: "Enhanced Script Loading Strategies"
The new section heading immediately signals the introduction of the updated configuration option. This serves as a clear marker for users to learn about the new loading strategies.


37-39: Deprecation and Default Value Updates in Hydration Settings
This segment succinctly describes that:
• The old defer_generated_component_packs configuration is deprecated,
• The new option defaults to :async for Shakapacker ≥ 8.2.0 and to :sync for earlier versions, and
force_load now defaults to true.

These points are clearly stated and help users understand the breaking changes.


48-60: Updated Async Handling for reactOnRailsPageLoaded()
The explanation and code snippet clearly describe that ReactOnRails.reactOnRailsPageLoaded() is now asynchronous and must be awaited. The before-and-after examples will be very useful for developers updating their code.


62-67: Script Loading Strategy Migration Instructions
The migration section succinctly maps the old defer_generated_component_packs values to the new generated_component_packs_loading_strategy settings. The instructions are clear; you might consider adding a brief rationale for these mappings to further aid users in understanding the performance implications.

- Replace `defer_generated_component_packs` with more flexible `generated_component_packs_loading_strategy`
- Add support for `:async`, `:defer`, and `:sync` loading strategies
- Validate loading strategy based on Shakapacker version
- Update helper to support new loading strategy configuration
- Add comprehensive specs for the new configuration option
@AbanoubGhadban AbanoubGhadban force-pushed the abanoubghadban/pro521-add-support-for-async-scripts-in-the-view branch from 27c7033 to 0c50b80 Compare March 27, 2025 09:25
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)
spec/dummy/spec/helpers/react_on_rails_helper_spec.rb (1)

54-59: The conditional expectation adds complexity for CI version compatibility.

This conditional logic accommodates different behavior based on the Shakapacker version in the CI environment. The approach is sound, but consider adding a comment explaining why this conditional is necessary - it would make the test more maintainable for future developers.

  if ENV["CI_PACKER_VERSION"] == "oldest"
+   # Older Shakapacker versions don't support async loading, so we only check for defer: false
    expect(helper).to have_received(:append_javascript_pack_tag).with("generated/component_name", { defer: false })
  else
+   # Newer Shakapacker versions support async loading, so we check for both options
    expect(helper).to have_received(:append_javascript_pack_tag)
      .with("generated/component_name", { defer: false, async: true })
  end
docs/release-notes/15.0.0.md (1)

24-32: Good overview of the new loading strategies.

The documentation clearly explains the new configuration option and the three loading strategies. This is helpful for users to understand how to configure their applications.

On line 29, consider hyphenating "Streamed-HTML" as it's used as a compound adjective:

- `:defer` - Defers script execution until after page load (doesn't work well with Streamed HTML as it will wait for the full page load before hydrating the components)
+ `:defer` - Defers script execution until after page load (doesn't work well with Streamed-HTML as it will wait for the full page load before hydrating the components)
🧰 Tools
🪛 LanguageTool

[uncategorized] ~29-~29: If this is a compound adjective that modifies the following noun, use a hyphen.
Context: ...h Streamed HTML as it will wait for the full page load before hydrating the components) ...

(EN_COMPOUND_ADJECTIVE_INTERNAL)

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 27c7033 and 0c50b80.

⛔ Files ignored due to path filters (3)
  • Gemfile.lock is excluded by !**/*.lock
  • spec/dummy/Gemfile.lock is excluded by !**/*.lock
  • spec/dummy/yarn.lock is excluded by !**/yarn.lock, !**/*.lock
📒 Files selected for processing (13)
  • .github/workflows/examples.yml (1 hunks)
  • .github/workflows/main.yml (1 hunks)
  • .github/workflows/rspec-package-specs.yml (1 hunks)
  • CHANGELOG.md (1 hunks)
  • Gemfile.development_dependencies (1 hunks)
  • docs/release-notes/15.0.0.md (2 hunks)
  • lib/react_on_rails/configuration.rb (5 hunks)
  • lib/react_on_rails/controller.rb (1 hunks)
  • lib/react_on_rails/helper.rb (1 hunks)
  • spec/dummy/package.json (1 hunks)
  • spec/dummy/spec/helpers/react_on_rails_helper_spec.rb (1 hunks)
  • spec/react_on_rails/configuration_spec.rb (2 hunks)
  • spec/react_on_rails/utils_spec.rb (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (10)
  • spec/dummy/package.json
  • spec/react_on_rails/utils_spec.rb
  • .github/workflows/examples.yml
  • .github/workflows/rspec-package-specs.yml
  • CHANGELOG.md
  • Gemfile.development_dependencies
  • .github/workflows/main.yml
  • lib/react_on_rails/controller.rb
  • lib/react_on_rails/helper.rb
  • lib/react_on_rails/configuration.rb
🧰 Additional context used
🧬 Code Definitions (1)
spec/dummy/spec/helpers/react_on_rails_helper_spec.rb (2)
lib/react_on_rails/configuration.rb (1)
  • configuration (15-55)
lib/react_on_rails/helper.rb (1)
  • load_pack_for_generated_component (417-433)
🪛 LanguageTool
docs/release-notes/15.0.0.md

[uncategorized] ~29-~29: If this is a compound adjective that modifies the following noun, use a hyphen.
Context: ...h Streamed HTML as it will wait for the full page load before hydrating the components) ...

(EN_COMPOUND_ADJECTIVE_INTERNAL)


[uncategorized] ~43-~43: If this is a compound adjective that modifies the following noun, use a hyphen.
Context: ...hes the client, without waiting for the full page load. - If you want to keep the previ...

(EN_COMPOUND_ADJECTIVE_INTERNAL)

⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: build-dummy-app-webpack-test-bundles (newest)
  • GitHub Check: build
  • GitHub Check: rspec-package-tests (newest)
  • GitHub Check: rspec-package-tests (oldest)
🔇 Additional comments (6)
spec/dummy/spec/helpers/react_on_rails_helper_spec.rb (2)

69-78: Nice technique for temporarily redefining the method.

The temporary method redefinition approach is a good solution for testing with older Shakapacker versions that may not support the async option. The comments explain the need clearly, and the implementation with begin/ensure block ensures proper cleanup.


93-105: Well-structured test for defer loading strategy.

The defer loading test is straightforward and properly tests that the correct loading attribute is passed to the script tag. The before block to set up the configuration and the expectations are clear and concise.

docs/release-notes/15.0.0.md (2)

37-44: Clear explanation of breaking changes.

The explanation of the breaking changes is thorough and provides important context about why the changes were made and how they improve component hydration.

🧰 Tools
🪛 LanguageTool

[uncategorized] ~43-~43: If this is a compound adjective that modifies the following noun, use a hyphen.
Context: ...hes the client, without waiting for the full page load. - If you want to keep the previ...

(EN_COMPOUND_ADJECTIVE_INTERNAL)


65-70: Helpful migration guide.

The migration instructions provide clear guidance on how to transition from the deprecated defer_generated_component_packs to the new generated_component_packs_loading_strategy. This will help users adopt the new configuration option more easily.

spec/react_on_rails/configuration_spec.rb (2)

268-269: Updated expectation count for calls to the shakapacker_version_requirement_met? method.

The change from expecting three calls to two calls to shakapacker_version_requirement_met? is appropriate. This adjustment aligns with changes in the implementation where one of the checks was likely consolidated or removed.


281-368: Comprehensive test coverage for the new loading strategy configuration.

The tests thoroughly cover all aspects of the new generated_component_packs_loading_strategy configuration:

  1. Default values for different Shakapacker versions
  2. Validation of valid configuration values
  3. Error handling for invalid values
  4. Version-specific behavior (e.g., rejecting :async for older versions)
  5. Warning logging when appropriate

The test suite is well-structured with clear context separation and covers both the happy path and error cases. This ensures the new configuration option behaves correctly across different environments and configurations.

@Judahmeek Judahmeek merged commit bc90695 into master Mar 27, 2025
11 checks passed
@Judahmeek Judahmeek deleted the abanoubghadban/pro521-add-support-for-async-scripts-in-the-view branch March 27, 2025 15:38
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