react_on_rails 11.0.10 → 11.1.0.beta.1

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: c451d146d7a22f7a7ef543534018d2b8f02b6c9f1a9544e32a4be1bc5adefa09
4
- data.tar.gz: d4348d9c3c67e9a508bc9a53bab51a83077beb609c6b34a524519d788cfd5202
3
+ metadata.gz: f5687d77e654b890214e39ea3536ed17983845335c442d2eb2cd4a8b09728205
4
+ data.tar.gz: 33976af7da00de964d3385772a57e9e0aa45f068ebe4d1e3a6590b963e524e8b
5
5
  SHA512:
6
- metadata.gz: 555fcb6cec66efa9f6d2ecaa834097f4706a20622abf3152d9261e027b5b07c46c511448ef2382b122471a30fce39b828f3d3e9b1e18607b096dcec59385107f
7
- data.tar.gz: 3ecaf4ab4726e7e77781a735c35163a1bcb230f6d3700a105f490fa6d45217641d5f3b2124f1109610a3b63920f3d2fc96b243322f549cab61f0d5dd796880fa
6
+ metadata.gz: dcc783be172cce095c75115e11d3bedfcf1f8e801cc577ab001087704985c644b68dae9403ae911ba0371317d32147b773e058395e27250bbac201186895b25d
7
+ data.tar.gz: '0068fd2eb0ed4965a5a3e89f8915f11444ff591c83a62f72250a51f75d0b6a18c74589bf57f0add986f27941110c39c527ffd35a8f5f80353490ca0ca9fa0afd'
@@ -3,6 +3,8 @@
3
3
 
4
4
  Once the bundled files have been generated in your `app/assets/webpack` folder and you have registered your components, you will want to render these components on your Rails views using the included helper method, `react_component`.
5
5
 
6
+ ------------
7
+
6
8
  ### react_component
7
9
 
8
10
  ```ruby
@@ -24,11 +26,13 @@ react_component(component_name,
24
26
  - **id:** Id for the div, will be used to attach the React component. This will get assigned automatically if you do not provide an id. Must be unique.
25
27
  - **html_options:** Any other HTML options get placed on the added div for the component. For example, you can set a class (or inline style) on the outer div so that it behaves like a span, with the styling of `display:inline-block`.
26
28
  - **trace:** set to true to print additional debugging information in the browser. Defaults to true for development, off otherwise. Only on the **client side** will you will see the `railsContext` and your props.
29
+ - **random_dom_id:** True to automatically generate random dom ids when using multiple instances of the same React component on one Rails view.
27
30
  - **options if prerender (server rendering) is true:**
28
31
  - **replay_console:** Default is true. False will disable echoing server-rendering logs to the browser. While this can make troubleshooting server rendering difficult, so long as you have the configuration of `logging_on_server` set to true, you'll still see the errors on the server.
29
32
  - **logging_on_server:** Default is true. True will log JS console messages and errors to the server.
30
33
  - **raise_on_prerender_error:** Default is false. True will throw an error on the server side rendering. Your controller will have to handle the error.
31
34
 
35
+ -------------
32
36
 
33
37
  ### react_component_hash
34
38
 
@@ -68,6 +72,8 @@ export default (props, _railsContext) => {
68
72
 
69
73
  ```
70
74
 
75
+ ------------
76
+
71
77
  ### cached_react_component and cached_react_component_hash
72
78
  Fragment caching is a [React on Rails Pro](https://github.com/shakacode/react_on_rails/wiki) feature. The API is the same as the above, but for 2 differences:
73
79
 
@@ -79,10 +85,13 @@ Fragment caching is a [React on Rails Pro](https://github.com/shakacode/react_on
79
85
  some_slow_method_that_returns_props
80
86
  end %>
81
87
  ```
88
+ ------------
89
+
82
90
  ### rails_context
83
91
 
84
92
  You can call `rails_context(server_side: true | false)` from your controller or view to see what values are are in the Rails Context. Pass true or false depending on whether you want to see the server side or the client side rails_context.
85
93
 
94
+ ------------
86
95
 
87
96
  ### Renderer Functions (function that will call ReactDOM.render or ReactDOM.hydrate)
88
97
 
@@ -92,6 +101,8 @@ Why would you want to call `ReactDOM.hydrate` yourself? One possible use case is
92
101
 
93
102
  Renderer functions are not meant to be used on the server since there's no DOM on the server. Instead, use a generator function. Attempting to server render with a renderer function will throw an error.
94
103
 
104
+ ------------
105
+
95
106
  ### React Router
96
107
 
97
108
  [React Router](https://github.com/reactjs/react-router) is supported, including server-side rendering! See:
@@ -100,6 +111,8 @@ Renderer functions are not meant to be used on the server since there's no DOM o
100
111
  2. Examples in [spec/dummy/app/views/react_router](../../spec/dummy/app/views/react_router) and follow to the JavaScript code in the [spec/dummy/client/app/startup/ServerRouterApp.jsx](../../spec/dummy/client/app/startup/ServerRouterApp.jsx).
101
112
  3. [Code Splitting docs](../misc-pending/code-splitting.md) for information about how to set up code splitting for server rendered routes.
102
113
 
114
+ ------------
115
+
103
116
  ## server_render_js
104
117
 
105
118
  `server_render_js(js_expression, options = {})`
@@ -109,6 +122,8 @@ Renderer functions are not meant to be used on the server since there's no DOM o
109
122
 
110
123
  This is a helper method that takes any JavaScript expression and returns the output from evaluating it. If you have more than one line that needs to be executed, wrap it in an IIFE. JS exceptions will be caught and console messages handled properly.
111
124
 
125
+ ------------
126
+
112
127
  # More details
113
128
 
114
129
  See the [lib/react_on_rails/helper.rb](../../lib/react_on_rails/helper.rb) source.
@@ -12,6 +12,15 @@ ReactOnRails.configure do |config|
12
12
  # setInterval, clearTimout when server rendering.
13
13
  config.trace = Rails.env.development?
14
14
 
15
+ # Configure if default DOM IDs have a random value or are fixed.
16
+ # false ==> Sets the dom id to "#{react_component_name}-react-component"
17
+ # true ==> Adds "-#{SecureRandom.uuid}" to that ID
18
+ # If you might use multiple instances of the same React component on a Rails page, then
19
+ # it is convenient to set this to true or else you have to either manually set the ids to
20
+ # avoid collisions. Most newer apps will have only one instance of a component on a page,
21
+ # so this should be false in most cases.
22
+ # This value can be overrident for a given call to react_component
23
+ config.random_dom_id = false # default is true
15
24
 
16
25
  # defaults to "" (top level)
17
26
  #
@@ -9,6 +9,7 @@ module ReactOnRails
9
9
  DEFAULT_GENERATED_ASSETS_DIR = File.join(%w[public webpack], Rails.env).freeze
10
10
  DEFAULT_SERVER_RENDER_TIMEOUT = 20
11
11
  DEFAULT_POOL_SIZE = 1
12
+ DEFAULT_RANDOM_DOM_ID = TRUE # for backwards compatability
12
13
 
13
14
  def self.configuration
14
15
  @configuration ||= Configuration.new(
@@ -32,7 +33,8 @@ module ReactOnRails
32
33
  server_render_method: nil,
33
34
  symlink_non_digested_assets_regex: nil,
34
35
  build_test_command: "",
35
- build_production_command: ""
36
+ build_production_command: "",
37
+ random_dom_id: DEFAULT_RANDOM_DOM_ID
36
38
  )
37
39
  end
38
40
 
@@ -45,7 +47,7 @@ module ReactOnRails
45
47
  :webpack_generated_files, :rendering_extension, :build_test_command,
46
48
  :build_production_command,
47
49
  :i18n_dir, :i18n_yml_dir,
48
- :server_render_method, :symlink_non_digested_assets_regex
50
+ :server_render_method, :symlink_non_digested_assets_regex, :random_dom_id
49
51
 
50
52
  def initialize(node_modules_location: nil, server_bundle_js_file: nil, prerender: nil,
51
53
  replay_console: nil,
@@ -56,7 +58,7 @@ module ReactOnRails
56
58
  generated_assets_dir: nil, webpack_generated_files: nil,
57
59
  rendering_extension: nil, build_test_command: nil,
58
60
  build_production_command: nil,
59
- i18n_dir: nil, i18n_yml_dir: nil,
61
+ i18n_dir: nil, i18n_yml_dir: nil, random_dom_id: nil,
60
62
  server_render_method: nil, symlink_non_digested_assets_regex: nil)
61
63
  self.node_modules_location = node_modules_location.present? ? node_modules_location : Rails.root
62
64
  self.server_bundle_js_file = server_bundle_js_file
@@ -67,6 +69,7 @@ module ReactOnRails
67
69
  self.i18n_dir = i18n_dir
68
70
  self.i18n_yml_dir = i18n_yml_dir
69
71
 
72
+ self.random_dom_id = random_dom_id
70
73
  self.prerender = prerender
71
74
  self.replay_console = replay_console
72
75
  self.logging_on_server = logging_on_server
@@ -98,6 +98,7 @@ module ReactOnRails
98
98
  # raise_on_prerender_error: <true/false> Default to false. True will raise exception on server
99
99
  # if the JS code throws
100
100
  # Any other options are passed to the content tag, including the id.
101
+ # random_dom_id can be set to override the global default.
101
102
  def react_component(component_name, options = {})
102
103
  internal_result = internal_react_component(component_name, options)
103
104
  server_rendered_html = internal_result[:result]["html"]
@@ -22,8 +22,26 @@ module ReactOnRails
22
22
  options.fetch(:props) { NO_PROPS }
23
23
  end
24
24
 
25
+ def random_dom_id
26
+ retrieve_key(:random_dom_id)
27
+ end
28
+
25
29
  def dom_id
26
- @dom_id ||= options.fetch(:id) { generate_unique_dom_id }
30
+ @dom_id ||= options.fetch(:id) do
31
+ if random_dom_id
32
+ generate_unique_dom_id
33
+ else
34
+ base_dom_id
35
+ end
36
+ end
37
+ end
38
+
39
+ def has_random_dom_id?
40
+ return false if options[:id]
41
+
42
+ return false unless random_dom_id
43
+
44
+ true
27
45
  end
28
46
 
29
47
  def html_options
@@ -58,8 +76,12 @@ module ReactOnRails
58
76
 
59
77
  attr_reader :options
60
78
 
79
+ def base_dom_id
80
+ "#{react_component_name}-react-component"
81
+ end
82
+
61
83
  def generate_unique_dom_id
62
- "#{react_component_name}-react-component-#{SecureRandom.uuid}"
84
+ "#{base_dom_id}-#{SecureRandom.uuid}"
63
85
  end
64
86
 
65
87
  def retrieve_key(key)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ReactOnRails
4
- VERSION = "11.0.10".freeze
4
+ VERSION = "11.1.0.beta.1".freeze
5
5
  end
data/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-on-rails",
3
- "version": "11.0.10",
3
+ "version": "11.1.0-beta.1",
4
4
  "description": "react-on-rails JavaScript for react_on_rails Ruby gem",
5
5
  "main": "node_package/lib/ReactOnRails.js",
6
6
  "directories": {
@@ -54,7 +54,7 @@
54
54
  "test": "babel-tape-runner -r node_package/tests/helpers/test_helper.js node_package/tests/*.js | tap-spec",
55
55
  "clean": "rm -rf node_package/lib",
56
56
  "prepare": "yarn run build",
57
- "prepublish": "check-node-version --npm \">=4\" || npm run prepare",
57
+ "prepublish": "npm run prepare",
58
58
  "babel": "babel --out-dir node_package/lib node_package/src",
59
59
  "build": "yarn run clean && yarn run babel",
60
60
  "build-watch": "babel --watch --out-dir node_package/lib node_package/src",
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: react_on_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 11.0.10
4
+ version: 11.1.0.beta.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Justin Gordon
@@ -503,9 +503,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
503
503
  version: 2.1.0
504
504
  required_rubygems_version: !ruby/object:Gem::Requirement
505
505
  requirements:
506
- - - ">="
506
+ - - ">"
507
507
  - !ruby/object:Gem::Version
508
- version: '0'
508
+ version: 1.3.1
509
509
  requirements: []
510
510
  rubyforge_project:
511
511
  rubygems_version: 2.7.7