react_on_rails 15.0.0.rc.2 → 16.0.1.rc.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.
Files changed (93) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +103 -34
  3. data/CLAUDE.md +102 -0
  4. data/CODING_AGENTS.md +312 -0
  5. data/CONTRIBUTING.md +378 -3
  6. data/Gemfile.lock +2 -1
  7. data/LICENSE.md +30 -4
  8. data/LICENSES/README.md +14 -0
  9. data/REACT-ON-RAILS-PRO-LICENSE.md +129 -0
  10. data/README.md +70 -20
  11. data/TODO.md +135 -0
  12. data/eslint.config.ts +5 -0
  13. data/knip.ts +20 -9
  14. data/lib/generators/USAGE +4 -5
  15. data/lib/generators/react_on_rails/USAGE +65 -0
  16. data/lib/generators/react_on_rails/base_generator.rb +263 -57
  17. data/lib/generators/react_on_rails/dev_tests_generator.rb +1 -0
  18. data/lib/generators/react_on_rails/generator_helper.rb +35 -1
  19. data/lib/generators/react_on_rails/generator_messages.rb +138 -17
  20. data/lib/generators/react_on_rails/install_generator.rb +336 -26
  21. data/lib/generators/react_on_rails/react_no_redux_generator.rb +19 -6
  22. data/lib/generators/react_on_rails/react_with_redux_generator.rb +111 -18
  23. data/lib/generators/react_on_rails/templates/base/base/Procfile.dev +5 -0
  24. data/lib/generators/react_on_rails/templates/base/base/Procfile.dev-prod-assets +8 -0
  25. data/lib/generators/react_on_rails/templates/base/base/Procfile.dev-static-assets +2 -0
  26. data/lib/generators/react_on_rails/templates/base/base/app/javascript/bundles/HelloWorld/components/HelloWorld.jsx +0 -5
  27. data/lib/generators/react_on_rails/templates/base/base/app/javascript/packs/server-bundle.js +1 -8
  28. data/lib/generators/react_on_rails/templates/base/base/app/javascript/src/HelloWorld/ror_components/HelloWorld.client.jsx +21 -0
  29. data/lib/generators/react_on_rails/templates/base/base/app/javascript/src/HelloWorld/ror_components/HelloWorld.client.tsx +25 -0
  30. data/lib/generators/react_on_rails/templates/base/base/app/javascript/src/HelloWorld/ror_components/HelloWorld.module.css +4 -0
  31. data/lib/generators/react_on_rails/templates/base/base/app/javascript/src/HelloWorld/ror_components/HelloWorld.server.jsx +5 -0
  32. data/lib/generators/react_on_rails/templates/base/base/app/javascript/src/HelloWorld/ror_components/HelloWorld.server.tsx +5 -0
  33. data/lib/generators/react_on_rails/templates/base/base/app/views/hello_world/index.html.erb.tt +1 -1
  34. data/lib/generators/react_on_rails/templates/base/base/app/views/layouts/hello_world.html.erb +4 -2
  35. data/lib/generators/react_on_rails/templates/base/base/babel.config.js.tt +5 -2
  36. data/lib/generators/react_on_rails/templates/base/base/bin/dev +34 -0
  37. data/lib/generators/react_on_rails/templates/base/base/config/initializers/react_on_rails.rb.tt +3 -3
  38. data/lib/generators/react_on_rails/templates/base/base/config/shakapacker.yml +76 -7
  39. data/lib/generators/react_on_rails/templates/base/base/config/webpack/commonWebpackConfig.js.tt +1 -1
  40. data/lib/generators/react_on_rails/templates/base/base/config/webpack/development.js.tt +8 -8
  41. data/lib/generators/react_on_rails/templates/base/base/config/webpack/production.js.tt +2 -2
  42. data/lib/generators/react_on_rails/templates/base/base/config/webpack/test.js.tt +2 -2
  43. data/lib/generators/react_on_rails/templates/dev_tests/spec/system/hello_world_spec.rb +0 -2
  44. data/lib/generators/react_on_rails/templates/redux/base/app/javascript/bundles/HelloWorld/actions/helloWorldActionCreators.ts +18 -0
  45. data/lib/generators/react_on_rails/templates/redux/base/app/javascript/bundles/HelloWorld/components/HelloWorld.jsx +0 -6
  46. data/lib/generators/react_on_rails/templates/redux/base/app/javascript/bundles/HelloWorld/components/HelloWorld.module.css +4 -0
  47. data/lib/generators/react_on_rails/templates/redux/base/app/javascript/bundles/HelloWorld/components/HelloWorld.tsx +24 -0
  48. data/lib/generators/react_on_rails/templates/redux/base/app/javascript/bundles/HelloWorld/constants/helloWorldConstants.ts +6 -0
  49. data/lib/generators/react_on_rails/templates/redux/base/app/javascript/bundles/HelloWorld/containers/HelloWorldContainer.ts +20 -0
  50. data/lib/generators/react_on_rails/templates/redux/base/app/javascript/bundles/HelloWorld/reducers/helloWorldReducer.ts +22 -0
  51. data/lib/generators/react_on_rails/templates/redux/base/app/javascript/bundles/HelloWorld/startup/HelloWorldApp.client.tsx +23 -0
  52. data/lib/generators/react_on_rails/templates/redux/base/app/javascript/bundles/HelloWorld/startup/HelloWorldApp.server.jsx +5 -0
  53. data/lib/generators/react_on_rails/templates/redux/base/app/javascript/bundles/HelloWorld/startup/HelloWorldApp.server.tsx +5 -0
  54. data/lib/generators/react_on_rails/templates/redux/base/app/javascript/bundles/HelloWorld/store/helloWorldStore.ts +18 -0
  55. data/lib/react_on_rails/configuration.rb +15 -11
  56. data/lib/react_on_rails/controller.rb +5 -3
  57. data/lib/react_on_rails/dev/file_manager.rb +78 -0
  58. data/lib/react_on_rails/dev/pack_generator.rb +27 -0
  59. data/lib/react_on_rails/dev/process_manager.rb +61 -0
  60. data/lib/react_on_rails/dev/server_manager.rb +487 -0
  61. data/lib/react_on_rails/dev.rb +20 -0
  62. data/lib/react_on_rails/doctor.rb +1149 -0
  63. data/lib/react_on_rails/engine.rb +6 -0
  64. data/lib/react_on_rails/git_utils.rb +12 -2
  65. data/lib/react_on_rails/helper.rb +19 -44
  66. data/lib/react_on_rails/packer_utils.rb +4 -18
  67. data/lib/react_on_rails/packs_generator.rb +134 -8
  68. data/lib/react_on_rails/pro/NOTICE +21 -0
  69. data/lib/react_on_rails/pro/helper.rb +122 -0
  70. data/lib/react_on_rails/pro/utils.rb +53 -0
  71. data/lib/react_on_rails/react_component/render_options.rb +8 -4
  72. data/lib/react_on_rails/server_rendering_js_code.rb +0 -1
  73. data/lib/react_on_rails/server_rendering_pool/ruby_embedded_java_script.rb +1 -0
  74. data/lib/react_on_rails/system_checker.rb +659 -0
  75. data/lib/react_on_rails/test_helper/webpack_assets_status_checker.rb +1 -0
  76. data/lib/react_on_rails/utils.rb +16 -1
  77. data/lib/react_on_rails/version.rb +1 -1
  78. data/lib/react_on_rails/version_syntax_converter.rb +1 -1
  79. data/lib/react_on_rails.rb +1 -0
  80. data/lib/tasks/doctor.rake +51 -0
  81. data/lib/tasks/generate_packs.rake +144 -1
  82. data/package-lock.json +11984 -0
  83. data/react_on_rails.gemspec +1 -0
  84. metadata +55 -11
  85. data/REACT-ON-RAILS-PRO-LICENSE +0 -95
  86. data/lib/generators/react_on_rails/adapt_for_older_shakapacker_generator.rb +0 -41
  87. data/lib/generators/react_on_rails/bin/dev +0 -30
  88. data/lib/generators/react_on_rails/bin/dev-static +0 -30
  89. data/lib/generators/react_on_rails/templates/base/base/Procfile.dev-static.tt +0 -9
  90. data/lib/generators/react_on_rails/templates/base/base/Procfile.dev.tt +0 -5
  91. data/lib/generators/react_on_rails/templates/base/base/app/javascript/packs/registration.js.tt +0 -8
  92. /data/lib/generators/react_on_rails/templates/base/base/config/webpack/{webpackConfig.js.tt → generateWebpackConfigs.js.tt} +0 -0
  93. /data/lib/generators/react_on_rails/templates/redux/base/app/javascript/bundles/HelloWorld/startup/{HelloWorldApp.jsx → HelloWorldApp.client.jsx} +0 -0
@@ -1,8 +1 @@
1
- import ReactOnRails from 'react-on-rails';
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;
@@ -0,0 +1,25 @@
1
+ import React, { useState } from 'react';
2
+ import * as style from './HelloWorld.module.css';
3
+
4
+ interface HelloWorldProps {
5
+ name: string;
6
+ }
7
+
8
+ const HelloWorld: React.FC<HelloWorldProps> = (props) => {
9
+ const [name, setName] = useState(props.name);
10
+
11
+ return (
12
+ <div>
13
+ <h3>Hello, {name}!</h3>
14
+ <hr />
15
+ <form>
16
+ <label className={style.bright} htmlFor="name">
17
+ Say hello to:
18
+ <input id="name" type="text" value={name} onChange={(e) => setName(e.target.value)} />
19
+ </label>
20
+ </form>
21
+ </div>
22
+ );
23
+ };
24
+
25
+ export default HelloWorld;
@@ -0,0 +1,5 @@
1
+ import HelloWorld from './HelloWorld.client';
2
+ // This could be specialized for server rendering
3
+ // For example, if using React Router, we'd have the SSR setup here.
4
+
5
+ export default HelloWorld;
@@ -0,0 +1,5 @@
1
+ import HelloWorld from './HelloWorld.client';
2
+ // This could be specialized for server rendering
3
+ // For example, if using React Router, we'd have the SSR setup here.
4
+
5
+ export default HelloWorld;
@@ -1,2 +1,2 @@
1
1
  <h1>Hello World</h1>
2
- <%%= react_component("<%= config[:component_name] %>", props: @hello_world_props, prerender: false) %>
2
+ <%%= react_component("<%= config[:component_name] %>", props: @hello_world_props, prerender: true) %>
@@ -3,8 +3,10 @@
3
3
  <head>
4
4
  <title>ReactOnRailsWithShakapacker</title>
5
5
  <%= csrf_meta_tags %>
6
- <%= javascript_pack_tag 'hello-world-bundle' %>
7
- <%= stylesheet_pack_tag 'hello-world-bundle' %>
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
- process.env.WEBPACK_SERVE && 'react-refresh/babel',
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,34 @@
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
+ require "bundler/setup"
22
+ require "react_on_rails/dev"
23
+
24
+ # Default route configuration
25
+ # This is set by the ReactOnRails installer to point to your generated component.
26
+ # Change this to your preferred default route, or pass --route=<route> to override.
27
+ DEFAULT_ROUTE = "hello_world"
28
+
29
+ # Main execution
30
+ # Add the default route to ARGV if no --route option is provided
31
+ argv_with_defaults = ARGV.dup
32
+ argv_with_defaults.push("--route", DEFAULT_ROUTE) unless argv_with_defaults.any? { |arg| arg.start_with?("--route") }
33
+
34
+ ReactOnRails::Dev::ServerManager.run_from_command_line(argv_with_defaults)
@@ -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 yarn command is run
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
- # config.components_subdirectory = "ror_components"
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 = false
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
- # Additional paths webpack should lookup modules
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
- # This is false since we're running `bin/shakapacker -w` in Procfile.dev-static
21
- compile: false
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: false
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: "0.0.0.0"
36
- # pathname: "/ws"
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: ['localhost']
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
@@ -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 webpackConfig = require('./webpackConfig');
5
+ const generateWebpackConfigs = require('./generateWebpackConfigs');
6
6
 
7
7
  const developmentEnvOnly = (clientWebpackConfig, _serverWebpackConfig) => {
8
- // plugins
9
- if (inliningCss) {
10
- // Note, when this is run, we're building the server and client bundles in separate processes.
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 = webpackConfig(developmentEnvOnly);
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 webpackConfig = require('./webpackConfig');
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 = webpackConfig(productionEnvOnly);
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 webpackConfig = require('./webpackConfig')
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 = webpackConfig(testOnly)
9
+ module.exports = generateWebpackConfigs(testOnly)
@@ -12,8 +12,6 @@ describe "Hello World", :js do
12
12
  end
13
13
  end
14
14
 
15
- private
16
-
17
15
  def name_input
18
16
  page.first("input")
19
17
  end
@@ -0,0 +1,18 @@
1
+ /* eslint-disable import/prefer-default-export */
2
+
3
+ import { HELLO_WORLD_NAME_UPDATE } from '../constants/helloWorldConstants';
4
+
5
+ // Action interface
6
+ export interface UpdateNameAction {
7
+ type: typeof HELLO_WORLD_NAME_UPDATE;
8
+ text: string;
9
+ }
10
+
11
+ // Union type for all actions
12
+ export type HelloWorldAction = UpdateNameAction;
13
+
14
+ // Action creator with proper TypeScript typing
15
+ export const updateName = (text: string): UpdateNameAction => ({
16
+ type: HELLO_WORLD_NAME_UPDATE,
17
+ text,
18
+ });
@@ -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;
@@ -0,0 +1,24 @@
1
+ import React from 'react';
2
+ import * as style from './HelloWorld.module.css';
3
+ import type { PropsFromRedux } from '../containers/HelloWorldContainer';
4
+
5
+ // Component props are inferred from Redux container
6
+ type HelloWorldProps = PropsFromRedux;
7
+
8
+ const HelloWorld: React.FC<HelloWorldProps> = ({ name, updateName }) => (
9
+ <div>
10
+ <h3>
11
+ Hello,
12
+ {name}!
13
+ </h3>
14
+ <hr />
15
+ <form>
16
+ <label className={style.bright} htmlFor="name">
17
+ Say hello to:
18
+ <input id="name" type="text" value={name} onChange={(e) => updateName(e.target.value)} />
19
+ </label>
20
+ </form>
21
+ </div>
22
+ );
23
+
24
+ export default HelloWorld;
@@ -0,0 +1,6 @@
1
+ /* eslint-disable import/prefer-default-export */
2
+
3
+ export const HELLO_WORLD_NAME_UPDATE = 'HELLO_WORLD_NAME_UPDATE' as const;
4
+
5
+ // Action type for TypeScript
6
+ export type HelloWorldActionType = typeof HELLO_WORLD_NAME_UPDATE;
@@ -0,0 +1,20 @@
1
+ // Simple example of a React "smart" component
2
+
3
+ import { connect, ConnectedProps } from 'react-redux';
4
+ import HelloWorld from '../components/HelloWorld';
5
+ import * as actions from '../actions/helloWorldActionCreators';
6
+ import type { HelloWorldState } from '../reducers/helloWorldReducer';
7
+
8
+ // Which part of the Redux global state does our component want to receive as props?
9
+ const mapStateToProps = (state: HelloWorldState) => ({ name: state.name });
10
+
11
+ // Create the connector
12
+ const connector = connect(mapStateToProps, actions);
13
+
14
+ // Infer the props from Redux state and actions
15
+ export type PropsFromRedux = ConnectedProps<typeof connector>;
16
+
17
+ // Don't forget to actually use connect!
18
+ // Note that we don't export HelloWorld, but the redux "connected" version of it.
19
+ // See https://github.com/reactjs/react-redux/blob/master/docs/api.md#examples
20
+ export default connector(HelloWorld);
@@ -0,0 +1,22 @@
1
+ import { combineReducers } from 'redux';
2
+ import { HELLO_WORLD_NAME_UPDATE } from '../constants/helloWorldConstants';
3
+ import { HelloWorldAction } from '../actions/helloWorldActionCreators';
4
+
5
+ // State interface
6
+ export interface HelloWorldState {
7
+ name: string;
8
+ }
9
+
10
+ // Individual reducer with TypeScript types
11
+ const name = (state: string = '', action: HelloWorldAction): string => {
12
+ switch (action.type) {
13
+ case HELLO_WORLD_NAME_UPDATE:
14
+ return action.text;
15
+ default:
16
+ return state;
17
+ }
18
+ };
19
+
20
+ const helloWorldReducer = combineReducers<HelloWorldState>({ name });
21
+
22
+ export default helloWorldReducer;
@@ -0,0 +1,23 @@
1
+ import { useMemo, type FC } from 'react';
2
+ import { Provider } from 'react-redux';
3
+
4
+ import configureStore, { type RailsProps } from '../store/helloWorldStore';
5
+ import HelloWorldContainer from '../containers/HelloWorldContainer';
6
+
7
+ // Props interface matches what Rails will pass from the controller
8
+ interface HelloWorldAppProps extends RailsProps {}
9
+
10
+ // See documentation for https://github.com/reactjs/react-redux.
11
+ // This is how you get props from the Rails view into the redux store.
12
+ // This code here binds your smart component to the redux store.
13
+ const HelloWorldApp: FC<HelloWorldAppProps> = (props) => {
14
+ const store = useMemo(() => configureStore(props), [props]);
15
+
16
+ return (
17
+ <Provider store={store}>
18
+ <HelloWorldContainer />
19
+ </Provider>
20
+ );
21
+ };
22
+
23
+ export default HelloWorldApp;
@@ -0,0 +1,5 @@
1
+ import HelloWorldApp from './HelloWorldApp.client';
2
+ // This could be specialized for server rendering
3
+ // For example, if using React Router, we'd have the SSR setup here.
4
+
5
+ export default HelloWorldApp;
@@ -0,0 +1,5 @@
1
+ import HelloWorldApp from './HelloWorldApp.client';
2
+ // This could be specialized for server rendering
3
+ // For example, if using React Router, we'd have the SSR setup here.
4
+
5
+ export default HelloWorldApp;
@@ -0,0 +1,18 @@
1
+ import { createStore } from 'redux';
2
+ import type { Store, PreloadedState } from 'redux';
3
+ import helloWorldReducer from '../reducers/helloWorldReducer';
4
+ import type { HelloWorldState } from '../reducers/helloWorldReducer';
5
+
6
+ // Rails props interface - customize based on your Rails controller
7
+ export interface RailsProps {
8
+ name: string;
9
+ [key: string]: any; // Allow additional props from Rails
10
+ }
11
+
12
+ // Store type
13
+ export type HelloWorldStore = Store<HelloWorldState>;
14
+
15
+ const configureStore = (railsProps: RailsProps): HelloWorldStore =>
16
+ createStore(helloWorldReducer, railsProps as PreloadedState<HelloWorldState>);
17
+
18
+ export default configureStore;
@@ -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
- # forces the loading of React components
50
- force_load: true,
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, :force_load, :rsc_bundle_js_file,
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, force_load: 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.force_load = force_load
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
@@ -175,7 +175,7 @@ module ReactOnRails
175
175
  end
176
176
 
177
177
  msg = <<~MSG
178
- ReactOnRails: Your current version of #{ReactOnRails::PackerUtils.packer_type.upcase_first} \
178
+ ReactOnRails: Your current version of shakapacker \
179
179
  does not support async script loading, which may cause performance issues. Please either:
180
180
  1. Use :sync or :defer loading strategy instead of :async
181
181
  2. Upgrade to Shakapacker v8.2.0 or above to enable async script loading
@@ -284,8 +284,10 @@ module ReactOnRails
284
284
  if ReactOnRails::PackerUtils.using_packer?
285
285
  packer_public_output_path = ReactOnRails::PackerUtils.packer_public_output_path
286
286
  # rubocop:disable Layout/LineLength
287
+ packer_name = ReactOnRails::PackerUtils.packer_type&.upcase_first
288
+
287
289
  Rails.logger.warn "Error configuring config/initializers/react_on_rails. Define neither the generated_assets_dirs nor " \
288
- "the generated_assets_dir when using #{ReactOnRails::PackerUtils.packer_type.upcase_first}. This is defined by " \
290
+ "the generated_assets_dir when using #{packer_name}. This is defined by " \
289
291
  "public_output_path specified in #{ReactOnRails::PackerUtils.packer_type}.yml = #{packer_public_output_path}."
290
292
  # rubocop:enable Layout/LineLength
291
293
  return
@@ -331,15 +333,17 @@ module ReactOnRails
331
333
  end
332
334
 
333
335
  def compile_command_conflict_message
336
+ packer_name = ReactOnRails::PackerUtils.packer_type.upcase_first
337
+ packer_type = ReactOnRails::PackerUtils.packer_type
334
338
  <<~MSG
335
339
 
336
- React on Rails and #{ReactOnRails::PackerUtils.packer_type.upcase_first} error in configuration!
340
+ React on Rails and #{packer_name} error in configuration!
337
341
  In order to use config/react_on_rails.rb config.build_production_command,
338
- you must edit config/#{ReactOnRails::PackerUtils.packer_type}.yml to include this value in the default configuration:
339
- '#{ReactOnRails::PackerUtils.packer_type}_precompile: false'
342
+ you must edit config/#{packer_type}.yml to include this value in the default configuration:
343
+ '#{packer_type}_precompile: false'
340
344
 
341
345
  Alternatively, remove the config/react_on_rails.rb config.build_production_command and the
342
- default bin/#{ReactOnRails::PackerUtils.packer_type} script will be used for assets:precompile.
346
+ default bin/#{packer_type} script will be used for assets:precompile.
343
347
 
344
348
  MSG
345
349
  end