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

Update Helper to Check for Bundle with correct Extension #1511

Merged
merged 6 commits into from
Jan 28, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Changes since last non-beta release.

*Please add entries here for your pull requests that are not yet released.*
- Added `./bin/dev` and `./bin/dev-static` executables to ease and standardize running the dev server. [PR 1491](https://github.com/shakacode/react_on_rails/pull/1491) by [ahangarha](https://github.com/ahangarha)
- Fixed pack not found warning while using `react_component` and `react_component_hash` helpers, even when corresponding chunks are present. [PR 1511](https://github.com/shakacode/react_on_rails/pull/1511) by [pulkitkkr](https://github.com/pulkitkkr)

### [13.2.0] - 2022-12-23

Expand Down
9 changes: 5 additions & 4 deletions lib/react_on_rails/helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,7 @@ def react_component(component_name, options = {})
end

def load_pack_for_component(component_name)
Copy link
Member

Choose a reason for hiding this comment

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

why is this part of the public helper?

there's no doc for this method load_pack_for_component
or generated_components_pack_path

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It should be private member as it is used internally by react_component and react_component_hash

component_pack_file = generated_components_pack(component_name)
is_component_pack_present = File.exist?("#{component_pack_file}.jsx")
is_component_pack_present = File.exist?(generated_components_pack_path(component_name))
is_development = ENV["RAILS_ENV"] == "development"

if is_development && !is_component_pack_present
Expand All @@ -109,8 +108,10 @@ def load_pack_for_component(component_name)
append_stylesheet_pack_tag "generated/#{component_name}"
end

def generated_components_pack(component_name)
"#{ReactOnRails::WebpackerUtils.webpacker_source_entry_path}/generated/#{component_name}"
def generated_components_pack_path(component_name)
Copy link
Member

Choose a reason for hiding this comment

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

Should this be part of the helper? or not?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It should be a private member

extension = PacksGenerator.generated_pack_extension
Copy link
Member

Choose a reason for hiding this comment

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

Why is this customizable? Why not always .js?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's not configurable! It's always js

Copy link
Member

Choose a reason for hiding this comment

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

Then why not a constant?


"#{ReactOnRails::WebpackerUtils.webpacker_source_entry_path}/generated/#{component_name}.#{extension}"
end

# react_component_hash is used to return multiple HTML strings for server rendering, such as for
Expand Down
4 changes: 3 additions & 1 deletion lib/react_on_rails/packs_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
module ReactOnRails
# rubocop:disable Metrics/ClassLength
class PacksGenerator
mattr_reader :generated_pack_extension, default: "js"

CONTAINS_CLIENT_OR_SERVER_REGEX = /\.(server|client)($|\.)/.freeze
MINIMUM_SHAKAPACKER_MAJOR_VERSION = 6
MINIMUM_SHAKAPACKER_MINOR_VERSION = 5
Expand Down Expand Up @@ -152,7 +154,7 @@ def relative_path(from, to)
end

def generated_pack_path(file_path)
"#{generated_packs_directory_path}/#{component_name(file_path)}.js"
"#{generated_packs_directory_path}/#{component_name(file_path)}.#{generated_pack_extension}"
end

def component_name(file_path)
Expand Down