Skip to content

Commit

Permalink
11.0.1 Fixes (#1068)
Browse files Browse the repository at this point in the history
- `react_component` allows logging_on_server specified at the component level.
- Missing class when throwing some error messages.
  • Loading branch information
justin808 authored Apr 24, 2018
1 parent ede0ac8 commit 57fdc40
Show file tree
Hide file tree
Showing 11 changed files with 172 additions and 142 deletions.
10 changes: 9 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@ Changes since last non-beta release.

*Please add entries here for your pull requests that are not yet released.*

### [11.0.1] - 2018-04-23

#### Added
- `react_component` allows logging_on_server specified at the component level. [PR 1068](https://github.com/shakacode/react_on_rails/pull/1068) by [justin808](https://github.com/justin808).

#### Fixed
- Missing class when throwing some error messages. [PR 1068](https://github.com/shakacode/react_on_rails/pull/1068) by [justin808](https://github.com/justin808).

### [11.0.0] - 2018-04-21

## MIGRATION for v11
Expand All @@ -24,7 +32,7 @@ Changes since last non-beta release.
- Removed ReactOnRails::Utils.server_bundle_file_name and ReactOnRails::Utils.bundle_file_name.
- No longer logging the `railsContext` when server logging.
- Rails.env is provided in the default railsContext, as suggested in [issue #697](https://github.com/shakacode/react_on_rails/issues/697).
[PR 1018](https://github.com/shakacode/react_on_rails/pull/1065) by [justin808](https://github.com/justin808).
[PR 1065](https://github.com/shakacode/react_on_rails/pull/1065) by [justin808](https://github.com/justin808).

#### Fixes
- More exact version checking. We keep the react_on_rails gem and the react-on-rails node package at
Expand Down
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -523,13 +523,17 @@ react_component(component_name,
```

+ **component_name:** Can be a React component, created using an ES6 class or a generator function that returns a React component (or, only on the server side, an object with shape { redirectLocation, error, renderedHtml }), or a "renderer function" that manually renders a React component to the dom (client side only).
+ **options:**
All options except `props, id, html_options` will inherit from your `react_on_rails.rb` initializer, as described [here](./docs/basics/configuration.md).

+ **general options:**
+ **props:** Ruby Hash which contains the properties to pass to the react object, or a JSON string. If you pass a string, we'll escape it for you.
+ **prerender:** enable server-side rendering of a component. Set to false when debugging!
+ **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.
+ **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`.
+ **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.
+ **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 default configuration of `logging_on_server` set to true, you'll still see the errors on the server.
+ **options if prerender (server rendering) is true:**
+ **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.
+ **logging_on_server:** Default is true. True will log JS console messages and errors to the server.
+ **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.

### redux_store
Expand Down
2 changes: 1 addition & 1 deletion lib/react_on_rails.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
require "react_on_rails/configuration"
require "react_on_rails/server_rendering_pool"
require "react_on_rails/engine"
require "react_on_rails/react_component/options"
require "react_on_rails/react_component/render_options"
require "react_on_rails/version_syntax_converter"
require "react_on_rails/test_helper"
require "react_on_rails/git_utils"
Expand Down
6 changes: 4 additions & 2 deletions lib/react_on_rails/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ def self.configure
end

DEFAULT_GENERATED_ASSETS_DIR = File.join(%w[public webpack], Rails.env).freeze
DEFAULT_SERVER_RENDER_TIMEOUT = 20
DEFAULT_POOL_SIZE = 1

def self.setup_config_values
ensure_webpack_generated_files_exists
Expand Down Expand Up @@ -112,8 +114,8 @@ def self.configuration
raise_on_prerender_error: false,
trace: Rails.env.development?,
development_mode: Rails.env.development?,
server_renderer_pool_size: 1,
server_renderer_timeout: 20,
server_renderer_pool_size: DEFAULT_POOL_SIZE,
server_renderer_timeout: DEFAULT_SERVER_RENDER_TIMEOUT,
skip_display_none: nil,
# skip_display_none is deprecated
webpack_generated_files: %w[manifest.json],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,22 @@

module ReactOnRails
module ReactComponent
class Options
class RenderOptions
include Utils::Required

NO_PROPS = {}.freeze

def initialize(name: required("name"), options: required("options"))
@name = name
def initialize(react_component_name: required("react_component_name"), options: required("options"))
@react_component_name = react_component_name.camelize
@options = options
end

attr_reader :react_component_name

def props
options.fetch(:props) { NO_PROPS }
end

def name
@name.camelize
end

def dom_id
@dom_id ||= options.fetch(:id) { generate_unique_dom_id }
end
Expand All @@ -46,12 +44,20 @@ def raise_on_prerender_error
retrieve_key(:raise_on_prerender_error)
end

def logging_on_server
retrieve_key(:logging_on_server)
end

def to_s
"{ react_component_name = #{react_component_name}, options = #{options}"
end

private

attr_reader :options

def generate_unique_dom_id
"#{@name}-react-component-#{SecureRandom.uuid}"
"#{react_component_name}-react-component-#{SecureRandom.uuid}"
end

def retrieve_key(key)
Expand Down
Loading

0 comments on commit 57fdc40

Please sign in to comment.