react_on_rails 15.0.0.rc.2 → 16.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +65 -36
- data/CLAUDE.md +90 -0
- data/CODING_AGENTS.md +312 -0
- data/CONTRIBUTING.md +378 -3
- data/Gemfile.lock +2 -1
- data/LICENSE.md +16 -4
- data/LICENSES/README.md +14 -0
- data/REACT-ON-RAILS-PRO-LICENSE.md +129 -0
- data/README.md +2 -2
- data/TODO.md +135 -0
- data/eslint.config.ts +2 -0
- data/lib/generators/USAGE +4 -5
- data/lib/generators/react_on_rails/base_generator.rb +263 -57
- data/lib/generators/react_on_rails/bin/dev +38 -22
- data/lib/generators/react_on_rails/dev_tests_generator.rb +1 -0
- data/lib/generators/react_on_rails/generator_helper.rb +31 -1
- data/lib/generators/react_on_rails/generator_messages.rb +138 -17
- data/lib/generators/react_on_rails/install_generator.rb +222 -20
- data/lib/generators/react_on_rails/react_no_redux_generator.rb +6 -5
- data/lib/generators/react_on_rails/react_with_redux_generator.rb +37 -13
- data/lib/generators/react_on_rails/templates/base/base/Procfile.dev +5 -0
- data/lib/generators/react_on_rails/templates/base/base/Procfile.dev-prod-assets +8 -0
- data/lib/generators/react_on_rails/templates/base/base/Procfile.dev-static-assets +2 -0
- data/lib/generators/react_on_rails/templates/base/base/app/javascript/bundles/HelloWorld/components/HelloWorld.jsx +0 -5
- data/lib/generators/react_on_rails/templates/base/base/app/javascript/packs/server-bundle.js +1 -8
- data/lib/generators/react_on_rails/templates/base/base/app/javascript/src/HelloWorld/ror_components/HelloWorld.client.jsx +21 -0
- data/lib/generators/react_on_rails/templates/base/base/app/javascript/src/HelloWorld/ror_components/HelloWorld.module.css +4 -0
- data/lib/generators/react_on_rails/templates/base/base/app/javascript/src/HelloWorld/ror_components/HelloWorld.server.jsx +5 -0
- data/lib/generators/react_on_rails/templates/base/base/app/views/hello_world/index.html.erb.tt +1 -1
- data/lib/generators/react_on_rails/templates/base/base/app/views/layouts/hello_world.html.erb +4 -2
- data/lib/generators/react_on_rails/templates/base/base/babel.config.js.tt +5 -2
- data/lib/generators/react_on_rails/templates/base/base/bin/dev +46 -0
- data/lib/generators/react_on_rails/templates/base/base/config/initializers/react_on_rails.rb.tt +3 -3
- data/lib/generators/react_on_rails/templates/base/base/config/shakapacker.yml +76 -7
- data/lib/generators/react_on_rails/templates/base/base/config/webpack/commonWebpackConfig.js.tt +1 -1
- data/lib/generators/react_on_rails/templates/base/base/config/webpack/development.js.tt +8 -8
- data/lib/generators/react_on_rails/templates/base/base/config/webpack/production.js.tt +2 -2
- data/lib/generators/react_on_rails/templates/base/base/config/webpack/test.js.tt +2 -2
- data/lib/generators/react_on_rails/templates/dev_tests/spec/system/hello_world_spec.rb +0 -2
- data/lib/generators/react_on_rails/templates/redux/base/app/javascript/bundles/HelloWorld/components/HelloWorld.jsx +0 -6
- data/lib/generators/react_on_rails/templates/redux/base/app/javascript/bundles/HelloWorld/components/HelloWorld.module.css +4 -0
- data/lib/generators/react_on_rails/templates/redux/base/app/javascript/bundles/HelloWorld/startup/HelloWorldApp.server.jsx +5 -0
- data/lib/react_on_rails/configuration.rb +5 -5
- data/lib/react_on_rails/controller.rb +5 -3
- data/lib/react_on_rails/dev/file_manager.rb +78 -0
- data/lib/react_on_rails/dev/pack_generator.rb +27 -0
- data/lib/react_on_rails/dev/process_manager.rb +61 -0
- data/lib/react_on_rails/dev/server_manager.rb +330 -0
- data/lib/react_on_rails/dev.rb +20 -0
- data/lib/react_on_rails/engine.rb +6 -0
- data/lib/react_on_rails/git_utils.rb +12 -2
- data/lib/react_on_rails/helper.rb +61 -17
- data/lib/react_on_rails/packer_utils.rb +4 -18
- data/lib/react_on_rails/packs_generator.rb +134 -8
- data/lib/react_on_rails/react_component/render_options.rb +2 -2
- data/lib/react_on_rails/server_rendering_js_code.rb +0 -1
- data/lib/react_on_rails/server_rendering_pool/ruby_embedded_java_script.rb +1 -0
- data/lib/react_on_rails/test_helper/webpack_assets_status_checker.rb +1 -0
- data/lib/react_on_rails/utils.rb +16 -1
- data/lib/react_on_rails/version.rb +1 -1
- data/lib/react_on_rails/version_syntax_converter.rb +1 -1
- data/lib/react_on_rails.rb +1 -0
- data/lib/tasks/generate_packs.rake +20 -0
- data/react_on_rails.gemspec +1 -0
- metadata +40 -11
- data/REACT-ON-RAILS-PRO-LICENSE +0 -95
- data/lib/generators/react_on_rails/adapt_for_older_shakapacker_generator.rb +0 -41
- data/lib/generators/react_on_rails/bin/dev-static +0 -30
- data/lib/generators/react_on_rails/templates/base/base/Procfile.dev-static.tt +0 -9
- data/lib/generators/react_on_rails/templates/base/base/Procfile.dev.tt +0 -5
- data/lib/generators/react_on_rails/templates/base/base/app/javascript/packs/registration.js.tt +0 -8
- /data/lib/generators/react_on_rails/templates/base/base/config/webpack/{webpackConfig.js.tt → generateWebpackConfigs.js.tt} +0 -0
- /data/lib/generators/react_on_rails/templates/redux/base/app/javascript/bundles/HelloWorld/startup/{HelloWorldApp.jsx → HelloWorldApp.client.jsx} +0 -0
data/lib/generators/react_on_rails/templates/base/base/app/javascript/packs/server-bundle.js
CHANGED
@@ -1,8 +1 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
import HelloWorld from '../bundles/HelloWorld/components/HelloWorldServer';
|
4
|
-
|
5
|
-
// This is how react_on_rails can see the HelloWorld in the browser.
|
6
|
-
ReactOnRails.register({
|
7
|
-
HelloWorld,
|
8
|
-
});
|
1
|
+
// Placeholder comment - auto-generated imports will be prepended here by react_on_rails:generate_packs
|
@@ -0,0 +1,21 @@
|
|
1
|
+
import React, { useState } from 'react';
|
2
|
+
import * as style from './HelloWorld.module.css';
|
3
|
+
|
4
|
+
const HelloWorld = (props) => {
|
5
|
+
const [name, setName] = useState(props.name);
|
6
|
+
|
7
|
+
return (
|
8
|
+
<div>
|
9
|
+
<h3>Hello, {name}!</h3>
|
10
|
+
<hr />
|
11
|
+
<form>
|
12
|
+
<label className={style.bright} htmlFor="name">
|
13
|
+
Say hello to:
|
14
|
+
<input id="name" type="text" value={name} onChange={(e) => setName(e.target.value)} />
|
15
|
+
</label>
|
16
|
+
</form>
|
17
|
+
</div>
|
18
|
+
);
|
19
|
+
};
|
20
|
+
|
21
|
+
export default HelloWorld;
|
data/lib/generators/react_on_rails/templates/base/base/app/views/hello_world/index.html.erb.tt
CHANGED
@@ -1,2 +1,2 @@
|
|
1
1
|
<h1>Hello World</h1>
|
2
|
-
<%%= react_component("<%= config[:component_name] %>", props: @hello_world_props, prerender:
|
2
|
+
<%%= react_component("<%= config[:component_name] %>", props: @hello_world_props, prerender: true) %>
|
data/lib/generators/react_on_rails/templates/base/base/app/views/layouts/hello_world.html.erb
CHANGED
@@ -3,8 +3,10 @@
|
|
3
3
|
<head>
|
4
4
|
<title>ReactOnRailsWithShakapacker</title>
|
5
5
|
<%= csrf_meta_tags %>
|
6
|
-
|
7
|
-
|
6
|
+
|
7
|
+
<!-- Empty pack tags - React on Rails injects component CSS/JS here -->
|
8
|
+
<%= stylesheet_pack_tag %>
|
9
|
+
<%= javascript_pack_tag %>
|
8
10
|
</head>
|
9
11
|
|
10
12
|
<body>
|
@@ -11,12 +11,15 @@ module.exports = function (api) {
|
|
11
11
|
'@babel/preset-react',
|
12
12
|
{
|
13
13
|
development: !isProductionEnv,
|
14
|
-
useBuiltIns: true
|
14
|
+
useBuiltIns: true,
|
15
|
+
runtime: 'automatic'
|
15
16
|
}
|
16
17
|
]
|
17
18
|
].filter(Boolean),
|
18
19
|
plugins: [
|
19
|
-
|
20
|
+
// Enable React Refresh (Fast Refresh) only when webpack-dev-server is running (HMR mode)
|
21
|
+
// This prevents React Refresh from trying to connect when using static compilation
|
22
|
+
!isProductionEnv && process.env.WEBPACK_SERVE && 'react-refresh/babel',
|
20
23
|
isProductionEnv && ['babel-plugin-transform-react-remove-prop-types',
|
21
24
|
{
|
22
25
|
removeImport: true
|
@@ -0,0 +1,46 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
# ReactOnRails Development Server
|
5
|
+
#
|
6
|
+
# This script provides a simple interface to the ReactOnRails development
|
7
|
+
# server management. The core logic is implemented in ReactOnRails::Dev
|
8
|
+
# classes for better maintainability and testing.
|
9
|
+
#
|
10
|
+
# Each command uses a specific Procfile for process management:
|
11
|
+
# - bin/dev (default/hmr): Uses Procfile.dev
|
12
|
+
# - bin/dev static: Uses Procfile.dev-static-assets
|
13
|
+
# - bin/dev prod: Uses Procfile.dev-prod-assets
|
14
|
+
#
|
15
|
+
# To customize development environment:
|
16
|
+
# 1. Edit the appropriate Procfile to modify which processes run
|
17
|
+
# 2. Modify this script for project-specific command-line behavior
|
18
|
+
# 3. Extend ReactOnRails::Dev classes in your Rails app for advanced customization
|
19
|
+
# 4. Use classes directly: ReactOnRails::Dev::ServerManager.start(:development, "Custom.procfile")
|
20
|
+
|
21
|
+
begin
|
22
|
+
require "bundler/setup"
|
23
|
+
require "react_on_rails/dev"
|
24
|
+
rescue LoadError
|
25
|
+
# Fallback for when gem is not yet installed
|
26
|
+
puts "Loading ReactOnRails development tools..."
|
27
|
+
require_relative "../../lib/react_on_rails/dev"
|
28
|
+
end
|
29
|
+
|
30
|
+
# Main execution
|
31
|
+
case ARGV[0]
|
32
|
+
when "production-assets", "prod"
|
33
|
+
ReactOnRails::Dev::ServerManager.start(:production_like)
|
34
|
+
when "static"
|
35
|
+
ReactOnRails::Dev::ServerManager.start(:static, "Procfile.dev-static-assets")
|
36
|
+
when "kill"
|
37
|
+
ReactOnRails::Dev::ServerManager.kill_processes
|
38
|
+
when "help", "--help", "-h"
|
39
|
+
ReactOnRails::Dev::ServerManager.show_help
|
40
|
+
when "hmr", nil
|
41
|
+
ReactOnRails::Dev::ServerManager.start(:development, "Procfile.dev")
|
42
|
+
else
|
43
|
+
puts "Unknown argument: #{ARGV[0]}"
|
44
|
+
puts "Run 'bin/dev help' for usage information"
|
45
|
+
exit 1
|
46
|
+
end
|
data/lib/generators/react_on_rails/templates/base/base/config/initializers/react_on_rails.rb.tt
CHANGED
@@ -20,7 +20,7 @@ ReactOnRails.configure do |config|
|
|
20
20
|
#
|
21
21
|
# ReactOnRails::TestHelper.configure_rspec_to_compile_assets(config)
|
22
22
|
#
|
23
|
-
# with rspec then this controls what
|
23
|
+
# with rspec then this controls what npm command is run
|
24
24
|
# to automatically refresh your webpack assets on every test run.
|
25
25
|
#
|
26
26
|
# Alternately, you can remove the `ReactOnRails::TestHelper.configure_rspec_to_compile_assets`
|
@@ -49,10 +49,10 @@ ReactOnRails.configure do |config|
|
|
49
49
|
################################################################################
|
50
50
|
# `components_subdirectory` is the name of the matching directories that contain automatically registered components
|
51
51
|
# for use in the Rails views. The default is nil, you can enable the feature by updating it in the next line.
|
52
|
-
|
52
|
+
config.components_subdirectory = "ror_components"
|
53
53
|
#
|
54
54
|
# For automated component registry, `render_component` view helper method tries to load bundle for component from
|
55
55
|
# generated directory. default is false, you can pass option at the time of individual usage or update the default
|
56
56
|
# in the following line
|
57
|
-
config.auto_load_bundle =
|
57
|
+
config.auto_load_bundle = true
|
58
58
|
end
|
@@ -1,43 +1,109 @@
|
|
1
1
|
# Note: You must restart bin/shakapacker-dev-server for changes to take effect
|
2
|
+
# This file contains the defaults used by shakapacker.
|
2
3
|
|
3
4
|
default: &default
|
4
5
|
source_path: app/javascript
|
6
|
+
|
7
|
+
# You can have a subdirectory of the source_path, like 'packs' (recommended).
|
8
|
+
# Alternatively, you can use '/' to use the whole source_path directory.
|
9
|
+
# Notice that this is a relative path to source_path
|
5
10
|
source_entry_path: packs
|
11
|
+
|
12
|
+
# If nested_entries is true, then we'll pick up subdirectories within the source_entry_path.
|
13
|
+
# You cannot set this option to true if you set source_entry_path to '/'
|
14
|
+
nested_entries: true
|
15
|
+
|
16
|
+
# While using a File-System-based automated bundle generation feature, miscellaneous warnings suggesting css order
|
17
|
+
# conflicts may arise due to the mini-css-extract-plugin. For projects where css ordering has been mitigated through
|
18
|
+
# consistent use of scoping or naming conventions, the css order warnings can be disabled by setting
|
19
|
+
# css_extract_ignore_order_warnings to true
|
20
|
+
css_extract_ignore_order_warnings: false
|
21
|
+
|
6
22
|
public_root_path: public
|
7
23
|
public_output_path: packs
|
8
24
|
cache_path: tmp/shakapacker
|
9
25
|
webpack_compile_output: true
|
26
|
+
# See https://github.com/shakacode/shakapacker#deployment
|
27
|
+
shakapacker_precompile: true
|
10
28
|
|
11
|
-
#
|
29
|
+
# Location for manifest.json, defaults to {public_output_path}/manifest.json if unset
|
30
|
+
# manifest_path: public/packs/manifest.json
|
31
|
+
|
32
|
+
# Additional paths webpack should look up modules
|
12
33
|
# ['app/assets', 'engine/foo/app/assets']
|
13
34
|
additional_paths: []
|
14
35
|
|
15
36
|
# Reload manifest.json on all requests so we reload latest compiled packs
|
16
37
|
cache_manifest: false
|
17
38
|
|
39
|
+
# Select loader to use, available options are 'babel' (default), 'swc' or 'esbuild'
|
40
|
+
webpack_loader: 'babel'
|
41
|
+
|
42
|
+
# Raises an error if there is a mismatch in the shakapacker gem and npm package being used
|
43
|
+
ensure_consistent_versioning: true
|
44
|
+
|
45
|
+
# Select whether the compiler will use SHA digest ('digest' option) or most recent modified timestamp ('mtime') to determine freshness
|
46
|
+
compiler_strategy: digest
|
47
|
+
|
48
|
+
# Select whether the compiler will always use a content hash and not just in production
|
49
|
+
# Don't use contentHash except for production for performance
|
50
|
+
# https://webpack.js.org/guides/build-performance/#avoid-production-specific-tooling
|
51
|
+
useContentHash: false
|
52
|
+
|
53
|
+
# Setting the asset host here will override Rails.application.config.asset_host.
|
54
|
+
# Here, you can set different asset_host per environment. Note that
|
55
|
+
# SHAKAPACKER_ASSET_HOST will override both configurations.
|
56
|
+
# asset_host: custom-path
|
57
|
+
|
58
|
+
# Utilizing webpack-subresource-integrity plugin, will generate integrity hashes for all entries in manifest.json
|
59
|
+
# https://github.com/waysact/webpack-subresource-integrity/tree/main/webpack-subresource-integrity
|
60
|
+
integrity:
|
61
|
+
enabled: false
|
62
|
+
# Which cryptographic function(s) to use, for generating the integrity hash(es). Default sha-384. Other possible values sha256, sha512
|
63
|
+
hash_functions: ["sha384"]
|
64
|
+
# Default "anonymous". Other possible value "use-credentials"
|
65
|
+
# https://developer.mozilla.org/en-US/docs/Web/Security/Subresource_Integrity#cross-origin_resource_sharing_and_subresource_integrity
|
66
|
+
cross_origin: "anonymous"
|
67
|
+
|
18
68
|
development:
|
19
69
|
<<: *default
|
20
|
-
|
21
|
-
|
70
|
+
compile: true
|
71
|
+
compiler_strategy: mtime
|
22
72
|
|
23
73
|
# Reference: https://webpack.js.org/configuration/dev-server/
|
74
|
+
# Keys not described there are documented inline and in https://github.com/shakacode/shakapacker/
|
24
75
|
dev_server:
|
25
|
-
https:
|
76
|
+
# For running dev server with https, set `server: https`.
|
77
|
+
# server: https
|
78
|
+
|
26
79
|
host: localhost
|
27
80
|
port: 3035
|
28
81
|
# Hot Module Replacement updates modules while the application is running without a full reload
|
82
|
+
# Used instead of the `hot` key in https://webpack.js.org/configuration/dev-server/#devserverhot
|
29
83
|
hmr: true
|
84
|
+
# If HMR is on, CSS will be inlined by delivering it as part of the script payload via style-loader. Be sure
|
85
|
+
# that you add style-loader to your project dependencies.
|
86
|
+
#
|
87
|
+
# If you want to instead deliver CSS via <link> with the mini-css-extract-plugin, set inline_css to false.
|
88
|
+
# In that case, style-loader is not needed as a dependency.
|
89
|
+
#
|
90
|
+
# mini-css-extract-plugin is a required dependency in both cases.
|
91
|
+
inline_css: true
|
92
|
+
# Defaults to the inverse of hmr. Uncomment to manually set this.
|
93
|
+
# live_reload: true
|
30
94
|
client:
|
31
95
|
# Should we show a full-screen overlay in the browser when there are compiler errors or warnings?
|
32
96
|
overlay: true
|
33
97
|
# May also be a string
|
34
98
|
# webSocketURL:
|
35
|
-
# hostname:
|
36
|
-
# pathname:
|
99
|
+
# hostname: '0.0.0.0'
|
100
|
+
# pathname: '/ws'
|
37
101
|
# port: 8080
|
102
|
+
# Should we use gzip compression?
|
38
103
|
compress: true
|
39
104
|
# Note that apps that do not check the host are vulnerable to DNS rebinding attacks
|
40
|
-
allowed_hosts:
|
105
|
+
allowed_hosts: 'auto'
|
106
|
+
# Shows progress and colorizes output of bin/shakapacker[-dev-server]
|
41
107
|
pretty: true
|
42
108
|
headers:
|
43
109
|
'Access-Control-Allow-Origin': '*'
|
@@ -58,5 +124,8 @@ production:
|
|
58
124
|
# Production depends on precompilation of packs prior to booting for performance.
|
59
125
|
compile: false
|
60
126
|
|
127
|
+
# Use content hash for naming assets. Cannot be overridden in production.
|
128
|
+
useContentHash: true
|
129
|
+
|
61
130
|
# Cache manifest.json for performance
|
62
131
|
cache_manifest: true
|
data/lib/generators/react_on_rails/templates/base/base/config/webpack/commonWebpackConfig.js.tt
CHANGED
@@ -14,4 +14,4 @@ const commonOptions = {
|
|
14
14
|
// Copy the object using merge b/c the baseClientWebpackConfig and commonOptions are mutable globals
|
15
15
|
const commonWebpackConfig = () => merge({}, baseClientWebpackConfig, commonOptions);
|
16
16
|
|
17
|
-
module.exports = commonWebpackConfig;
|
17
|
+
module.exports = commonWebpackConfig;
|
@@ -2,20 +2,20 @@
|
|
2
2
|
|
3
3
|
const { devServer, inliningCss } = require('shakapacker');
|
4
4
|
|
5
|
-
const
|
5
|
+
const generateWebpackConfigs = require('./generateWebpackConfigs');
|
6
6
|
|
7
7
|
const developmentEnvOnly = (clientWebpackConfig, _serverWebpackConfig) => {
|
8
|
-
//
|
9
|
-
|
10
|
-
|
11
|
-
// Thus, this plugin is not applied to the server bundle.
|
12
|
-
|
8
|
+
// React Refresh (Fast Refresh) setup - only when webpack-dev-server is running (HMR mode)
|
9
|
+
// This matches the condition in generateWebpackConfigs.js and babel.config.js
|
10
|
+
if (process.env.WEBPACK_SERVE) {
|
13
11
|
// eslint-disable-next-line global-require
|
14
12
|
const ReactRefreshWebpackPlugin = require('@pmmmwh/react-refresh-webpack-plugin');
|
15
13
|
clientWebpackConfig.plugins.push(
|
16
|
-
new ReactRefreshWebpackPlugin({
|
14
|
+
new ReactRefreshWebpackPlugin({
|
15
|
+
// Use default overlay configuration for better compatibility
|
16
|
+
}),
|
17
17
|
);
|
18
18
|
}
|
19
19
|
};
|
20
20
|
|
21
|
-
module.exports =
|
21
|
+
module.exports = generateWebpackConfigs(developmentEnvOnly);
|
@@ -1,9 +1,9 @@
|
|
1
1
|
<%= add_documentation_reference(config[:message], "// https://github.com/shakacode/react_on_rails_demo_ssr_hmr/blob/master/config/webpack/production.js") %>
|
2
2
|
|
3
|
-
const
|
3
|
+
const generateWebpackConfigs = require('./generateWebpackConfigs');
|
4
4
|
|
5
5
|
const productionEnvOnly = (_clientWebpackConfig, _serverWebpackConfig) => {
|
6
6
|
// place any code here that is for production only
|
7
7
|
};
|
8
8
|
|
9
|
-
module.exports =
|
9
|
+
module.exports = generateWebpackConfigs(productionEnvOnly);
|
@@ -1,9 +1,9 @@
|
|
1
1
|
<%= add_documentation_reference(config[:message], "// https://github.com/shakacode/react_on_rails_demo_ssr_hmr/blob/master/config/webpack/test.js") %>
|
2
2
|
|
3
|
-
const
|
3
|
+
const generateWebpackConfigs = require('./generateWebpackConfigs')
|
4
4
|
|
5
5
|
const testOnly = (_clientWebpackConfig, _serverWebpackConfig) => {
|
6
6
|
// place any code here that is for test only
|
7
7
|
}
|
8
8
|
|
9
|
-
module.exports =
|
9
|
+
module.exports = generateWebpackConfigs(testOnly)
|
@@ -1,4 +1,3 @@
|
|
1
|
-
import PropTypes from 'prop-types';
|
2
1
|
import React from 'react';
|
3
2
|
import * as style from './HelloWorld.module.css';
|
4
3
|
|
@@ -18,9 +17,4 @@ const HelloWorld = ({ name, updateName }) => (
|
|
18
17
|
</div>
|
19
18
|
);
|
20
19
|
|
21
|
-
HelloWorld.propTypes = {
|
22
|
-
name: PropTypes.string.isRequired,
|
23
|
-
updateName: PropTypes.func.isRequired,
|
24
|
-
};
|
25
|
-
|
26
20
|
export default HelloWorld;
|
@@ -46,8 +46,8 @@ module ReactOnRails
|
|
46
46
|
components_subdirectory: nil,
|
47
47
|
make_generated_server_bundle_the_entrypoint: false,
|
48
48
|
defer_generated_component_packs: false,
|
49
|
-
#
|
50
|
-
|
49
|
+
# React on Rails Pro (licensed) feature - enables immediate hydration of React components
|
50
|
+
immediate_hydration: false,
|
51
51
|
# Maximum time in milliseconds to wait for client-side component registration after page load.
|
52
52
|
# If exceeded, an error will be thrown for server-side rendered components not registered on the client.
|
53
53
|
# Set to 0 to disable the timeout and wait indefinitely for component registration.
|
@@ -67,7 +67,7 @@ module ReactOnRails
|
|
67
67
|
:server_render_method, :random_dom_id, :auto_load_bundle,
|
68
68
|
:same_bundle_for_client_and_server, :rendering_props_extension,
|
69
69
|
:make_generated_server_bundle_the_entrypoint,
|
70
|
-
:generated_component_packs_loading_strategy, :
|
70
|
+
:generated_component_packs_loading_strategy, :immediate_hydration, :rsc_bundle_js_file,
|
71
71
|
:react_client_manifest_file, :react_server_client_manifest_file, :component_registry_timeout
|
72
72
|
|
73
73
|
# rubocop:disable Metrics/AbcSize
|
@@ -83,7 +83,7 @@ module ReactOnRails
|
|
83
83
|
same_bundle_for_client_and_server: nil,
|
84
84
|
i18n_dir: nil, i18n_yml_dir: nil, i18n_output_format: nil, i18n_yml_safe_load_options: nil,
|
85
85
|
random_dom_id: nil, server_render_method: nil, rendering_props_extension: nil,
|
86
|
-
components_subdirectory: nil, auto_load_bundle: nil,
|
86
|
+
components_subdirectory: nil, auto_load_bundle: nil, immediate_hydration: nil,
|
87
87
|
rsc_bundle_js_file: nil, react_client_manifest_file: nil, react_server_client_manifest_file: nil,
|
88
88
|
component_registry_timeout: nil)
|
89
89
|
self.node_modules_location = node_modules_location.present? ? node_modules_location : Rails.root
|
@@ -128,7 +128,7 @@ module ReactOnRails
|
|
128
128
|
self.auto_load_bundle = auto_load_bundle
|
129
129
|
self.make_generated_server_bundle_the_entrypoint = make_generated_server_bundle_the_entrypoint
|
130
130
|
self.defer_generated_component_packs = defer_generated_component_packs
|
131
|
-
self.
|
131
|
+
self.immediate_hydration = immediate_hydration
|
132
132
|
self.generated_component_packs_loading_strategy = generated_component_packs_loading_strategy
|
133
133
|
end
|
134
134
|
# rubocop:enable Metrics/AbcSize
|
@@ -9,14 +9,16 @@ module ReactOnRails
|
|
9
9
|
# JavaScript code.
|
10
10
|
# props: Named parameter props which is a Ruby Hash or JSON string which contains the properties
|
11
11
|
# to pass to the redux store.
|
12
|
+
# immediate_hydration: React on Rails Pro (licensed) feature. Pass as true if you wish to hydrate this
|
13
|
+
# store immediately instead of waiting for the page to load.
|
12
14
|
#
|
13
15
|
# Be sure to include view helper `redux_store_hydration_data` at the end of your layout or view
|
14
16
|
# or else there will be no client side hydration of your stores.
|
15
|
-
def redux_store(store_name, props: {},
|
16
|
-
|
17
|
+
def redux_store(store_name, props: {}, immediate_hydration: nil)
|
18
|
+
immediate_hydration = ReactOnRails.configuration.immediate_hydration if immediate_hydration.nil?
|
17
19
|
redux_store_data = { store_name: store_name,
|
18
20
|
props: props,
|
19
|
-
|
21
|
+
immediate_hydration: immediate_hydration }
|
20
22
|
@registered_stores_defer_render ||= []
|
21
23
|
@registered_stores_defer_render << redux_store_data
|
22
24
|
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ReactOnRails
|
4
|
+
module Dev
|
5
|
+
class FileManager
|
6
|
+
class << self
|
7
|
+
def cleanup_stale_files
|
8
|
+
socket_cleanup = cleanup_overmind_sockets
|
9
|
+
pid_cleanup = cleanup_rails_pid_file
|
10
|
+
|
11
|
+
socket_cleanup || pid_cleanup
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def cleanup_overmind_sockets
|
17
|
+
return false if overmind_running?
|
18
|
+
|
19
|
+
socket_files = [".overmind.sock", "tmp/sockets/overmind.sock"]
|
20
|
+
cleaned_any = false
|
21
|
+
|
22
|
+
socket_files.each do |socket_file|
|
23
|
+
cleaned_any = true if remove_file_if_exists(socket_file, "stale socket")
|
24
|
+
end
|
25
|
+
|
26
|
+
cleaned_any
|
27
|
+
end
|
28
|
+
|
29
|
+
def cleanup_rails_pid_file
|
30
|
+
server_pid_file = "tmp/pids/server.pid"
|
31
|
+
return false unless File.exist?(server_pid_file)
|
32
|
+
|
33
|
+
pid_content = File.read(server_pid_file).strip
|
34
|
+
begin
|
35
|
+
pid = Integer(pid_content)
|
36
|
+
# PIDs must be > 1 (0 is kernel, 1 is init)
|
37
|
+
if pid <= 1
|
38
|
+
remove_file_if_exists(server_pid_file, "stale Rails pid file")
|
39
|
+
return true
|
40
|
+
end
|
41
|
+
rescue ArgumentError, TypeError
|
42
|
+
remove_file_if_exists(server_pid_file, "stale Rails pid file")
|
43
|
+
return true
|
44
|
+
end
|
45
|
+
|
46
|
+
return false if process_running?(pid)
|
47
|
+
|
48
|
+
remove_file_if_exists(server_pid_file, "stale Rails pid file")
|
49
|
+
end
|
50
|
+
|
51
|
+
def overmind_running?
|
52
|
+
!`pgrep -f "overmind" 2>/dev/null`.split("\n").empty?
|
53
|
+
end
|
54
|
+
|
55
|
+
def process_running?(pid)
|
56
|
+
Process.kill(0, pid)
|
57
|
+
true
|
58
|
+
rescue Errno::ESRCH, ArgumentError, RangeError
|
59
|
+
# Process doesn't exist or invalid PID
|
60
|
+
false
|
61
|
+
rescue Errno::EPERM
|
62
|
+
# Process exists but we don't have permission to signal it
|
63
|
+
true
|
64
|
+
end
|
65
|
+
|
66
|
+
def remove_file_if_exists(file_path, description)
|
67
|
+
return false unless File.exist?(file_path)
|
68
|
+
|
69
|
+
puts " 🧹 Cleaning up #{description}: #{file_path}"
|
70
|
+
File.delete(file_path)
|
71
|
+
true
|
72
|
+
rescue StandardError
|
73
|
+
false
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "English"
|
4
|
+
|
5
|
+
module ReactOnRails
|
6
|
+
module Dev
|
7
|
+
class PackGenerator
|
8
|
+
class << self
|
9
|
+
def generate(verbose: false)
|
10
|
+
if verbose
|
11
|
+
puts "📦 Generating React on Rails packs..."
|
12
|
+
success = system "bundle exec rake react_on_rails:generate_packs"
|
13
|
+
else
|
14
|
+
print "📦 Generating packs... "
|
15
|
+
success = system "bundle exec rake react_on_rails:generate_packs > /dev/null 2>&1"
|
16
|
+
puts success ? "✅" : "❌"
|
17
|
+
end
|
18
|
+
|
19
|
+
return if success
|
20
|
+
|
21
|
+
puts "❌ Pack generation failed"
|
22
|
+
exit 1
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ReactOnRails
|
4
|
+
module Dev
|
5
|
+
class ProcessManager
|
6
|
+
class << self
|
7
|
+
def installed?(process)
|
8
|
+
IO.popen([process, "-v"], &:close)
|
9
|
+
true
|
10
|
+
rescue Errno::ENOENT
|
11
|
+
false
|
12
|
+
end
|
13
|
+
|
14
|
+
def ensure_procfile(procfile)
|
15
|
+
return if File.exist?(procfile)
|
16
|
+
|
17
|
+
warn <<~MSG
|
18
|
+
ERROR:
|
19
|
+
Please ensure `#{procfile}` exists in your project!
|
20
|
+
MSG
|
21
|
+
exit 1
|
22
|
+
end
|
23
|
+
|
24
|
+
def run_with_process_manager(procfile)
|
25
|
+
# Validate procfile path for security
|
26
|
+
unless valid_procfile_path?(procfile)
|
27
|
+
warn "ERROR: Invalid procfile path: #{procfile}"
|
28
|
+
exit 1
|
29
|
+
end
|
30
|
+
|
31
|
+
# Clean up stale files before starting
|
32
|
+
FileManager.cleanup_stale_files
|
33
|
+
|
34
|
+
if installed?("overmind")
|
35
|
+
system("overmind", "start", "-f", procfile)
|
36
|
+
elsif installed?("foreman")
|
37
|
+
system("foreman", "start", "-f", procfile)
|
38
|
+
else
|
39
|
+
warn <<~MSG
|
40
|
+
NOTICE:
|
41
|
+
For this script to run, you need either 'overmind' or 'foreman' installed on your machine. Please try this script after installing one of them.
|
42
|
+
MSG
|
43
|
+
exit 1
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
private
|
48
|
+
|
49
|
+
def valid_procfile_path?(procfile)
|
50
|
+
# Reject paths with shell metacharacters
|
51
|
+
return false if procfile.match?(/[;&|`$(){}\[\]<>]/)
|
52
|
+
|
53
|
+
# Ensure it's a readable file
|
54
|
+
File.readable?(procfile)
|
55
|
+
rescue StandardError
|
56
|
+
false
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|