quilt_rails 1.3.1 → 1.3.2

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: 5214ca27d069782ed72ddcd0f8efe1570ac2d8ebbf71df664f01d88977b09d80
4
- data.tar.gz: c80609914deb36fb2fe95b683b5bdca6bab97f2100609daf95e9938a31a35e4d
3
+ metadata.gz: 9cee30519a782a6fddf8ef312f68e594872ff80a832a776549c20c85775fa5e4
4
+ data.tar.gz: bb9c1ac6a10090dcb245eef5ac5523963319e413f6c19709da7a72f2c72508c5
5
5
  SHA512:
6
- metadata.gz: 98813d5e73ad5a700318b8185f08db41863665adb071bef21e9abfea66cbda8810f42ee4c3d7065dbc6fbd32111de9b875964a215258d3fdb6fd71ddd0bfaaab
7
- data.tar.gz: 0601b77ac976964817c259c5b4fc9d92356493ebe7f9bf617a5be03b8da9493e8cc04375bba08d6bedff54aec5db5b0fc7c5df0ca22ee9ff6eab6bb09f047e4b
6
+ metadata.gz: dcc8be76612a56b7f8a9b0874d3e8efee17fb6b2eb41ff426113f01e84431abc7418d74b8c1b533561fe9bfb7f647a6eae64fda37d5899fd1c1348ef2978bccd
7
+ data.tar.gz: ea5953b8ec5e4f4996eaf4f1d611b32c83d0f9b11809a41f478fd6d6123296321d5f74b9e59046001ce4a8bbdf9171531bc91d19e27445f1a3bf840171910e21
data/README.md CHANGED
@@ -4,6 +4,11 @@ A turn-key solution for integrating server-rendered react into your Rails app us
4
4
 
5
5
  This document focuses on Rails integration. For details of `@shopify/react-server`'s configuration and usage, see the [react-server documentation](/packages/react-server/README.md).
6
6
 
7
+ ## Table of Contents
8
+
9
+ 1. [Quick Start](#quick-start)
10
+ 1. [Advanced Use](#advanced-use)
11
+
7
12
  ## Quick Start
8
13
 
9
14
  ### Add Ruby dependencies
@@ -114,12 +119,115 @@ function App() {
114
119
  export default App;
115
120
  ```
116
121
 
117
- ## Rails Generators'
122
+ ## Rails Generators
118
123
 
119
124
  ### `quilt:install`
120
125
 
121
126
  Installs the Node dependencies, provide a basic React app (in TypeScript) and mounts the Quilt engine inside of your `config/routes.rb` file.
122
127
 
123
- ### `sewing-kit:install`
128
+ ### `sewing_kit:install`
124
129
 
125
130
  Adds a basic `sewing-kit.config.ts` file.
131
+
132
+ ## Advanced use
133
+
134
+ ### Interacting with the request / response in your React code
135
+
136
+ React-server sets up [@shopify/react-network](https://github.com/Shopify/quilt/blob/master/packages/react-network/src/hooks.ts#L25) for you, so most interactions with the request or response can be done from inside your React code.
137
+
138
+ #### Example: getting headers
139
+
140
+ ```tsx
141
+ // app/ui/index.tsx
142
+
143
+ import * as React from 'react';
144
+ import {AppProvider, Page, Card} from '@shopify/polaris';
145
+ import {useRequestHeader} from '@shopify/react-network';
146
+
147
+ function App() {
148
+ // get `some-header` from the request that was sent through Rails
149
+ const someHeaderICareAbout = useRequestHeader('some-header');
150
+
151
+ return (
152
+ <AppProvider>
153
+ <Page title="Hello">
154
+ {someHeaderICareAbout}
155
+ <Card sectioned>Hi there</Card>
156
+ </Page>
157
+ </AppProvider>
158
+ );
159
+ }
160
+
161
+ export default App;
162
+ ```
163
+
164
+ #### Example: redirecting
165
+
166
+ ```tsx
167
+ // app/ui/index.tsx
168
+
169
+ import * as React from 'react';
170
+ import {AppProvider, Page, Card} from '@shopify/polaris';
171
+ import {useRedirect} from '@shopify/react-network';
172
+
173
+ function App() {
174
+ // redirect to google as soon as we render
175
+ useRedirect('www.google.com');
176
+
177
+ return (
178
+ <AppProvider>
179
+ <Page title="Hello">
180
+ <Card sectioned>Hi there</Card>
181
+ </Page>
182
+ </AppProvider>
183
+ );
184
+ }
185
+
186
+ export default App;
187
+ ```
188
+
189
+ ### Customizing the node server
190
+
191
+ By default, sewing-kit bundles in `@shopify/react-server-webpack-plugin` for `quilt_rails` applications to get you up and running fast without needing to manually write any node server code. If you would like to customize what data your react application receives from the incoming request, you can add your own `server.js` / `server.ts` file to the app folder.
192
+
193
+ ```
194
+ └── app
195
+ └── ui
196
+ └─- app.js
197
+ └─- index.js
198
+ └─- server.js
199
+ ```
200
+
201
+ ```tsx
202
+ // app/ui/server.tsx
203
+ import '@shopify/polyfills/fetch';
204
+ import {createServer} from '@shopify/react-server';
205
+ import {Context} from 'koa';
206
+ import React from 'react';
207
+
208
+ import App from './app';
209
+
210
+ // you could create your own server from scratch, but the easiest way to is using `@shopify/react-server`
211
+ // https://github.com/Shopify/quilt/blob/master/packages/react-server/README.md#L8
212
+ const app = createServer({
213
+ port: process.env.PORT ? parseInt(process.env.PORT, 10) : 8081,
214
+ ip: process.env.IP,
215
+ assetPrefix: process.env.CDN_URL || 'localhost:8080/assets/webpack',
216
+ serverMiddleware: [(ctx, next) => {
217
+ // you can add your own middleware to extend the server's functionality.
218
+ console.log('I am a custom middleware!');
219
+ await next();
220
+ }]
221
+ render: (ctx, {locale}) => {
222
+ const whatever = /* do something special with the koa context */;
223
+ // any special data we add to the incoming request in our rails controller we can access here to pass into our component
224
+ return <App server someCustomProp={whatever} location={ctx.request.url} locale={locale} />;
225
+ },
226
+ });
227
+
228
+ export default app;
229
+ ```
230
+
231
+ ### Isomorphic state
232
+
233
+ With SSR enabled React apps, state must be serialized on the server and deserialized on the client to keep it consistent. With `@shopify/react-server`, the main way you will accomplish is using [`@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 to implement [self-serializers](https://github.com/Shopify/quilt/blob/master/packages/react-self-serializers/README.md#self-serializers). We offer some common ones out of the box in [`@shopify/react-self-serializers`](https://github.com/Shopify/quilt/blob/master/packages/react-self-serializers/README.md#self-serializers).
data/config/routes.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  Quilt::Engine.routes.draw do
4
- get '/*path', to: 'react#index'
5
- root 'react#index'
4
+ get '/*path', to: 'ui#index'
5
+ root 'ui#index'
6
6
  end
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module Quilt
3
- VERSION = "1.3.1"
3
+ VERSION = "1.3.2"
4
4
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: quilt_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.1
4
+ version: 1.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mathew Allen