react_on_rails 13.1.0 → 13.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 67d4584eb27dc3faa475b108565c57f201da8be1b50959f280c1e9904d22e891
4
- data.tar.gz: c1d0c37d9cf8be39c87b7976466c10d72837f7b777b39b5b1d3771fb1602c097
3
+ metadata.gz: 763474ed712a00d925c374048aca65cef79aa72ababa1ab3b06d00c8eb8ede2a
4
+ data.tar.gz: 47cb351a79b2aca23615ae60b5b9d8e2f4300b7d1e92abf04b67ed7d7ac54a18
5
5
  SHA512:
6
- metadata.gz: 8ddc27d5e684c33d23234221989fa04ba4c46a44ade8593a392e2444feb4b569a74334c3b704ff4124bc6ae89a8ca9210736ea37afb6e11e574c3aadafb2e0f4
7
- data.tar.gz: bbcdae693b9cad8f964ec85b89a61ad656b2192ee5b26476d039d3328d31eb47fd6c91e361b31d4ab68a2647477dcfb2d631b98a771e6d956ea44523aa55309d
6
+ metadata.gz: ddff41744b61108f731644f8e4d7e7f9e059ee25a656baf60ac4b9e58ad7da8e90bc047a8d2e0d91d2caf3947080a8afa305a4c9ce75a1e29635da61c3b78e4c
7
+ data.tar.gz: 8030fdb57740f229e97e6545d360c61f6fbdcad4d8a2b227d11b21693ff0ee10774d92c3b8076610724f9ba9f8eb8d5cf10271c3e9f0726022a1a57968afe363
@@ -8,13 +8,17 @@ jobs:
8
8
  matrix:
9
9
  ruby: [2.7]
10
10
  node: [14]
11
- runs-on: ubuntu-latest
11
+ runs-on: ubuntu-20.04
12
12
  steps:
13
13
  - uses: actions/checkout@v2
14
14
  - name: Setup Ruby
15
15
  uses: ruby/setup-ruby@v1
16
16
  with:
17
17
  ruby-version: ${{ matrix.ruby }}
18
+ # libyaml-dev is needed for psych v5
19
+ # this gem depends on sdoc which depends on rdoc which depends on psych
20
+ - name: Fix dependency for libyaml-dev
21
+ run: sudo apt install libyaml-dev
18
22
  - name: Setup Node
19
23
  uses: actions/setup-node@v2-beta
20
24
  with:
@@ -73,7 +77,7 @@ jobs:
73
77
  ruby: [2.7]
74
78
  node: [14]
75
79
  rake_task: ['run_rspec:all_dummy', 'run_rspec:all_but_examples', 'run_rspec:examples']
76
- runs-on: ubuntu-latest
80
+ runs-on: ubuntu-20.04
77
81
  steps:
78
82
  - uses: actions/checkout@v2
79
83
  - name: Setup Ruby
data/CHANGELOG.md CHANGED
@@ -17,6 +17,15 @@ Changes since last non-beta release.
17
17
 
18
18
  *Please add entries here for your pull requests that are not yet released.*
19
19
 
20
+ ### [13.2.0] - 2022-12-23
21
+
22
+ ### Fixed
23
+ - Fix reactOnRailsPageUnloaded when there is no component on the page. Important for apps using both hotwire and react_on_rails. [PR 1498](https://github.com/shakacode/react_on_rails/pull/1498) by [NhanHo](https://github.com/NhanHo).
24
+ - Fixing wrong type. The throwIfMissing param of getStore should be optional as it defaults to true. [PR 1480](https://github.com/shakacode/react_on_rails/pull/1480) by [wouldntsavezion](https://github.com/wouldntsavezion).
25
+
26
+ ### Added
27
+ - Exposed `reactHydrateOrRender` utility via [PR 1481](https://github.com/shakacode/react_on_rails/pull/1481) by [vaukalak](https://github.com/vaukalak).
28
+
20
29
  ### [13.1.0] - 2022-08-20
21
30
 
22
31
  #### Improved
@@ -1042,7 +1051,8 @@ Best done with Object destructing:
1042
1051
  ##### Fixed
1043
1052
  - Fix several generator related issues.
1044
1053
 
1045
- [Unreleased]: https://github.com/shakacode/react_on_rails/compare/13.0.2...master
1054
+ [Unreleased]: https://github.com/shakacode/react_on_rails/compare/13.2.0...master
1055
+ [13.2.0]: https://github.com/shakacode/react_on_rails/compare/13.1.0...13.2.0
1046
1056
  [13.1.0]: https://github.com/shakacode/react_on_rails/compare/13.0.2...13.1.0
1047
1057
  [13.0.2]: https://github.com/shakacode/react_on_rails/compare/13.0.1...13.0.2
1048
1058
  [13.0.1]: https://github.com/shakacode/react_on_rails/compare/13.0.0...13.0.1
@@ -7,7 +7,7 @@ gem "sqlite3"
7
7
  gem "sass-rails", "~> 6.0"
8
8
  gem "uglifier"
9
9
  gem "jquery-rails"
10
- gem "puma"
10
+ gem "puma", "~> 5.0"
11
11
 
12
12
  # Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
13
13
  gem "turbolinks" if ENV["DISABLE_TURBOLINKS"].nil? || ENV["DISABLE_TURBOLINKS"].strip.empty?
data/README.md CHANGED
@@ -48,6 +48,8 @@ To provide a high performance framework for integrating Ruby on Rails with React
48
48
 
49
49
  Given that `rails/webpacker` gem already provides basic React integration, why would you use "React on Rails"?
50
50
 
51
+ 1. Automatic configuration of what bundles are added to the page based on what React components are on the page. This results in faster browser loading time via smaller bundle sizes.
52
+ 1. Keep up with the latest changes of different versions of React. React 18 is supported.
51
53
  1. Easy passing of props directly from your Rails view to your React components rather than having your Rails view load and then make a separate request to your API.
52
54
  Tight integration with [shakapacker](https://github.com/shakacode/shakapacker) (or it's predecessor [rails/webpacker](https://github.com/rails/webpacker)).
53
55
  1. Server-Side Rendering (SSR), often used for SEO crawler indexing and UX performance.
@@ -58,6 +58,15 @@ The best source of docs is the main [ReactOnRails.js](https://github.com/shakaco
58
58
  */
59
59
  getStore(name, throwIfMissing = true )
60
60
 
61
+ /**
62
+ * Renders or hydrates the react element passed. In case react version is >=18 will use the new api.
63
+ * @param domNode
64
+ * @param reactElement
65
+ * @param hydrate if true will perform hydration, if false will render
66
+ * @returns {Root|ReactComponent|ReactElement|null}
67
+ */
68
+ reactHydrateOrRender(domNode, reactElement, hydrate)
69
+
61
70
  /**
62
71
  * Set options for ReactOnRails, typically before you call ReactOnRails.register
63
72
  * Available Options:
@@ -9,7 +9,10 @@ Note, the best way to understand how to use ReactOnRails is to study a few simpl
9
9
 
10
10
  ## Basic Installation
11
11
 
12
- *See also [the instructions for installing into an existing Rails app](https://www.shakacode.com/react-on-rails/docs/guides/installation-into-an-existing-rails-app/).*
12
+ These steps assume that you've got a rails application with webpacker (e.g. one
13
+ generated using `rails new my_app --javascript=webpack`). If your
14
+ application is not yet set up to use webpacker, please see
15
+ [the instructions for installing into an existing Rails app](https://www.shakacode.com/react-on-rails/docs/guides/installation-into-an-existing-rails-app/).*
13
16
 
14
17
  1. Add the `react_on_rails` gem to Gemfile:
15
18
 
@@ -158,7 +158,7 @@ ReactOnRails.configure do |config|
158
158
  # components_subdirectory is the name of the subdirectory matched to detect and register components automatically
159
159
  # The default is nil. You can enable the feature by updating it in the next line.
160
160
  config.components_subdirectory = "ror_components"
161
-
161
+
162
162
  # For automated component registry, `render_component` view helper method tries to load bundle for component from
163
163
  # generated directory. default is false, you can pass option at the time of individual usage or update the default
164
164
  # in the following line
@@ -226,7 +226,7 @@ ReactOnRails.configure do |config|
226
226
  #
227
227
  # Define the files we need to check for webpack compilation when running tests.
228
228
  # The default is `%w( manifest.json )` as will be sufficient for most webpacker builds.
229
- # However, if you are generated a server bundle that is NOT hashed (present in manifest.json),
229
+ # However, if you are generating a server bundle that is NOT hashed (present in manifest.json),
230
230
  # then include the file in this list like this:
231
231
  config.webpack_generated_files = %w( server-bundle.js manifest.json )
232
232
  # Note, be sure NOT to include your server-bundle.js if it is hashed, or else React on Rails will
@@ -5,7 +5,8 @@ To use the automated bundle generation feature introduced in React on Rails v13.
5
5
  ## Configuration
6
6
 
7
7
  ### Enable nested_entries for Shakapacker
8
- To use the automated bundle generation feature, set nested_entries: true in the webpacker.yml file like this. The generated files will go in a nested directory.
8
+ To use the automated bundle generation feature, set `nested_entries: true` in the `webpacker.yml` file like this.
9
+ The generated files will go in a nested directory.
9
10
 
10
11
  ```yml
11
12
  default:
@@ -36,7 +37,7 @@ config.auto_load_bundle = true
36
37
  ```
37
38
 
38
39
  ### Update `.gitignore` file
39
- React on Rails automatically generates pack files for components to be registered in the `packs/generated` directory. To avoid committing generated files into the version control system, please update `.gitignore` to have
40
+ React on Rails automatically generates pack files for components to be registered in the `packs/generated` directory. To avoid committing generated files into the version control system, please update `.gitignore` to have
40
41
 
41
42
  ```gitignore
42
43
  # Generated React on Rails packs
@@ -55,11 +56,11 @@ If the `webpacker.yml` file is configured as instructed [here](https://github.co
55
56
  ```yml
56
57
  default: &default
57
58
  source_path: app/javascript
58
- source_entry_path: packs
59
+ source_entry_path: packs
59
60
  public_root_path: public
60
61
  public_output_path: packs
61
62
  nested_entries: true
62
- # And more
63
+ # And more
63
64
  ```
64
65
 
65
66
  the directory structure will look like this
@@ -100,7 +101,7 @@ Your layout would contain:
100
101
  ```
101
102
 
102
103
 
103
- Suppose, you want to use bundle splitting to minimize unnecessary javascript loaded on each page, You would put each of your components in the `packs` directory.
104
+ Suppose, you want to use bundle splitting to minimize unnecessary javascript loaded on each page, you would put each of your components in the `packs` directory.
104
105
  ```
105
106
  app/javascript:
106
107
  └── packs: # sets up webpack entries
@@ -138,8 +139,8 @@ Your layout would now contain:
138
139
 
139
140
  ```
140
141
  app/javascript:
141
- └── packs
142
- └── src:
142
+ └── packs
143
+ └── src:
143
144
  │ └── Foo
144
145
  │ │ └── ...
145
146
  │ │ └── ror_components # configured as `components_subdirectory`
@@ -148,25 +149,25 @@ app/javascript:
148
149
  │ │ └── ...
149
150
  │ │ └── ror_components # configured as `components_subdirectory`
150
151
  │ │ │ └── BarComponentOne.jsx
151
- │ │ │ └── BarComponentTwo.jsx
152
+ │ │ │ └── BarComponentTwo.jsx
152
153
  ```
153
154
 
154
155
  4. You no longer need to register these React components nor directly add their bundles. For example you can have a Rails view using three components:
155
156
 
156
157
  ```erb
157
- <%= react_component("FooComponentOne", {}, auto_load_bundle: true) %>
158
- <%= react_component("BarComponentOne", {}, auto_load_bundle: true) %>
159
- <%= react_component("BarComponentTwo", {}, auto_load_bundle: true) %>
158
+ <%= react_component("FooComponentOne", {}, auto_load_bundle: true) %>
159
+ <%= react_component("BarComponentOne", {}, auto_load_bundle: true) %>
160
+ <%= react_component("BarComponentTwo", {}, auto_load_bundle: true) %>
160
161
  ```
161
162
 
162
163
  If `FooComponentOne` uses multiple HTML strings for server rendering, the [`react_component_hash`](https://www.shakacode.com/react-on-rails/docs/api/view-helpers-api/#react_component_hash) view helper can be used on the Rails view, as illustrated below.
163
164
 
164
165
  ```erb
165
- <% foo_component_one_data = react_component_hash("FooComponentOne",
166
+ <% foo_component_one_data = react_component_hash("FooComponentOne",
166
167
  prerender: true,
167
168
  auto_load_bundle: true
168
169
  props: {}
169
- ) %>
170
+ ) %>
170
171
  <% content_for :title do %>
171
172
  <%= foo_component_one_data['title'] %>
172
173
  <% end %>
@@ -3,9 +3,9 @@
3
3
  You only _need_ props hydration if you need SSR. However, there's no good reason to
4
4
  have your app make a second round trip to the Rails server to get initialization props.
5
5
 
6
- **Server-Side Rendering (SSR)** results in Rails rendering HTML for your React components. The main reasons to use SSR are better SEO and pages display more quickly.
6
+ **Server-Side Rendering (SSR)** results in Rails rendering HTML for your React components. The main reasons to use SSR are better SEO and pages display more quickly.
7
7
 
8
- These gems provide advanced integration of React with [rails/webpacker](https://github.com/rails/webpacker):
8
+ These gems provide advanced integration of React with [rails/webpacker](https://github.com/rails/webpacker):
9
9
 
10
10
  | Gem | Props Hydration | Server-Side-Rendering (SSR) | SSR with HMR | SSR with React-Router | SSR with Code Splitting | Node SSR |
11
11
  | --- | --------------- | --- | --------------------- | ----------------------| ------------------------|----|
@@ -19,7 +19,7 @@ Note, Node SSR for React on Rails requires [React on Rails Pro](https://www.shak
19
19
 
20
20
  As mentioned, you don't _need_ to use a gem to integrate Rails with React.
21
21
 
22
- If you're not concerned with view helpers to pass props or server rendering, can do it yourself:
22
+ If you're not concerned with view helpers to pass props or server rendering, you can do it yourself:
23
23
 
24
24
  ```erb
25
25
  <%# views/layouts/application.html.erb %>
@@ -71,7 +71,7 @@ development:
71
71
  inline: true
72
72
  ```
73
73
 
74
- This basic configuration alone will have HMR working with the default webpacker setup. However, an code saves will trigger a full page refresh each time you save a file.
74
+ This basic configuration alone will have HMR working with the default webpacker setup. However, a code save will trigger a full page refresh each time you save a file.
75
75
 
76
76
  Webpack's HMR allows the replacement of modules for React in-place without reloading the browser. To do this, you have two options:
77
77
 
@@ -95,9 +95,9 @@ You can see an example commit of adding this [here](https://github.com/shakacode
95
95
  ```js
96
96
  const ReactRefreshWebpackPlugin = require('@pmmmwh/react-refresh-webpack-plugin');
97
97
  const environment = require('./environment')
98
-
98
+
99
99
  const isWebpackDevServer = process.env.WEBPACK_DEV_SERVER;
100
-
100
+
101
101
  //plugins
102
102
  if (isWebpackDevServer) {
103
103
  environment.plugins.append(
@@ -164,11 +164,11 @@ const environment = require('./environment')
164
164
  + if (!module.hot) {
165
165
  + environment.loaders.get('sass').use.find(item => item.loader === 'sass-loader').options.sourceMapContents = false
166
166
  + }
167
- +
167
+ +
168
168
  module.exports = environment.toWebpackConfig()
169
169
  ```
170
170
 
171
- 5. Adjust your `config/webpack/environment.js` for a
171
+ 5. Adjust your `config/webpack/environment.js` for a
172
172
 
173
173
  ```diff
174
174
  // config/webpack/environment.js
@@ -17,7 +17,7 @@ See [this note](https://www.shakacode.com/react-on-rails/docs/guides/client-vs-s
17
17
 
18
18
  ## How do you do Server Rendering with React on Rails?
19
19
  1. The `react_component` view helper method provides the `prerender:` option to switch on or off server rendering.
20
- 1. Configure your Webpack setup to create a different server bundle per your needs. While you may reuse the same bundle as for client rendering, this is not common in larger apps for many reasons, such as as code splitting, handling CSS and images, different code paths for React Router on the server vs. client, etc.
20
+ 1. Configure your Webpack setup to create a different server bundle per your needs. While you may reuse the same bundle as for client rendering, this is not common in larger apps for many reasons, such as code splitting, handling CSS and images, different code paths for React Router on the server vs. client, etc.
21
21
  1. You need to configure `config.server_bundle_js_file = "server-bundle.js"` in your `config/initializers/react_on_rails.rb`
22
22
  1. You should ***not*** put a hash on the server-bundle so that you can easily use the webpack-dev-server for client bundles and have the server bundle generated by a watch process.
23
23
 
@@ -50,7 +50,7 @@ cd <directory where you want to create your new Rails app>
50
50
  # Any name you like for the rails app
51
51
  # Skip javascript so will add that next and get the current version
52
52
  # This is for Rails 7
53
- rails new --skip-turbolinks --skip-javascript test-react-on-rails
53
+ rails new test-react-on-rails --skip-turbolinks --skip-javascript
54
54
 
55
55
  cd test-react-on-rails
56
56
  ```
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ReactOnRails
4
- VERSION = "13.1.0"
4
+ VERSION = "13.2.0"
5
5
  end
data/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-on-rails",
3
- "version": "13.1.0",
3
+ "version": "13.2.0",
4
4
  "description": "react-on-rails JavaScript for react_on_rails Ruby gem",
5
5
  "main": "node_package/lib/ReactOnRails.js",
6
6
  "directories": {
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: react_on_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 13.1.0
4
+ version: 13.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Justin Gordon
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-08-21 00:00:00.000000000 Z
11
+ date: 2023-01-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: addressable