Skip to content

Commit a44cfb2

Browse files
coopersamueljustin808
authored andcommitted
Add option or ReactOnRails.render of hydrate (#1159)
To support React v16, updated API for ReactOnRails.render(name, props, domNodeId, hydrate) { * Added 3rd @PARAM hydrate Pass truthy to update server rendered html. Default is falsey Any truthy values calls hydrate rather than render Other updates: * upgraded react and react DOM, fixed breaking test * updated all minor and patch release packages * updated eslint and flow, fixed a few eslint errors, ignored a flow error added a few rules in eslintrc * updated redux, no broken tests * updated tap-spec and release-it * updated dummy apps gemfile, specified version for miniracer * poltergeist removal * Updates to spec/dummy for new packages * add prettier, but not enforcing * Change String.match? to =~ b/c Can't use match? on Ruby 2.2. Uncomment when Ruby 2.4 is used for all test platforms
1 parent 18e7840 commit a44cfb2

79 files changed

Lines changed: 5456 additions & 3264 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.eslintrc

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
---
2-
extends: eslint-config-shakacode
2+
extends:
3+
- eslint-config-shakacode
4+
- prettier
5+
- prettier/react
36

47
plugins:
5-
- react
8+
- prettier
69

710
globals:
811
__DEBUG_SERVER_ERRORS__: true
@@ -15,6 +18,9 @@ env:
1518

1619
rules:
1720
no-console: 0
21+
function-paren-newline: 0
22+
object-curly-newline: 0
23+
1824

1925
# https://github.com/benmosher/eslint-plugin-import/issues/340
2026
import/no-extraneous-dependencies: 0

.prettierignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules

.prettierrc

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
printWidth: 110
2+
tabWidth: 2
3+
useTabs: false
4+
semi: true
5+
singleQuote: true
6+
trailingComma: all
7+
bracketSpacing: true
8+
jsxBracketSameLine: false
9+
parser: flow
10+
11+
overrides:
12+
- files: "*.@(css|scss)"
13+
options:
14+
parser: css
15+
singleQuote: false
16+
printWidth: 120
17+
- files: "*.@(json)"
18+
options:
19+
parser: json
20+
printWidth: 100

CONTRIBUTING.md

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -127,14 +127,6 @@ _Note: running `npm i` automatically builds the npm package before installing. H
127127
### Prereqs
128128
After checking out the repo, making sure you have rvm and nvm setup (setup ruby and node), cd to `spec/dummy` and run `bin/setup` to install ruby dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
129129

130-
Additionally, our RSpec tests use the poltergeist web driver. You will need to install the phantomjs node module:
131-
132-
```sh
133-
yarn global add phantomjs-prebuilt
134-
```
135-
136-
Note this *must* be installed globally for the dummy test project rspec runner to see it properly.
137-
138130
### Local Node Package
139131
Because the example and dummy apps rely on the react-on-rails node package, they should link directly to your local version to pick up any changes you may have made to that package. To achieve this, switch to the dummy app's root directory and run this command below which runs something like [this script](spec/dummy/package.json#L14)
140132

@@ -171,7 +163,7 @@ spec/dummy.
171163

172164
```sh
173165
# Optionally change default selenium_firefox driver
174-
export DRIVER=poltergeist
166+
export DRIVER=selenium_firefox
175167
cd react_on_rails/
176168
yarn run dummy:spec
177169
```

Gemfile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ gem "capybara"
3232
gem "capybara-screenshot"
3333
gem "chromedriver-helper"
3434
gem "launchy"
35-
gem "poltergeist"
3635
gem "rspec-rails"
3736
gem "rspec-retry"
3837
gem "selenium-webdriver"

Gemfile.rails32

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ group :test do
6565
gem "chromedriver-helper"
6666
gem "generator_spec"
6767
gem "launchy"
68-
gem "poltergeist"
6968
gem "rspec-rails"
7069
gem "rspec-retry"
7170
gem "selenium-webdriver"

docs/additional-reading/images.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ const assetLoaderRules = [
3939

4040

4141

42-
A full example can be found at [spec/dummy/client/app/components/ImageExample/ImageExample.js](../../spec/dummy/client/app/components/ImageExample/ImageExample.js)
42+
A full example can be found at [spec/dummy/client/app/components/ImageExample/ImageExample.jsx](../../spec/dummy/client/app/components/ImageExample/ImageExample.jsx)
4343

4444
You are free to use images either in image tags or as background images in SCSS files. You can
4545
use a "global" location of /client/app/assets/images or a relative path to your JS or SCSS file, as

docs/additional-reading/rails_view_rendering_from_inline_javascript.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,10 @@ You can easily render React components in your JavaScript with `render` method t
1212
* @param name Name of your registered component
1313
* @param props Props to pass to your component
1414
* @param domNodeId
15+
* @param hydrate [optional] Pass truthy to update server rendered html. Default is falsy
1516
* @returns {virtualDomElement} Reference to your component's backing instance
1617
*/
17-
ReactOnRails.render(componentName, props, elementId)
18+
ReactOnRails.render(componentName, props, domNodeId)
1819
```
1920

2021
## Why do we need this?

docs/api/view-helpers-api.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ adding meta-tags to a page. It is exactly like react_component except for the fo
4141

4242
1. `prerender: true` is automatically added to options, as this method doesn't make sense for
4343
client only rendering.
44-
2. Your JavaScript for server rendering must return an Object for the key `server_rendered_html`.
44+
2. Your JavaScript generator function for server rendering must return an Object rather than a React Component.
4545
3. Your view code must expect an object and not a string.
4646

4747
Here is an example of ERB view code:

docs/misc-pending/code-splitting.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Different markup is generated on the client than on the server. Why does this ha
2121

2222
### The solution
2323

24-
To prevent this, you have to wait until the code chunk is fetched before doing the initial render on the client side. To accomplish this, react on rails allows you to register a renderer. This works just like registering a generator function, except that the function you pass takes three arguments: `renderer(props, railsContext, domNodeId)`, and is responsible for calling `ReactDOM.render` to render the component to the DOM. React on rails will automatically detect when a generator function takes three arguments, and will not call `ReactDOM.render`, instead allowing you to control the initial render yourself.
24+
To prevent this, you have to wait until the code chunk is fetched before doing the initial render on the client side. To accomplish this, react on rails allows you to register a renderer. This works just like registering a generator function, except that the function you pass takes three arguments: `renderer(props, railsContext, domNodeId)`, and is responsible for calling `ReactDOM.render` or `ReactDOM.hydrate` to render the component to the DOM. React on rails will automatically detect when a generator function takes three arguments, and will not call `ReactDOM.render` or `ReactDOM.hydrate`, instead allowing you to control the initial render yourself. Note, you have to be careful to call `ReactDOM.hydrate` rather than `ReactDOM.render` if you are are server rendering.
2525

2626
Here's an example of how you might use this in practice:
2727

@@ -115,7 +115,7 @@ See:
115115

116116
- [spec/dummy/client/app/startup/clientRegistration.jsx](https://github.com/shakacode/react_on_rails/tree/master/spec/dummy/client/app/startup/clientRegistration.jsx)
117117
- [spec/dummy/client/app/startup/serverRegistration.jsx](https://github.com/shakacode/react_on_rails/tree/master/spec/dummy/client/app/startup/serverRegistration.jsx)
118-
- [spec/dummy/client/app/startup/DeferredRenderAppRenderer.jsx](https://github.com/shakacode/react_on_rails/tree/master/spec/dummy/client/app/startup/DeferredRenderAppRenderer.jsx) <-- Code splitting implemented here
118+
- [spec/dummy/client/app/startup/DeferredRenderAppClient](https://github.com/shakacode/react_on_rails/tree/master/spec/dummy/client/app/startup/DeferredRenderAppClient.jsx)<-- Code splitting implemented here
119119
- [spec/dummy/client/app/startup/DeferredRenderAppServer.jsx](https://github.com/shakacode/react_on_rails/tree/master/spec/dummy/client/app/startup/DeferredRenderAppServer.jsx)
120120
- [spec/dummy/client/app/components/DeferredRender.jsx](https://github.com/shakacode/react_on_rails/tree/master/spec/dummy/client/app/components/DeferredRender.jsx)
121121
- [spec/dummy/client/app/components/DeferredRenderAsyncPage.jsx](https://github.com/shakacode/react_on_rails/tree/master/spec/dummy/client/app/components/DeferredRenderAsyncPage.jsx)

0 commit comments

Comments
 (0)