Skip to content

Commit 45d1bbe

Browse files
authored
Merge branch 'master' into add-option-for-generating-functional-component
2 parents f755896 + 5c93087 commit 45d1bbe

File tree

108 files changed

+1580
-1165
lines changed

Some content is hidden

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

108 files changed

+1580
-1165
lines changed

.github/workflows/rubocop.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: Rubocop
2+
3+
on: [push]
4+
5+
jobs:
6+
rubocop:
7+
name: Rubocop
8+
runs-on: ${{ matrix.os }}
9+
strategy:
10+
matrix:
11+
os: [ubuntu-latest]
12+
ruby: ['2.7', '3.0']
13+
14+
steps:
15+
- uses: actions/checkout@v2
16+
- uses: ruby/setup-ruby@v1
17+
with:
18+
ruby-version: ${{ matrix.ruby }}
19+
bundler-cache: true
20+
- name: Install linting gems
21+
run: gem install rubocop rubocop-performance rubocop-minitest
22+
- name: Run rubocop
23+
run: rubocop

.github/workflows/ruby.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
# For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby
77

88
name: Ruby
9-
on: [push]
9+
10+
on: [push, pull_request]
11+
1012
jobs:
1113
check_react_and_ujs:
1214
strategy:

.rubocop.yml

Lines changed: 86 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,89 @@
1+
inherit_from: .rubocop_todo.yml
2+
3+
require:
4+
- rubocop-performance
5+
- rubocop-minitest
6+
17
AllCops:
2-
TargetRubyVersion: 2.3
8+
NewCops: enable
9+
TargetRubyVersion: 2.5
310
DisplayCopNames: true
11+
12+
Include:
13+
- '**/Rakefile'
14+
- '**/config.ru'
15+
- 'Gemfile'
16+
- '**/*.rb'
17+
- '**/*.rake'
18+
419
Exclude:
5-
- test/dummy_sprockets/**/*
6-
- test/dummy_webpacker1/**/*
7-
- test/dummy_webpacker2/**/*
8-
- test/dummy_webpacker3/**/*
9-
- node_modules/**/*
10-
- react_ujs/**/*
20+
<% `git status --ignored --porcelain`.lines.grep(/^!! /).each do |path| %>
21+
- <%= path.sub(/^!! /, '') %>
22+
<% end %>
23+
- '**/*.js'
24+
- '**/node_modules/**/*'
25+
- '**/public/**/*'
26+
- '**/tmp/**/*'
27+
- 'vendor/**/*'
28+
- 'test/dummy_sprockets/**/*'
29+
- 'test/dummy_webpacker1/**/*'
30+
- 'test/dummy_webpacker2/**/*'
31+
- 'test/dummy_webpacker3/**/*'
32+
- 'react_ujs/**/*'
33+
34+
Naming/FileName:
35+
Exclude:
36+
- '**/Gemfile'
37+
- '**/Rakefile'
38+
- 'lib/react-rails.rb'
39+
40+
Layout/LineLength:
41+
Max: 120
42+
43+
Style/StringLiterals:
44+
EnforcedStyle: double_quotes
45+
46+
Style/Documentation:
47+
Enabled: false
48+
49+
Style/HashEachMethods:
50+
Enabled: true
51+
52+
Style/HashTransformKeys:
53+
Enabled: true
54+
55+
Style/HashTransformValues:
56+
Enabled: true
57+
58+
Metrics/AbcSize:
59+
Max: 28
60+
61+
Metrics/CyclomaticComplexity:
62+
Max: 7
63+
64+
Metrics/PerceivedComplexity:
65+
Max: 10
66+
67+
Metrics/ClassLength:
68+
Max: 150
69+
70+
Metrics/ParameterLists:
71+
Max: 5
72+
CountKeywordArgs: false
73+
74+
Metrics/MethodLength:
75+
Max: 41
76+
77+
Metrics/ModuleLength:
78+
Max: 180
79+
80+
Naming/RescuedExceptionsVariableName:
81+
Enabled: false
82+
83+
# Style/GlobalVars:
84+
# Exclude:
85+
# - 'spec/dummy/config/environments/development.rb'
86+
87+
Metrics/BlockLength:
88+
Exclude:
89+
- 'test/**/*_test.rb'

.rubocop_todo.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# This configuration was generated by
2+
# `rubocop --auto-gen-config`
3+
# on 2023-06-30 00:26:13 UTC using RuboCop version 1.53.1.
4+
# The point is for the user to remove these configuration records
5+
# one by one as the offenses are removed from the code base.
6+
# Note that changes in the inspected code, or installation of new
7+
# versions of RuboCop, may require this file to be generated again.
8+
9+
# Offense count: 2
10+
Lint/IneffectiveAccessModifier:
11+
Exclude:
12+
- 'lib/generators/react/component_generator.rb'
13+
14+
# Offense count: 1
15+
# Configuration parameters: CountComments, CountAsOne.
16+
Metrics/ClassLength:
17+
Exclude:
18+
- 'lib/generators/react/component_generator.rb'

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ _Please add entries here for your pull requests that are not yet released._
1212
### Breaking Changes
1313
- Remove support & testing for Webpacker 3/4.
1414
- Add support & testing for Shakapacker v6
15-
- Requires separate compilations for server & client bundles (see [Webpack config](https://github.com/reactjs/react-rails/blob/judahmeek/workingCI/test/dummy/config/webpack))
15+
- Requires separate compilations for server & client bundles (see [Webpack config](https://github.com/reactjs/react-rails/tree/master/test/dummy/config/webpack))
1616
- Replaces WebpackManifestContainer, which searched for assets in the webpack manifest, with SeparateServerBundleContainer, which expects a single server bundle file & does not use the webpack manifest at all.
1717
- All in one PR! #1274
1818

CONTRIBUTING.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,13 +94,17 @@ To develop the React_UJS NPM Package, make your changes and run `npm pack` to ma
9494

9595
##### Running tests
9696

97+
Run `yalc publish --push` in the root directory of the gem to ensure the test suites use the exact same js code used in the currenlty developing ReactRails.
98+
9799
`bundle exec appraisal install` to install gems on every gemfile Appraisal contains.
98100
`rake test` or `bundle exec appraisal rake test` runs everything.
99101
or run a specific suite using `bundle exec appraisal <appraisal name> rake test`
100102
- Find appraisal names in [Appraisals](Appraisals)
101103
- Integration tests run in Headless Chrome which is included in Chrome (59+ linux,OSX | 60+ Windows)
102104
- ChromeDriver is included with `chromedriver-helper` gem so no need to manually install that 👍
103105

106+
**Note:** If using Ruby 2.7, set `MT_KWARGS_HACK=1` to ensure Minitest runs smoothly.
107+
104108
##### Updating the pre-bundled react
105109
- Update React with `rake react:update`
106110
It outputs an ironically webpacked couple of files into `lib/assets/react-source/<environment>/react(-server).js` where it will be picked up by `sprockets` in `lib/react/rails/asset_variant.rb`

Gemfile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
source 'http://rubygems.org'
1+
# frozen_string_literal: true
2+
3+
source "http://rubygems.org"
24

35
gemspec
46
# This is an optional dev-dependency, required whenever sprockets is required

Gemfile.lock

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,11 +103,9 @@ GEM
103103
matrix (0.4.2)
104104
method_source (1.0.0)
105105
mini_mime (1.0.2)
106-
mini_portile2 (2.8.1)
107106
minitest (5.17.0)
108107
nenv (0.3.0)
109-
nokogiri (1.14.3)
110-
mini_portile2 (~> 2.8.0)
108+
nokogiri (1.14.3-x86_64-darwin)
111109
racc (~> 1.4)
112110
nokogiri (1.14.3-x86_64-linux)
113111
racc (~> 1.4)
@@ -168,7 +166,7 @@ GEM
168166
zeitwerk (2.6.6)
169167

170168
PLATFORMS
171-
ruby
169+
x86_64-darwin-20
172170
x86_64-linux
173171

174172
DEPENDENCIES

README.md

Lines changed: 15 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
1-
# React-Rails
1+
# React-Rails v3
22

33
[![Gem](https://img.shields.io/gem/v/react-rails.svg?style=flat-square)](http://rubygems.org/gems/react-rails)
44
[![npm](https://img.shields.io/npm/v/react_ujs.svg?style=flat-square)](https://www.npmjs.com/package/react_ujs)
55
[![Ruby](https://github.com/reactjs/react-rails/actions/workflows/ruby.yml/badge.svg)](https://github.com/reactjs/react-rails/actions/workflows/ruby.yml)
66

77
## News
8-
v2.7.1 is released. Please try it out and report any issues. We'll try to address any critical issues ASAP. We're going shortly release 3.0, which fully support Shakapacker v6, including SSR.
8+
V3.0.0 is released with Shakapacker v6 support, including SSR. Please try it out and report any issues. We'll try to address any critical issues ASAP.
9+
10+
For version 2.7 documentation checkout [2.7-stable](https://github.com/reactjs/react-rails/tree/2.7-stable) branch.
911

1012
## Summary
1113
React-Rails is a flexible tool to use [React](http://facebook.github.io/react/) with Rails. The benefits:
1214
* Automatically renders React server-side and client-side
13-
* Supports Webpacker 4.x, 3.x, 2.x, 1.1+ or Shakapacker v6+
14-
* Supports Sprockets 4.x, 3.x, 2.x
15+
* Supports [Shakapacker](https://github.com/shakacode/shakapacker) v6.x
16+
* Supports Sprockets 4.x, 3.x
1517
* Lets you use [JSX](http://facebook.github.io/react/docs/jsx-in-depth.html), [ES6](http://es6-features.org/), [TypeScript](https://www.typescriptlang.org/), [CoffeeScript](http://coffeescript.org/)
1618

1719
---
@@ -64,10 +66,10 @@ Read the [full review here](https://clutch.co/profile/shakacode#reviews?sort_by=
6466
- [Camelize Props](#camelize-props)
6567
- [Changing Component Templates](#changing-component-templates)
6668
- [Upgrading](#upgrading)
69+
- [2.7 to 3.0](#27-to-30)
6770
- [2.3 to 2.4](#23-to-24)
6871
- [Common Errors](#common-errors)
6972
- [Getting warning for `Can't resolve 'react-dom/client'` in React < 18](#getting-warning-for-cant-resolve-react-domclient-in-react--18)
70-
- [During installation](#during-installation)
7173
- [Undefined Set](#undefined-set)
7274
- [Using TheRubyRacer](#using-therubyracer)
7375
- [HMR](#hmr)
@@ -491,7 +493,7 @@ ReactRailsUJS.detectEvents()
491493

492494
For example, if `Turbolinks` is loaded _after_ `ReactRailsUJS`, you'll need to call this again. This function removes previous handlers before adding new ones, so it's safe to call as often as needed.
493495

494-
If `Turbolinks` is `import`ed via Webpacker (and thus not available globally), `ReactRailsUJS` will be unable to locate it. To fix this, you can temporarily add it to the global namespace:
496+
If `Turbolinks` is `import`ed via Shakapacker (and thus not available globally), `ReactRailsUJS` will be unable to locate it. To fix this, you can temporarily add it to the global namespace:
495497

496498
```js
497499
// Order is particular. First start Turbolinks:
@@ -545,6 +547,7 @@ Server rendering is powered by [`ExecJS`](https://github.com/rails/execjs) and s
545547

546548
- `react-rails` must load your code. By convention, it uses `server_rendering.js`, which was created
547549
by the install task. This file must include your components _and_ their dependencies (eg, Underscore.js).
550+
- Requires separate compilations for server & client bundles (see [Webpack config](https://github.com/reactjs/react-rails/tree/master/test/dummy/config/webpack))
548551
- Your code can't reference `document` or `window`. Prerender processes don't have access to `document` or `window`,
549552
so jQuery and some other libs won't work in this environment :(
550553

@@ -775,6 +778,11 @@ For example, to change the [ES6 Component template](https://github.com/reactjs/r
775778

776779
## Upgrading
777780

781+
### 2.7 to 3.0
782+
- Keep your `react_ujs` up to date: `yarn upgrade`
783+
- **Drop support for Webpacker:** Before any ReactRails upgrade, make sure upgrading from Webpacker to Shakapacker 6.x.
784+
- **SSR:** ReactRails 3.x requires separate compilations for server & client bundles. See [Webpack config](https://github.com/reactjs/react-rails/tree/master/test/dummy/config/webpack) directory in the dummy app to addapt the new implementation.
785+
778786
### 2.3 to 2.4
779787

780788
Keep your `react_ujs` up to date, `yarn upgrade`
@@ -810,30 +818,6 @@ You may see a warning like this when building a Webpack bundle using any version
810818
+ module.exports = merge({}, webpackConfig, ignoreWarningsConfig)
811819
```
812820

813-
### During installation
814-
1) While using installers.(rails webpacker:install:react && rails webpacker:install)
815-
Error:
816-
```
817-
public/packs/manifest.json. Possible causes:
818-
1. You want to set webpacker.yml value of compile to true for your environment
819-
unless you are using the `webpack -w` or the webpack-dev-server.
820-
2. webpack has not yet re-run to reflect updates.
821-
3. You have misconfigured Webpacker's config/webpacker.yml file.
822-
4. Your webpack configuration is not creating a manifest.
823-
or
824-
yarn: error: no such option: --dev
825-
ERROR: [Errno 2] No such file or directory: 'add'
826-
```
827-
Fix: Try updating yarn package.
828-
```
829-
sudo apt remove cmdtest
830-
sudo apt remove yarn
831-
curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
832-
echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
833-
sudo apt-get update && sudo apt-get install yarn
834-
835-
yarn install
836-
```
837821
### Undefined Set
838822
```
839823
ExecJS::ProgramError (identifier 'Set' undefined):
@@ -849,9 +833,8 @@ TheRubyRacer [hasn't updated LibV8](https://github.com/cowboyd/therubyracer/blob
849833
LibV8 itself is already [beyond version 7](https://github.com/cowboyd/libv8/releases/tag/v7.3.492.27.1) therefore many serverside issues are caused by old JS engines and fixed by using an up to date one such as [MiniRacer](https://github.com/discourse/mini_racer) or [TheRubyRhino](https://github.com/cowboyd/therubyrhino) on JRuby.
850834

851835
### HMR
852-
Hot Module Replacement is [possible with this gem](https://stackoverflow.com/a/54846330/193785) as it does just pass through to Webpacker. Please open an issue to let us know tips and tricks for it to add to the wiki.
853836

854-
Sample repo that shows HMR working with `react-rails`: [https://github.com/edelgado/react-rails-hmr](https://github.com/edelgado/react-rails-hmr)
837+
Check out [Enabling Hot Module Replacement (HMR)](https://github.com/shakacode/shakapacker/blob/master/docs/react.md#enabling-hot-module-replacement-hmr) in Shakapacker documentation.
855838

856839
One caveat is that currently you [cannot Server-Side Render along with HMR](https://github.com/reactjs/react-rails/issues/925#issuecomment-415469572).
857840

0 commit comments

Comments
 (0)