quilt_rails 1.13.0 → 3.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +48 -19
- data/lib/generators/quilt/react_app/react_app_generator.rb +12 -0
- data/lib/generators/quilt/react_setup/react_setup_generator.rb +5 -4
- data/lib/quilt_rails/react_renderable.rb +2 -3
- data/lib/quilt_rails/version.rb +1 -1
- metadata +4 -11
- data/lib/generators/quilt/react_setup/templates/App.tsx +0 -7
- data/lib/generators/quilt_rails/USAGE +0 -5
- data/lib/generators/quilt_rails/install_generator.rb +0 -10
- data/lib/generators/sewing_kit/USAGE +0 -5
- data/lib/generators/sewing_kit/install_generator.rb +0 -34
- data/lib/generators/sewing_kit/templates/package.json +0 -31
- data/lib/generators/sewing_kit/templates/sewing-kit.config.ts +0 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e887915bb7068b86352c99c8f53b38a69bcc313c8859a058ceac543ef1ea1d79
|
4
|
+
data.tar.gz: 8aa15f78b167b1513094d40b4714b7539164880cb7514884ce3ab40c03288325
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1138e0a191bd3412a5bfb735efdb2a45e24549660a5085922e8495427ebe5246baf5b5d2e216446975efd5cee9f77c25c4d79b35edbde462383495f70e709ea5
|
7
|
+
data.tar.gz: 9d52ae742f44161da2486543e335d83a46c8ae70a21778e9a809d4b62ce029687c2571379ae9cc2f4adc87758135e5bdb448cddcf41b14ca2446b1bc7b25f059
|
data/README.md
CHANGED
@@ -23,7 +23,7 @@ A turn-key solution for integrating Quilt client-side libraries into your Rails
|
|
23
23
|
|
24
24
|
## Server-side-rendering
|
25
25
|
|
26
|
-
🗒 This guide is focused on internal Shopify developers with access
|
26
|
+
🗒 This guide is focused on internal Shopify developers with access [@shopify/sewing-kit](https://github.com/Shopify/sewing-kit). A similar setup can be achieved using the [manual installation](./docs/manual-installation.md) , and following the [react-server webpack plugin](../../packages/react-server/README.md#webpack-plugin) guide. Apps not running on Shopify infrastructure should [disable server-side GraphQL queries](./docs/FAQ.md) to avoid scalability issue.
|
27
27
|
|
28
28
|
### Quick start
|
29
29
|
|
@@ -31,12 +31,7 @@ Using the magic of generators, we can spin up a basic app with a few console com
|
|
31
31
|
|
32
32
|
#### Generate Rails boilerplate
|
33
33
|
|
34
|
-
|
35
|
-
When prompted, choose `rails`. This will generate a basic Rails application scaffold.
|
36
|
-
|
37
|
-
Alternatively, you can use [`rails new .`](https://guides.rubyonrails.org/command_line.html#rails-new) to do the same.
|
38
|
-
|
39
|
-
In either case, remove [`webpacker`](./docs/FAQ.md#i-run-into-webpacker-issue-while-setting-up-quilt_rails) before continuing.
|
34
|
+
Use [`rails new . --skip-javascript`](https://guides.rubyonrails.org/command_line.html#rails-new) to scaffold out a Rails application.to do the same.
|
40
35
|
|
41
36
|
#### Add Ruby dependencies
|
42
37
|
|
@@ -46,22 +41,25 @@ This will install our ruby dependencies and update the project's gemfile.
|
|
46
41
|
|
47
42
|
#### Generate app boilerplate
|
48
43
|
|
49
|
-
`rails generate
|
44
|
+
`rails generate sewing_kit:install`
|
45
|
+
|
46
|
+
This will generate a package.json file with common sewing-kit script tasks, default lint, format configuration; a sewing-kit configuration file, and other project default configurations.
|
50
47
|
|
51
|
-
|
48
|
+
`rails generate quilt:install`
|
49
|
+
|
50
|
+
This command will install Node dependencies, mount the Quilt engine in `config/routes.rb`, and provide a bare bone React app (in TypeScript) that.
|
52
51
|
|
53
52
|
#### Try it out
|
54
53
|
|
55
54
|
```sh
|
56
|
-
|
57
|
-
dev server
|
55
|
+
bin/rails server
|
58
56
|
```
|
59
57
|
|
60
58
|
Will run the application, starting up both servers and compiling assets.
|
61
59
|
|
62
60
|
### Manual installation
|
63
61
|
|
64
|
-
Follow [this guide](./docs/manual-installation) on how to do manual setup without the generator.
|
62
|
+
Follow [this guide](./docs/manual-installation.md) on how to do manual setup without the generator.
|
65
63
|
|
66
64
|
### Advanced use
|
67
65
|
|
@@ -133,6 +131,8 @@ function App() {
|
|
133
131
|
export default App;
|
134
132
|
```
|
135
133
|
|
134
|
+
**Note:** This solution works out of the box for initial server-side renders. If you wish to have consistent access to request headers on subsequent client-side renders, take a look at [`NetworkUniversalProvider`](https://github.com/Shopify/quilt/tree/master/packages/react-network#networkuniversalprovider).
|
135
|
+
|
136
136
|
##### Example: sending custom headers from Rails controller
|
137
137
|
|
138
138
|
In some cases you may want to send custom headers from Rails to your React server. Quilt facilitates this case by providing consumers with a `headers` argument on the `render_react` call.
|
@@ -147,6 +147,8 @@ class ReactController < ApplicationController
|
|
147
147
|
end
|
148
148
|
```
|
149
149
|
|
150
|
+
🗒️ if you don't have a controller. Follow the [instruction](./docs/manual-installation#add-a-react-controller-and-routes) to setup `quilt_rails` in a controller instead of using the engine.
|
151
|
+
|
150
152
|
Headers can be accessed during server-side-rendering with the `useRequestHeader` hook from `@shopify/react-network`.
|
151
153
|
|
152
154
|
```tsx
|
@@ -169,6 +171,8 @@ In some cases you may want to send basic data from Rails to your React server. Q
|
|
169
171
|
|
170
172
|
**Note:** The data passed should be data that is unlikely or will never change over the course of the session before they render any React components.
|
171
173
|
|
174
|
+
**Note:** Please note the minimal dependencies require to use this feature is listed in [CHANGELOG](./CHANGELOG.md#[1.12.0]-2020-05-07)
|
175
|
+
|
172
176
|
```ruby
|
173
177
|
class ReactController < ApplicationController
|
174
178
|
include Quilt::ReactRenderable
|
@@ -179,7 +183,9 @@ class ReactController < ApplicationController
|
|
179
183
|
end
|
180
184
|
```
|
181
185
|
|
182
|
-
|
186
|
+
🗒️ if you don't have a controller. Follow the [instruction](./docs/manual-installation#add-a-react-controller-and-routes) to setup `quilt_rails` in a controller instead of using the engine.
|
187
|
+
|
188
|
+
If using `react-server` without a customized server & client file, this will be automatically passed into your application as the `data` prop. If `react-server` is not being used or a customized server / client file was provided, check out [`react-server/webpack-plugin`](../../packages/react-server/src/webpack-plugin/webpack-plugin.ts) on how to pass the data to React.
|
183
189
|
|
184
190
|
```tsx
|
185
191
|
// app/ui/index.tsx
|
@@ -218,11 +224,11 @@ export default App;
|
|
218
224
|
|
219
225
|
With SSR enabled React apps, state must be serialized on the server and deserialized on the client to keep it consistent. When using `@shopify/react-server`, the best tool for this job is [`@shopify/react-html`](https://github.com/Shopify/quilt/tree/master/packages/react-html)'s [`useSerialized`](https://github.com/Shopify/quilt/tree/master/packages/react-html#in-your-application-code) hook.
|
220
226
|
|
221
|
-
`useSerialized` can be used to implement [universal-providers](https://github.com/Shopify/quilt/tree/master/packages/react-universal-provider#what-is-a-universal-provider-), allowing application code to manage what is persisted between the server and client without adding any custom code to client or server entrypoints. We offer some for common use cases such as [
|
227
|
+
`useSerialized` can be used to implement [universal-providers](https://github.com/Shopify/quilt/tree/master/packages/react-universal-provider#what-is-a-universal-provider-), allowing application code to manage what is persisted between the server and client without adding any custom code to client or server entrypoints. We offer some for common use cases such as [GraphQL](https://github.com/Shopify/quilt/tree/master/packages/react-graphql-universal-provider), and [I18n](https://github.com/Shopify/quilt/tree/master/packages/react-i18n-universal-provider).
|
222
228
|
|
223
229
|
#### Customizing the Node server
|
224
230
|
|
225
|
-
By default, sewing-kit bundles in [`@shopify/react-server
|
231
|
+
By default, sewing-kit bundles in [`@shopify/react-server/webpack-plugin`](../../packages/react-server/README.md#webpack-plugin) for `quilt_rails` applications to get apps up and running fast without needing to manually write any Node server code.
|
226
232
|
|
227
233
|
If what it provides is not sufficient, a completely custom server can be defined by adding a `server.js` or `server.ts` file to the `app/ui` folder. The simplest way to customize the server is to export the object created by [`@shopify/react-server`](../../packages/react-server/README.md#node-usage)'s `createServer` call in `server.ts` file.
|
228
234
|
|
@@ -240,6 +246,10 @@ When a React component sends HTTP requests back to a Rails endpoint (e.g., `/gra
|
|
240
246
|
|
241
247
|
If your API **does not** require session data, the easiest way to deal with this is to use `protect_from_forgery with: :null_session`. This will work for APIs that either have no authentication requirements, or use header based authentication.
|
242
248
|
|
249
|
+
While `Can't verify CSRF token authenticity` error will persist, `protect_from_forgery with: :null_session` will keep CSRF protection while ensuring the session is nullified when a token is not sent in to be more secure.
|
250
|
+
|
251
|
+
You can also add `self.log_warning_on_csrf_failure = false` to the controller to suppress this error all together.
|
252
|
+
|
243
253
|
##### Example
|
244
254
|
|
245
255
|
```rb
|
@@ -259,7 +269,7 @@ end
|
|
259
269
|
If your API **does** require session data, you can follow these steps:
|
260
270
|
|
261
271
|
- Add an `x-shopify-react-xhr` header to all GraphQL requests with a value of 1 (this is done automatically if you are using `@shopify/react-graphql-universal-provider`)
|
262
|
-
- Add a `protect_from_forgery with: Quilt::HeaderCsrfStrategy` override to your controllers
|
272
|
+
- Add a `protect_from_forgery with: Quilt::HeaderCsrfStrategy` override to your API controllers
|
263
273
|
|
264
274
|
##### Example
|
265
275
|
|
@@ -277,15 +287,34 @@ class GraphqlController < ApplicationController
|
|
277
287
|
end
|
278
288
|
```
|
279
289
|
|
290
|
+
#### Exception monitoring with Bugsnag
|
291
|
+
|
292
|
+
For an opinionated universal Bugsnag+React setup we provide and support [`@shopify/react-bugsnag`](https://github.com/Shopify/quilt/tree/master/packages/react-bugsnag).
|
293
|
+
|
294
|
+
##### Example
|
295
|
+
|
296
|
+
```typescript
|
297
|
+
// app/ui/index.tsx
|
298
|
+
import React from 'react';
|
299
|
+
import {Bugsnag, createBugsnagClient} from 'utilities/bugsnag';
|
300
|
+
import {bugsnagClientApiKey} from 'config/bugsnag';
|
301
|
+
|
302
|
+
const bugsnagClient = createBugsnagClient({apiKey: bugsnagClientApiKey});
|
303
|
+
|
304
|
+
export function App() {
|
305
|
+
return <Bugsnag client={bugsnagClient}>{/* actual app content here */}</Bugsnag>;
|
306
|
+
}
|
307
|
+
```
|
308
|
+
|
280
309
|
## Performance tracking a React app
|
281
310
|
|
282
311
|
To setup performance tracking with your React app with `quilt_rails`.
|
283
|
-
Follow details guide [here](./docs/performance-tracking).
|
312
|
+
Follow details guide [here](./docs/performance-tracking.md).
|
284
313
|
|
285
314
|
## API
|
286
315
|
|
287
|
-
Find all features this gem offer in this [API doc](./docs/api).
|
316
|
+
Find all features this gem offer in this [API doc](./docs/api.md).
|
288
317
|
|
289
318
|
## FAQ
|
290
319
|
|
291
|
-
Find your [here](./docs/FAQ).
|
320
|
+
Find your [here](./docs/FAQ.md).
|
@@ -6,6 +6,18 @@ module Quilt
|
|
6
6
|
|
7
7
|
desc "This generator adds a React app."
|
8
8
|
|
9
|
+
def set_app_config_javascript_path
|
10
|
+
config_path = "config/application.rb"
|
11
|
+
|
12
|
+
unless File.exist?(config_path)
|
13
|
+
inject_into_file(
|
14
|
+
config_path,
|
15
|
+
"\n config.javascript_path = \"ui\"\n",
|
16
|
+
before: /^ end$/,
|
17
|
+
)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
9
21
|
def create_app_file
|
10
22
|
copy_file("App.tsx", "app/ui/index.tsx")
|
11
23
|
end
|
@@ -3,19 +3,20 @@
|
|
3
3
|
module Quilt
|
4
4
|
class ReactSetupGenerator < Rails::Generators::Base
|
5
5
|
source_root File.expand_path('templates', __dir__)
|
6
|
+
class_option :skip_yarn, type: :boolean, default: false
|
6
7
|
|
7
8
|
desc "This generator adds a React app."
|
8
9
|
|
9
10
|
def install_js_dependencies
|
10
|
-
|
11
|
+
return if options.skip_yarn?
|
12
|
+
|
13
|
+
say "Installing react and types dependencies"
|
11
14
|
system("yarn add "\
|
12
|
-
"@shopify/sewing-kit "\
|
13
|
-
"@shopify/react-server "\
|
14
15
|
"typescript@~3.8.0 "\
|
15
16
|
"react@~16.11.0 "\
|
16
17
|
"react-dom@~16.11.0 "\
|
17
18
|
"@types/react@~16.9.0 "\
|
18
|
-
"@types/react-dom@~16.9.0 ")
|
19
|
+
"@types/react-dom@~16.9.0 ")
|
19
20
|
end
|
20
21
|
|
21
22
|
def create_tsconfig
|
@@ -37,10 +37,9 @@ module Quilt
|
|
37
37
|
end
|
38
38
|
|
39
39
|
begin
|
40
|
-
|
41
40
|
reverse_proxy(
|
42
41
|
url,
|
43
|
-
headers: headers.merge('X-
|
42
|
+
headers: headers.merge('X-Quilt-Data': data.to_json)
|
44
43
|
) do |callbacks|
|
45
44
|
callbacks.on_response do |status_code, _response|
|
46
45
|
Quilt::Logger.log("[ReactRenderable] #{url} returned #{status_code}")
|
@@ -54,7 +53,7 @@ module Quilt
|
|
54
53
|
class ReactServerNoResponseError < StandardError
|
55
54
|
def initialize(url)
|
56
55
|
# rubocop:disable LineLength
|
57
|
-
super "Errno::ECONNREFUSED: Waiting for React server to boot up. If this error
|
56
|
+
super "Errno::ECONNREFUSED: Waiting for React server to boot up. If this error persists verify that @shopify/react-server is configured on #{url}"
|
58
57
|
# rubocop:enable LineLength
|
59
58
|
end
|
60
59
|
end
|
data/lib/quilt_rails/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: quilt_rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 3.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mathew Allen
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-07-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: railties
|
@@ -80,7 +80,7 @@ dependencies:
|
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: 0.1.3
|
83
|
-
description: A turn-key solution for integrating server-rendered
|
83
|
+
description: A turn-key solution for integrating server-rendered React into your Rails
|
84
84
|
app using Quilt libraries.
|
85
85
|
email:
|
86
86
|
- mathew.allen@shopify.com
|
@@ -104,14 +104,7 @@ files:
|
|
104
104
|
- lib/generators/quilt/react_app/templates/App.tsx
|
105
105
|
- lib/generators/quilt/react_setup/USAGE
|
106
106
|
- lib/generators/quilt/react_setup/react_setup_generator.rb
|
107
|
-
- lib/generators/quilt/react_setup/templates/App.tsx
|
108
107
|
- lib/generators/quilt/react_setup/templates/tsconfig.json
|
109
|
-
- lib/generators/quilt_rails/USAGE
|
110
|
-
- lib/generators/quilt_rails/install_generator.rb
|
111
|
-
- lib/generators/sewing_kit/USAGE
|
112
|
-
- lib/generators/sewing_kit/install_generator.rb
|
113
|
-
- lib/generators/sewing_kit/templates/package.json
|
114
|
-
- lib/generators/sewing_kit/templates/sewing-kit.config.ts
|
115
108
|
- lib/quilt_rails.rb
|
116
109
|
- lib/quilt_rails/configuration.rb
|
117
110
|
- lib/quilt_rails/engine.rb
|
@@ -153,6 +146,6 @@ requirements: []
|
|
153
146
|
rubygems_version: 3.0.3
|
154
147
|
signing_key:
|
155
148
|
specification_version: 4
|
156
|
-
summary: A turn-key solution for integrating server-rendered
|
149
|
+
summary: A turn-key solution for integrating server-rendered React into your Rails
|
157
150
|
app using Quilt libraries.
|
158
151
|
test_files: []
|
@@ -1,34 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module SewingKit
|
4
|
-
class InstallGenerator < Rails::Generators::Base
|
5
|
-
source_root File.expand_path('templates', __dir__)
|
6
|
-
|
7
|
-
desc "This generator creates a sewing-kit config file."
|
8
|
-
|
9
|
-
def initialize(args, *options)
|
10
|
-
@application_name = Rails.application.class.module_parent.to_s.underscore
|
11
|
-
super(args, *options)
|
12
|
-
end
|
13
|
-
|
14
|
-
def create_package_json
|
15
|
-
package_json_path = "package.json"
|
16
|
-
|
17
|
-
copy_file(package_json_path)
|
18
|
-
gsub_file(package_json_path, "\${application_name}", @application_name)
|
19
|
-
end
|
20
|
-
|
21
|
-
def create_sk_config
|
22
|
-
sk_config_path = "config/sewing-kit.config.ts"
|
23
|
-
|
24
|
-
copy_file("sewing-kit.config.ts", sk_config_path)
|
25
|
-
gsub_file(sk_config_path, "\${application_name}", @application_name)
|
26
|
-
end
|
27
|
-
|
28
|
-
def create_config_files
|
29
|
-
copy_file(".editorconfig")
|
30
|
-
copy_file(".eslintignore")
|
31
|
-
copy_file(".prettierignore")
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
@@ -1,31 +0,0 @@
|
|
1
|
-
{
|
2
|
-
"name": "${application_name}",
|
3
|
-
"private": true,
|
4
|
-
"sideEffects": false,
|
5
|
-
"scripts": {
|
6
|
-
"dev": "sewing-kit dev",
|
7
|
-
"check": "sewing-kit check",
|
8
|
-
"lint": "sewing-kit lint",
|
9
|
-
"type-check": "sewing-kit type-check",
|
10
|
-
"nuke": "sewing-kit nuke",
|
11
|
-
"test": "sewing-kit test"
|
12
|
-
},
|
13
|
-
"eslintConfig": {
|
14
|
-
"extends": [
|
15
|
-
"plugin:@shopify/typescript",
|
16
|
-
"plugin:@shopify/react",
|
17
|
-
"plugin:@shopify/prettier",
|
18
|
-
"plugin:@shopify/jest",
|
19
|
-
"plugin:@shopify/polaris"
|
20
|
-
]
|
21
|
-
},
|
22
|
-
"prettier": "@shopify/prettier-config",
|
23
|
-
"stylelint": {
|
24
|
-
"extends": [
|
25
|
-
"@shopify/stylelint-plugin/prettier"
|
26
|
-
]
|
27
|
-
},
|
28
|
-
"resolutions": {
|
29
|
-
"babel-plugin-dynamic-import-node": "2.3.0"
|
30
|
-
}
|
31
|
-
}
|