Skip to content

Commit 4d2ca7f

Browse files
Revert previous two commits to preserve Pro warning badge
1 parent a7fccea commit 4d2ca7f

File tree

10 files changed

+356
-106
lines changed

10 files changed

+356
-106
lines changed

LICENSE.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,15 @@ 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/` (entire directory)
14+
- `lib/react_on_rails/` (excluding `lib/react_on_rails/pro/`)
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/`
2223
- `packages/react-on-rails-pro/` (entire package)
2324
- `react_on_rails_pro/` (entire directory)
2425

docs/MONOREPO_MERGER_PLAN.md

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

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

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

380+
- `lib/react_on_rails/pro/`
380381
- `packages/react-on-rails-pro/` (entire package)
381382
- `react_on_rails_pro/` (entire directory)
382383
```

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::ProHelper
19+
include ReactOnRails::Pro::Helper
2020

2121
COMPONENT_HTML_KEY = "componentHtml"
2222

lib/react_on_rails/pro/NOTICE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# React on Rails Pro License
2+
3+
The files in this directory and its subdirectories are licensed under the **React on Rails Pro** license, which is separate from the MIT license that covers the core React on Rails functionality.
4+
5+
## License Terms
6+
7+
These files are proprietary software and are **NOT** covered by the MIT license found in the root LICENSE.md file. Usage requires a valid React on Rails Pro license.
8+
9+
## Distribution
10+
11+
Files in this directory will be **omitted** from future distributions of the open source React on Rails Ruby gem. They are exclusively available to React on Rails Pro licensees.
12+
13+
## License Reference
14+
15+
For the complete React on Rails Pro license terms, see: `REACT-ON-RAILS-PRO-LICENSE.md` in the root directory of this repository.
16+
17+
## More Information
18+
19+
For React on Rails Pro licensing information and to obtain a license, please visit:
20+
- [React on Rails Pro](https://www.shakacode.com/react-on-rails-pro/)
21+

lib/react_on_rails/pro/helper.rb

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
# frozen_string_literal: true
2+
3+
# /*
4+
# * Copyright (c) 2025 Shakacode LLC
5+
# *
6+
# * This file is NOT licensed under the MIT (open source) license.
7+
# * It is part of the React on Rails Pro offering and is licensed separately.
8+
# *
9+
# * Unauthorized copying, modification, distribution, or use of this file,
10+
# * via any medium, is strictly prohibited without a valid license agreement
11+
# * from Shakacode LLC.
12+
# *
13+
# * For licensing terms, please see:
14+
# * https://github.com/shakacode/react_on_rails/blob/master/REACT-ON-RAILS-PRO-LICENSE.md
15+
# */
16+
17+
module ReactOnRails
18+
module Pro
19+
module Helper
20+
IMMEDIATE_HYDRATION_PRO_WARNING = "[REACT ON RAILS] The 'immediate_hydration' feature requires a " \
21+
"React on Rails Pro license. " \
22+
"Please visit https://shakacode.com/react-on-rails-pro to learn more."
23+
24+
# Generates the complete component specification script tag.
25+
# Handles both immediate hydration (Pro feature) and standard cases.
26+
def generate_component_script(render_options)
27+
# Setup the page_loaded_js, which is the same regardless of prerendering or not!
28+
# The reason is that React is smart about not doing extra work if the server rendering did its job.
29+
component_specification_tag = content_tag(:script,
30+
json_safe_and_pretty(render_options.client_props).html_safe,
31+
type: "application/json",
32+
class: "js-react-on-rails-component",
33+
id: "js-react-on-rails-component-#{render_options.dom_id}",
34+
"data-component-name" => render_options.react_component_name,
35+
"data-trace" => (render_options.trace ? true : nil),
36+
"data-dom-id" => render_options.dom_id,
37+
"data-store-dependencies" =>
38+
render_options.store_dependencies&.to_json,
39+
"data-immediate-hydration" =>
40+
(render_options.immediate_hydration ? true : nil))
41+
42+
# Add immediate invocation script if immediate hydration is enabled
43+
spec_tag = if render_options.immediate_hydration
44+
# Escape dom_id for JavaScript context
45+
escaped_dom_id = escape_javascript(render_options.dom_id)
46+
immediate_script = content_tag(:script, %(
47+
typeof ReactOnRails === 'object' && ReactOnRails.reactOnRailsComponentLoaded('#{escaped_dom_id}');
48+
).html_safe)
49+
"#{component_specification_tag}\n#{immediate_script}"
50+
else
51+
component_specification_tag
52+
end
53+
54+
pro_warning_badge = pro_warning_badge_if_needed(render_options.explicitly_disabled_pro_options)
55+
"#{pro_warning_badge}\n#{spec_tag}".html_safe
56+
end
57+
58+
# Generates the complete store hydration script tag.
59+
# Handles both immediate hydration (Pro feature) and standard cases.
60+
def generate_store_script(redux_store_data)
61+
pro_options_check_result = ReactOnRails::Pro::Utils.disable_pro_render_options_if_not_licensed(redux_store_data)
62+
redux_store_data = pro_options_check_result[:raw_options]
63+
explicitly_disabled_pro_options = pro_options_check_result[:explicitly_disabled_pro_options]
64+
65+
store_hydration_data = content_tag(:script,
66+
json_safe_and_pretty(redux_store_data[:props]).html_safe,
67+
type: "application/json",
68+
"data-js-react-on-rails-store" => redux_store_data[:store_name].html_safe,
69+
"data-immediate-hydration" =>
70+
(redux_store_data[:immediate_hydration] ? true : nil))
71+
72+
# Add immediate invocation script if immediate hydration is enabled and Pro license is valid
73+
store_hydration_scripts = if redux_store_data[:immediate_hydration]
74+
# Escape store_name for JavaScript context
75+
escaped_store_name = escape_javascript(redux_store_data[:store_name])
76+
immediate_script = content_tag(:script, <<~JS.strip_heredoc.html_safe
77+
typeof ReactOnRails === 'object' && ReactOnRails.reactOnRailsStoreLoaded('#{escaped_store_name}');
78+
JS
79+
)
80+
"#{store_hydration_data}\n#{immediate_script}"
81+
else
82+
store_hydration_data
83+
end
84+
85+
pro_warning_badge = pro_warning_badge_if_needed(explicitly_disabled_pro_options)
86+
"#{pro_warning_badge}\n#{store_hydration_scripts}".html_safe
87+
end
88+
89+
def pro_warning_badge_if_needed(explicitly_disabled_pro_options)
90+
return "" unless explicitly_disabled_pro_options.any?
91+
92+
disabled_features_message = disabled_pro_features_message(explicitly_disabled_pro_options)
93+
warning_message = "[REACT ON RAILS] #{disabled_features_message}\n" \
94+
"Please visit https://shakacode.com/react-on-rails-pro to learn more."
95+
puts warning_message
96+
Rails.logger.warn warning_message
97+
98+
tooltip_text = "#{disabled_features_message} Click to learn more."
99+
100+
<<~HTML.strip
101+
<a href="https://shakacode.com/react-on-rails-pro" target="_blank" rel="noopener noreferrer" title="#{tooltip_text}">
102+
<div style="position: fixed; top: 0; right: 0; width: 180px; height: 180px; overflow: hidden; z-index: 9999; pointer-events: none;">
103+
<div style="position: absolute; top: 50px; right: -40px; transform: rotate(45deg); background-color: rgba(220, 53, 69, 0.85); color: white; padding: 7px 40px; text-align: center; font-weight: bold; font-family: sans-serif; font-size: 12px; box-shadow: 0 2px 8px rgba(0,0,0,0.3); pointer-events: auto;">
104+
React On Rails Pro Required
105+
</div>
106+
</div>
107+
</a>
108+
HTML
109+
end
110+
111+
def disabled_pro_features_message(explicitly_disabled_pro_options)
112+
return "".html_safe unless explicitly_disabled_pro_options.any?
113+
114+
feature_list = explicitly_disabled_pro_options.join(", ")
115+
feature_word = explicitly_disabled_pro_options.size == 1 ? "feature" : "features"
116+
"The '#{feature_list}' #{feature_word} " \
117+
"#{explicitly_disabled_pro_options.size == 1 ? 'requires' : 'require'} a " \
118+
"React on Rails Pro license. "
119+
end
120+
end
121+
end
122+
end

lib/react_on_rails/pro/utils.rb

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# frozen_string_literal: true
2+
3+
# /*
4+
# * Copyright (c) 2025 Shakacode LLC
5+
# *
6+
# * This file is NOT licensed under the MIT (open source) license.
7+
# * It is part of the React on Rails Pro offering and is licensed separately.
8+
# *
9+
# * Unauthorized copying, modification, distribution, or use of this file,
10+
# * via any medium, is strictly prohibited without a valid license agreement
11+
# * from Shakacode LLC.
12+
# *
13+
# * For licensing terms, please see:
14+
# * https://github.com/shakacode/react_on_rails/blob/master/REACT-ON-RAILS-PRO-LICENSE.md
15+
# */
16+
17+
module ReactOnRails
18+
module Pro
19+
module Utils
20+
PRO_ONLY_OPTIONS = %i[immediate_hydration].freeze
21+
22+
# Checks if React on Rails Pro features are available
23+
# @return [Boolean] true if Pro license is valid, false otherwise
24+
def self.support_pro_features?
25+
ReactOnRails::Utils.react_on_rails_pro_licence_valid?
26+
end
27+
28+
def self.disable_pro_render_options_if_not_licensed(raw_options)
29+
if support_pro_features?
30+
return {
31+
raw_options: raw_options,
32+
explicitly_disabled_pro_options: []
33+
}
34+
end
35+
36+
raw_options_after_disable = raw_options.dup
37+
38+
explicitly_disabled_pro_options = PRO_ONLY_OPTIONS.select do |option|
39+
# Use global configuration if it's not overridden in the options
40+
next ReactOnRails.configuration.send(option) if raw_options[option].nil?
41+
42+
raw_options[option]
43+
end
44+
explicitly_disabled_pro_options.each { |option| raw_options_after_disable[option] = false }
45+
46+
{
47+
raw_options: raw_options_after_disable,
48+
explicitly_disabled_pro_options: explicitly_disabled_pro_options
49+
}
50+
end
51+
end
52+
end
53+
end

lib/react_on_rails/pro_helper.rb

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

lib/react_on_rails/pro_utils.rb

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

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::ProUtils.disable_pro_render_options_if_not_licensed(options)
19+
result = ReactOnRails::Pro::Utils.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)