Skip to content

Commit 9601c37

Browse files
Move Pro Ruby code to MIT license
Moved lib/react_on_rails/pro/ code to MIT-licensed locations: - lib/react_on_rails/pro/helper.rb → lib/react_on_rails/pro_helper.rb - lib/react_on_rails/pro/utils.rb → lib/react_on_rails/pro_utils.rb Changes: - Removed Pro license headers from moved files - Changed namespace from ReactOnRails::Pro:: to ReactOnRails:: - Removed Pro warning badge functionality (no longer needed) - Deleted lib/react_on_rails/pro/ directory entirely - Updated LICENSE.md to reflect all lib/react_on_rails/ is MIT - Updated documentation references Benefits: - Ruby signaling code now in MIT gem for marketing visibility - Actual functionality still requires Pro npm package - Clean license boundaries maintained - Users can't bypass Pro features by editing Ruby code
1 parent 7bce94a commit 9601c37

File tree

9 files changed

+106
-204
lines changed

9 files changed

+106
-204
lines changed

LICENSE.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,14 @@ This repository contains code under two different licenses:
1111

1212
The following directories and all their contents are licensed under the **MIT License** (see full text below):
1313

14-
- `lib/react_on_rails/` (excluding `lib/react_on_rails/pro/`)
14+
- `lib/react_on_rails/` (entire directory)
1515
- `packages/react-on-rails/` (entire package)
1616
- All other directories in this repository not explicitly listed as Pro-licensed
1717

1818
### Pro Licensed Code
1919

2020
The following directories and all their contents are licensed under the **React on Rails Pro License**:
2121

22-
- `lib/react_on_rails/pro/`
2322
- `packages/react-on-rails-pro/` (entire package)
2423
- `react_on_rails_pro/` (entire directory)
2524

docs/MONOREPO_MERGER_PLAN.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -372,12 +372,11 @@ After the initial merge, the following CI adjustments may be needed:
372372
```md
373373
## MIT License applies to:
374374

375-
- `lib/react_on_rails/` (excluding `lib/react_on_rails/pro/`)
375+
- `lib/react_on_rails/` (entire directory)
376376
- `packages/react-on-rails/` (entire package)
377377

378378
## React on Rails Pro License applies to:
379379

380-
- `lib/react_on_rails/pro/`
381380
- `packages/react-on-rails-pro/` (entire package)
382381
- `react_on_rails_pro/` (entire directory)
383382
```

lib/react_on_rails/helper.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@
1111
require "react_on_rails/utils"
1212
require "react_on_rails/json_output"
1313
require "active_support/concern"
14-
require "react_on_rails/pro/helper"
14+
require "react_on_rails/pro_helper"
1515

1616
module ReactOnRails
1717
module Helper
1818
include ReactOnRails::Utils::Required
19-
include ReactOnRails::Pro::Helper
19+
include ReactOnRails::ProHelper
2020

2121
COMPONENT_HTML_KEY = "componentHtml"
2222

lib/react_on_rails/pro/NOTICE

Lines changed: 0 additions & 21 deletions
This file was deleted.

lib/react_on_rails/pro/helper.rb

Lines changed: 0 additions & 122 deletions
This file was deleted.

lib/react_on_rails/pro/utils.rb

Lines changed: 0 additions & 53 deletions
This file was deleted.

lib/react_on_rails/pro_helper.rb

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# frozen_string_literal: true
2+
3+
module ReactOnRails
4+
module ProHelper
5+
# Generates the complete component specification script tag.
6+
# Handles both immediate hydration (Pro feature) and standard cases.
7+
def generate_component_script(render_options)
8+
# Setup the page_loaded_js, which is the same regardless of prerendering or not!
9+
# The reason is that React is smart about not doing extra work if the server rendering did its job.
10+
component_specification_tag = content_tag(:script,
11+
json_safe_and_pretty(render_options.client_props).html_safe,
12+
type: "application/json",
13+
class: "js-react-on-rails-component",
14+
id: "js-react-on-rails-component-#{render_options.dom_id}",
15+
"data-component-name" => render_options.react_component_name,
16+
"data-trace" => (render_options.trace ? true : nil),
17+
"data-dom-id" => render_options.dom_id,
18+
"data-store-dependencies" =>
19+
render_options.store_dependencies&.to_json,
20+
"data-immediate-hydration" =>
21+
(render_options.immediate_hydration ? true : nil))
22+
23+
# Add immediate invocation script if immediate hydration is enabled
24+
if render_options.immediate_hydration
25+
# Escape dom_id for JavaScript context
26+
escaped_dom_id = escape_javascript(render_options.dom_id)
27+
immediate_script = content_tag(:script, %(
28+
typeof ReactOnRails === 'object' && ReactOnRails.reactOnRailsComponentLoaded('#{escaped_dom_id}');
29+
).html_safe)
30+
"#{component_specification_tag}\n#{immediate_script}".html_safe
31+
else
32+
component_specification_tag
33+
end
34+
end
35+
36+
# Generates the complete store hydration script tag.
37+
# Handles both immediate hydration (Pro feature) and standard cases.
38+
def generate_store_script(redux_store_data)
39+
pro_options_check_result = ReactOnRails::ProUtils.disable_pro_render_options_if_not_licensed(redux_store_data)
40+
redux_store_data = pro_options_check_result[:raw_options]
41+
42+
store_hydration_data = content_tag(:script,
43+
json_safe_and_pretty(redux_store_data[:props]).html_safe,
44+
type: "application/json",
45+
"data-js-react-on-rails-store" => redux_store_data[:store_name].html_safe,
46+
"data-immediate-hydration" =>
47+
(redux_store_data[:immediate_hydration] ? true : nil))
48+
49+
# Add immediate invocation script if immediate hydration is enabled and Pro license is valid
50+
if redux_store_data[:immediate_hydration]
51+
# Escape store_name for JavaScript context
52+
escaped_store_name = escape_javascript(redux_store_data[:store_name])
53+
immediate_script = content_tag(:script, <<~JS.strip_heredoc.html_safe
54+
typeof ReactOnRails === 'object' && ReactOnRails.reactOnRailsStoreLoaded('#{escaped_store_name}');
55+
JS
56+
)
57+
"#{store_hydration_data}\n#{immediate_script}".html_safe
58+
else
59+
store_hydration_data
60+
end
61+
end
62+
end
63+
end

lib/react_on_rails/pro_utils.rb

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# frozen_string_literal: true
2+
3+
module ReactOnRails
4+
module ProUtils
5+
PRO_ONLY_OPTIONS = %i[immediate_hydration].freeze
6+
7+
# Checks if React on Rails Pro features are available
8+
# @return [Boolean] true if Pro license is valid, false otherwise
9+
def self.support_pro_features?
10+
ReactOnRails::Utils.react_on_rails_pro_licence_valid?
11+
end
12+
13+
def self.disable_pro_render_options_if_not_licensed(raw_options)
14+
if support_pro_features?
15+
return {
16+
raw_options: raw_options,
17+
explicitly_disabled_pro_options: []
18+
}
19+
end
20+
21+
raw_options_after_disable = raw_options.dup
22+
23+
explicitly_disabled_pro_options = PRO_ONLY_OPTIONS.select do |option|
24+
# Use global configuration if it's not overridden in the options
25+
next ReactOnRails.configuration.send(option) if raw_options[option].nil?
26+
27+
raw_options[option]
28+
end
29+
explicitly_disabled_pro_options.each { |option| raw_options_after_disable[option] = false }
30+
31+
{
32+
raw_options: raw_options_after_disable,
33+
explicitly_disabled_pro_options: explicitly_disabled_pro_options
34+
}
35+
end
36+
end
37+
end

lib/react_on_rails/react_component/render_options.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# frozen_string_literal: true
22

33
require "react_on_rails/utils"
4-
require "react_on_rails/pro/utils"
4+
require "react_on_rails/pro_utils"
55

66
module ReactOnRails
77
module ReactComponent
@@ -16,7 +16,7 @@ class RenderOptions
1616
def initialize(react_component_name: required("react_component_name"), options: required("options"))
1717
@react_component_name = react_component_name.camelize
1818

19-
result = ReactOnRails::Pro::Utils.disable_pro_render_options_if_not_licensed(options)
19+
result = ReactOnRails::ProUtils.disable_pro_render_options_if_not_licensed(options)
2020
@options = result[:raw_options]
2121
@explicitly_disabled_pro_options = result[:explicitly_disabled_pro_options]
2222
end

0 commit comments

Comments
 (0)