quilt_rails 3.4.0 → 3.5.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: aa35ecd25ebbe9bd095f8e161debda741a45237533aef5d36751f9a1858dd5c7
4
- data.tar.gz: 8de82016b228fe4f9ef5f21bd09380637db99d5b160345ce3910e7ca7fdf1e11
3
+ metadata.gz: aa72dc117e88bc8726ec6dcc658d86fe6882b62d91a964bac6267b351de1c595
4
+ data.tar.gz: d11b303d107674073e8a0bc597b59861ef627251c64554c515ef978f497cbe5e
5
5
  SHA512:
6
- metadata.gz: 4e205902095208ed7d79c0e963389220b1c1d1050e46201935428b6949ca6f37f600e412b9cf1eeadf9435e7fd8fade00191edc922cbcb64819bb79acdc9af2f
7
- data.tar.gz: f22a95a82bd538ff24ebaf4e15a1ada939b77e1be3e258c1f5a2ead5f342116517006934d625507f6770da5bce75e52675af5e48cea4c19ee948032c21a7342d
6
+ metadata.gz: b38651e9772a2a6882a9ab3064897e3f9c78ad75a05f9f2f6cedcb77602c59ba12581187c800694758dc841bdc87fde6a261d3c8516478639e58b9fe60f8263d
7
+ data.tar.gz: ef8e6e54e66d7e9132d738fb51efc5ccc06c4d7e243201ddd177fda4992e6260d1bb9b5790a7eeaa785c8f31f2e3f39f2cdec5119508ceae8fabd2e188a3cb85
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # quilt_rails
2
2
 
3
- A turn-key solution for integrating Quilt client-side libraries into your Rails app, with support for server-side-rendering using [`@shopify/react-server`](https://www.npmjs.com/package/@shopify/react-server), integration with [`@shopify/sewing-kit`](https://github.com/Shopify/sewing-kit) for building, testing and linting, and front-end performance tracking through [`@shopify/performance`](https://www.npmjs.com/package/@shopify/performance).
3
+ A turn-key solution for integrating [Quilt](https://github.com/Shopify/quilt) client-side libraries into your Rails app, with support for server-side-rendering using [`@shopify/react-server`](https://www.npmjs.com/package/@shopify/react-server), integration with [`@shopify/sewing-kit`](https://github.com/Shopify/sewing-kit) for building, testing and linting, and front-end performance tracking through [`@shopify/performance`](https://www.npmjs.com/package/@shopify/performance).
4
4
 
5
5
  ## Table of Contents
6
6
 
@@ -67,9 +67,9 @@ Follow [this guide](./docs/manual-installation.md) on how to do manual setup wit
67
67
 
68
68
  For fast tests with consistent results, test front-end components using the tools provided by sewing-kit instead of Rails integration tests.
69
69
 
70
- Use [`sewing-kit test`](https://github.com/Shopify/sewing-kit/blob/master/docs/commands/test.md#L3) to run all `.test.{js|ts}x` files in the `app/ui` directory. [Jest](https://jestjs.io/) is used as a test runner, with customization available via [its sewing-kit plugin](https://github.com/Shopify/sewing-kit/blob/master/docs/plugins/jest.md).
70
+ Use [`sewing-kit test`](https://github.com/Shopify/sewing-kit/blob/main/docs/commands/test.md#L3) to run all `.test.{js|ts}x` files in the `app/ui` directory. [Jest](https://jestjs.io/) is used as a test runner, with customization available via [its sewing-kit plugin](https://github.com/Shopify/sewing-kit/blob/main/docs/plugins/jest.md).
71
71
 
72
- For testing React applications we provide and support [`@shopify/react-testing`](https://github.com/Shopify/quilt/tree/master/packages/react-testing).
72
+ For testing React applications we provide and support [`@shopify/react-testing`](https://github.com/Shopify/quilt/tree/main/packages/react-testing).
73
73
 
74
74
  ##### Example
75
75
 
@@ -102,11 +102,11 @@ describe('MyComponent', () => {
102
102
 
103
103
  Often you will want to hook up custom polyfills, global mocks, or other logic that needs to run either before the initialization of the test environment, or once for each test suite.
104
104
 
105
- By default, sewing-kit will look for such test setup files under `/app/ui/tests`. Check out the [documentation](https://github.com/Shopify/sewing-kit/blob/master/docs/plugins/jest.md#smart-defaults) for more details.
105
+ By default, sewing-kit will look for such test setup files under `/app/ui/tests`. Check out the [documentation](https://github.com/Shopify/sewing-kit/blob/main/docs/plugins/jest.md#smart-defaults) for more details.
106
106
 
107
107
  ##### Interacting with the request and response in React code
108
108
 
109
- React-server sets up [@shopify/react-network](https://github.com/Shopify/quilt/blob/master/packages/react-network) automatically, so most interactions with the request or response can be done from inside the React app.
109
+ React-server sets up [@shopify/react-network](https://github.com/Shopify/quilt/blob/main/packages/react-network) automatically, so most interactions with the request or response can be done from inside the React app.
110
110
 
111
111
  ##### Example: getting headers
112
112
 
@@ -131,7 +131,7 @@ function App() {
131
131
  export default App;
132
132
  ```
133
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).
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/main/packages/react-network#networkuniversalprovider).
135
135
 
136
136
  ##### Example: sending custom headers from Rails controller
137
137
 
@@ -147,7 +147,7 @@ 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.
150
+ 🗒️ if you don't have a controller. Follow the [instruction](./docs/manual-installation.md#option-2-add-a-react-controller-and-routes) to setup `quilt_rails` in a controller instead of using the engine.
151
151
 
152
152
  Headers can be accessed during server-side-rendering with the `useRequestHeader` hook from `@shopify/react-network`.
153
153
 
@@ -171,7 +171,7 @@ In some cases you may want to send basic data from Rails to your React server. Q
171
171
 
172
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.
173
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)
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
175
 
176
176
  ```ruby
177
177
  class ReactController < ApplicationController
@@ -183,7 +183,7 @@ class ReactController < ApplicationController
183
183
  end
184
184
  ```
185
185
 
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.
186
+ 🗒️ if you don't have a controller. Follow the [instruction](./docs/manual-installation.md#option-2-add-a-react-controller-and-routes) to setup `quilt_rails` in a controller instead of using the engine.
187
187
 
188
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.
189
189
 
@@ -222,9 +222,9 @@ export default App;
222
222
 
223
223
  #### Isomorphic state
224
224
 
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.
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/main/packages/react-html)'s [`useSerialized`](https://github.com/Shopify/quilt/tree/main/packages/react-html#in-your-application-code) hook.
226
226
 
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).
227
+ `useSerialized` can be used to implement [universal-providers](https://github.com/Shopify/quilt/tree/main/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/main/packages/react-graphql-universal-provider), and [I18n](https://github.com/Shopify/quilt/tree/main/packages/react-i18n-universal-provider).
228
228
 
229
229
  #### Customizing the Node server
230
230
 
@@ -289,7 +289,7 @@ end
289
289
 
290
290
  #### Exception monitoring with Bugsnag
291
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).
292
+ For an opinionated universal Bugsnag+React setup we provide and support [`@shopify/react-bugsnag`](https://github.com/Shopify/quilt/tree/main/packages/react-bugsnag).
293
293
 
294
294
  ##### Example
295
295
 
@@ -5,12 +5,17 @@ module Quilt
5
5
  include Quilt::ReactRenderable
6
6
  layout(false)
7
7
 
8
- rescue_from(Quilt::ReactRenderable::ReactServerNoResponseError) do
9
- render(:react_render_error, status: :internal_server_error)
10
- end
11
-
12
8
  def index
13
9
  render_react
10
+ rescue Quilt::ReactRenderable::ReactServerNoResponseError
11
+ sleep(1)
12
+ retry if execution_count < 10
13
+ raise
14
+ end
15
+
16
+ def execution_count
17
+ @times ||= 0
18
+ @times = @times.next
14
19
  end
15
20
  end
16
21
  end
@@ -11,7 +11,9 @@ module Quilt
11
11
 
12
12
  self.react_server_host = "#{react_server_ip}:#{react_server_port}"
13
13
  self.react_server_protocol = ENV['REACT_SERVER_PROTOCOL'] || "http"
14
+ self.logger = ::Logger.new($stdout)
14
15
  self.mount = true
16
+ self.allow_integration_test = false
15
17
  end
16
18
 
17
19
  def mount?
@@ -19,11 +21,13 @@ module Quilt
19
21
  end
20
22
  end
21
23
 
22
- def self.configuration
23
- @configuration ||= Configuration.new
24
- end
24
+ class << self
25
+ def configuration
26
+ @configuration ||= Configuration.new
27
+ end
25
28
 
26
- def self.configure
27
- yield(configuration)
29
+ def configure
30
+ yield(configuration)
31
+ end
28
32
  end
29
33
  end
@@ -6,6 +6,10 @@ module Quilt
6
6
 
7
7
  config.quilt = Quilt.configuration
8
8
 
9
+ initializer(:initialize_quilt_logger, after: :initialize_logger) do
10
+ config.quilt.logger = ::Rails.logger
11
+ end
12
+
9
13
  initializer(:mount_quilt, before: :add_builtin_route) do |app|
10
14
  if config.quilt.mount?
11
15
  app.routes.append do
@@ -3,11 +3,14 @@
3
3
  module Quilt
4
4
  module Logger
5
5
  def self.log(string)
6
- if Rails.logger.nil?
7
- puts string
8
- else
9
- Rails.logger.info(string)
10
- end
6
+ ActiveSupport::Deprecation.warn(<<~MSG.squish)
7
+ Quilt::Logger.log is deprecated. Please use Quilt.logger instead.
8
+ MSG
9
+ Quilt.configuration.logger.info(string)
11
10
  end
12
11
  end
12
+
13
+ class << self
14
+ delegate(:logger, to: :configuration)
15
+ end
13
16
  end
@@ -7,7 +7,9 @@ module Quilt
7
7
  include ReverseProxy::Controller
8
8
 
9
9
  def render_react(headers: {}, data: {})
10
- raise DoNotIntegrationTestError if Rails.env.test?
10
+ if Rails.env.test? && !Quilt.configuration.allow_integration_test
11
+ raise DoNotIntegrationTestError
12
+ end
11
13
 
12
14
  # Allow concurrent loading to prevent this thread from blocking class
13
15
  # loading in controllers called by the Node server.
@@ -20,7 +22,8 @@ module Quilt
20
22
 
21
23
  def call_proxy(headers, data)
22
24
  if defined? ShopifySecurityBase
23
- ShopifySecurityBase::HTTPHostRestriction.whitelist([Quilt.configuration.react_server_host]) do
25
+ allowlist = ShopifySecurityBase::HTTPHostRestriction.respond_to?(:allowlist) ? :allowlist : :whitelist
26
+ ShopifySecurityBase::HTTPHostRestriction.send(allowlist, [Quilt.configuration.react_server_host]) do
24
27
  proxy(headers, data)
25
28
  end
26
29
  else
@@ -30,10 +33,10 @@ module Quilt
30
33
 
31
34
  def proxy(headers, data)
32
35
  url = "#{Quilt.configuration.react_server_protocol}://#{Quilt.configuration.react_server_host}"
33
- Quilt::Logger.log("[ReactRenderable] proxying to React server at #{url}")
36
+ Quilt.logger.info("[ReactRenderable] proxying to React server at #{url}")
34
37
 
35
38
  unless headers.blank?
36
- Quilt::Logger.log("[ReactRenderable] applying custom headers #{headers.inspect}")
39
+ Quilt.logger.info("[ReactRenderable] applying custom headers #{headers.inspect}")
37
40
  end
38
41
 
39
42
  begin
@@ -42,7 +45,7 @@ module Quilt
42
45
  headers: headers.merge('X-Request-ID': request.request_id, 'X-Quilt-Data': data.to_json)
43
46
  ) do |callbacks|
44
47
  callbacks.on_response do |status_code, _response|
45
- Quilt::Logger.log("[ReactRenderable] #{url} returned #{status_code}")
48
+ Quilt.logger.info("[ReactRenderable] #{url} returned #{status_code}")
46
49
  end
47
50
  end
48
51
  rescue Errno::ECONNREFUSED
@@ -53,8 +56,8 @@ module Quilt
53
56
  class ReactServerNoResponseError < StandardError
54
57
  def initialize(url)
55
58
  super(<<~MSG.squish)
56
- Errno::ECONNREFUSED: Waiting for React server to boot up.
57
- If this error persists verify that @shopify/react-server is configured on #{url}"
59
+ Connection refused while waiting for React server to boot up.
60
+ If this error persists, verify that @shopify/react-server is configured on #{url}.
58
61
  MSG
59
62
  end
60
63
  end
@@ -62,8 +65,10 @@ module Quilt
62
65
  class DoNotIntegrationTestError < StandardError
63
66
  def initialize
64
67
  super(<<~MSG.squish)
65
- Do not try to use Rails integration tests on your quilt_rails app.
66
- Instead use Jest and @shopify/react-testing to test your React application directly."
68
+ Please don't test React views with Ruby.
69
+ Jest and @shopify/react-testing should be used to test React components.
70
+
71
+ If you meant to query your Rails application, please check your integration test for errors.
67
72
  MSG
68
73
  end
69
74
  end
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module Quilt
3
- VERSION = "3.4.0"
3
+ VERSION = "3.5.1"
4
4
  end
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: 3.4.0
4
+ version: 3.5.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-08-26 00:00:00.000000000 Z
11
+ date: 2021-08-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: railties
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: 3.2.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: activesupport
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 3.2.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 3.2.0
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: rails-reverse-proxy
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -92,7 +106,6 @@ files:
92
106
  - Rakefile
93
107
  - app/controllers/quilt/performance_report_controller.rb
94
108
  - app/controllers/quilt/ui_controller.rb
95
- - app/views/quilt/ui/react_render_error.html
96
109
  - config/routes.rb
97
110
  - lib/generators/quilt/USAGE
98
111
  - lib/generators/quilt/install_generator.rb
@@ -124,7 +137,7 @@ files:
124
137
  - lib/quilt_rails/react_renderable.rb
125
138
  - lib/quilt_rails/trusted_ui_server_csrf_strategy.rb
126
139
  - lib/quilt_rails/version.rb
127
- homepage: https://github.com/Shopify/quilt/tree/master/gems/quilt_rails
140
+ homepage: https://github.com/Shopify/quilt/tree/main/gems/quilt_rails
128
141
  licenses:
129
142
  - MIT
130
143
  metadata:
@@ -144,7 +157,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
144
157
  - !ruby/object:Gem::Version
145
158
  version: '0'
146
159
  requirements: []
147
- rubygems_version: 3.0.3
160
+ rubygems_version: 3.2.20
148
161
  signing_key:
149
162
  specification_version: 4
150
163
  summary: A turn-key solution for integrating server-rendered React into your Rails
@@ -1,21 +0,0 @@
1
- <!DOCTYPE html>
2
- <html>
3
- <head>
4
- <title>React Render Error</title>
5
- <meta name="viewport" content="width=device-width,initial-scale=1">
6
- <meta http-equiv="refresh" content="3;URL='/'" />
7
- <link rel="stylesheet" href="https://unpkg.com/@shopify/polaris@5.1.0/dist/styles.css" />
8
- </head>
9
- <body>
10
- <div>
11
- <div>
12
- <h1>Waiting for React Sever to boot up.</h1>
13
- <p>This page will refresh automatically.</p>
14
- </div>
15
- <p>
16
- If this error persists, ensure <code>@shopify/react-server</code>
17
- is running on <code>http://localhost:8081</code>.
18
- </p>
19
- </div>
20
- </body>
21
- </html>