@tramvai/module-page-render-mode 2.72.3 → 2.72.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +1 -227
  2. package/package.json +13 -13
package/README.md CHANGED
@@ -1,34 +1,6 @@
1
1
  # @tramvai/module-page-render-mode
2
2
 
3
- Enable different rendering modes for specific pages:
4
-
5
- - `ssr`
6
-
7
- SSR mode - provides default `tramvai` behaviour, render full page on server-side.
8
-
9
- - `client`
10
-
11
- Client mode - render only fallback for page component, then render full page on browser, after hydration.
12
-
13
- This mode can significally improve server rendering performance, but not recommended for pages with high SEO impact.
14
-
15
- By default, Header and Footer will be rendered as usual.
16
-
17
- - `static`
18
-
19
- Static mode - in-memory cache for page HTML markup.
20
-
21
- Response for first request for specific page, without `Cookie` header, will be cached directly, and sended as response to next requests for this page. Otherwise, unpersonalized request for the same page will be triggered at background, and result will be cached.
22
-
23
- 5xx responses will not be cached by default, but this behaviour are configurable.
24
-
25
- Any responses from cache will have `X-Tramvai-Static-Page-From-Cache` header.
26
-
27
- Additional metric with name `static_pages_cache_hit` will be added with cache hits counter.
28
-
29
- Response from cache will be sended from `customer_start` command line, and next lines execution will be aborted.
30
-
31
- Cache will be segmented by page path and method, request hostname, device type and browser (modern or default group).
3
+ Link to complete Page Render Modes documentation - https://tramvai.dev/docs/features/rendering/page-render-mode/
32
4
 
33
5
  ## Installation
34
6
 
@@ -49,201 +21,3 @@ createApp({
49
21
  modules: [PageRenderModeModule],
50
22
  });
51
23
  ```
52
-
53
- ## Usage
54
-
55
- ### Rendering mode
56
-
57
- By default, this module connection has no changes, because default rendering mode is `ssr`. You can change this mode for all pages or for specific pages only.
58
-
59
- #### Default mode
60
-
61
- For global rendering mode changing, use token `TRAMVAI_RENDER_MODE` from `@tramvai/tokens-render`:
62
-
63
- ```ts
64
- import { TRAMVAI_RENDER_MODE } from '@tramvai/tokens-render';
65
-
66
- const provider = {
67
- provide: TRAMVAI_RENDER_MODE,
68
- useValue: 'client',
69
- };
70
- ```
71
-
72
- #### Mode for specifig pages
73
-
74
- For specific pages available two options:
75
-
76
- - setting mode in route config:
77
-
78
- ```ts
79
- const routes = [
80
- {
81
- name: 'main',
82
- path: '/',
83
- config: {
84
- bundle: 'mainDefault',
85
- pageComponent: 'pageDefault',
86
- pageRenderMode: 'client',
87
- },
88
- },
89
- ];
90
- ```
91
-
92
- - setting mode in page component static property:
93
-
94
- ```tsx
95
- const PageComponent = () => <div>Page</div>;
96
-
97
- PageComponent.renderMode = 'client';
98
-
99
- export default PageComponent;
100
- ```
101
-
102
- ### Fallback
103
-
104
- Standard behaviour for SPA applications - render some fallback with spinner or page skeleton before application was rendered. You can set default fallback for all pages with `client` render mode, or only for specific pages.
105
-
106
- #### Default fallback
107
-
108
- For setting default fallback, use token `PAGE_RENDER_DEFAULT_FALLBACK_COMPONENT`:
109
-
110
- ```tsx
111
- import { PAGE_RENDER_DEFAULT_FALLBACK_COMPONENT } from '@tramvai/module-page-render-mode';
112
-
113
- const DefaultFallback = () => <div>Loading...</div>;
114
-
115
- const provider = {
116
- provide: PAGE_RENDER_DEFAULT_FALLBACK_COMPONENT,
117
- useValue: DefaultFallback,
118
- };
119
- ```
120
-
121
- #### Fallback for specific pages
122
-
123
- For specific pages available few options:
124
-
125
- - add fallback to page component static property, use name `pageRenderFallbackDefault`:
126
-
127
- ```tsx
128
- import { PageComponent } from '@tramvai/react';
129
-
130
- const Page: PageComponent = () => <div>Page</div>;
131
-
132
- const PageFallback = () => <div>Loading...</div>;
133
-
134
- Page.components = {
135
- pageRenderFallbackDefault: PageFallback,
136
- };
137
-
138
- export default Page;
139
- ```
140
-
141
- - add default fallback to bundle, use name `pageRenderFallbackDefault`:
142
-
143
- ```tsx
144
- const DefaultFallback = () => <div>Loading...</div>;
145
-
146
- const mainDefaultBundle = createBundle({
147
- name: 'mainDefault',
148
- components: {
149
- pageRenderFallbackDefault: DefaultFallback,
150
- },
151
- });
152
-
153
- export default mainDefaultBundle;
154
- ```
155
-
156
- - and you can add fallback in route config, use key `pageRenderFallbackComponent` with any fallback name you provided in bundle or page component:
157
-
158
- ```ts
159
- const routes = [
160
- {
161
- name: 'main',
162
- path: '/',
163
- config: {
164
- bundle: 'mainDefault',
165
- pageComponent: 'pageDefault',
166
- pageRenderFallbackComponent: 'myOwnFallbackComponent',
167
- },
168
- },
169
- ];
170
- ```
171
-
172
- ### Static pages
173
-
174
- #### Options
175
-
176
- - `ttl` parameter spicified page response cache time. Default - `60000` ms.
177
- - `maxSize` parameter spicified maximum cached urls count (can be up to 4 pages per url for different segments). Default - `1000`. For apps with heavy HTML and a lot of urls memory usage can be increased significantly.
178
-
179
- ```ts
180
- const provider = {
181
- provide: STATIC_PAGES_OPTIONS_TOKEN,
182
- useValue: {
183
- ttl: 60 * 1000,
184
- maxSize: 1000,
185
- },
186
- };
187
- ```
188
-
189
- ## How-to
190
-
191
- ### How to prevent Header and Footer Rendering
192
-
193
- By default, Header and Footer will be rendered as usual, because this module provide Page component wrapper. If you want to make less work on server, use token `PAGE_RENDER_WRAPPER_TYPE` with `layout` or `content` value, e.g.:
194
-
195
- ```ts
196
- const providers = [
197
- {
198
- provide: PAGE_RENDER_WRAPPER_TYPE,
199
- useValue: 'layout',
200
- },
201
- ];
202
- ```
203
-
204
- With `client` rendering mode, all layout will be rendered in browser.
205
-
206
- `PAGE_RENDER_WRAPPER_TYPE` value will be passed to [default layout](references/modules/render.md#basic-layout), where the library [@tinkoff/layout-factory](references/libs/tinkoff-layout.md#wrappers) is used.
207
-
208
- ### How to clear static page cache
209
-
210
- If you want to clear all cache, make POST request to special papi endpoint without body - `/{appName}/private/papi/revalidate/`.
211
-
212
- For specific page, just add `path` parameter to request body, e.g. for `/static/` - `{ path: 'static' }`.
213
-
214
- ### How to disable background requests for static pages
215
-
216
- For example, you want to cache only requests without cookies, without extra requests into the application:
217
-
218
- ```ts
219
- const provider = {
220
- provide: STATIC_PAGES_BACKGROUND_FETCH_ENABLED,
221
- useValue: () => false,
222
- };
223
- ```
224
-
225
- ### How to enable 5xx requests caching for static pages
226
-
227
- For example, 5xx responses are expected behaviour:
228
-
229
- ```ts
230
- const provider = {
231
- provide: STATIC_PAGES_CACHE_5xx_RESPONSE,
232
- useValue: () => true,
233
- };
234
- ```
235
-
236
- ## Troubleshooting
237
-
238
- ### Fallback name conflicts
239
-
240
- You might have a potential issue with conflict existing components and render fallback component names - `pageRenderFallbackComponent` and `pageRenderFallbackDefault`. For avoiding this issues, just change fallback name prefix using token `PAGE_RENDER_FALLBACK_COMPONENT_PREFIX`:
241
-
242
- ```ts
243
- import { PAGE_RENDER_FALLBACK_COMPONENT_PREFIX } from '@tramvai/module-page-render-mode';
244
-
245
- const provider = {
246
- provide: PAGE_RENDER_FALLBACK_COMPONENT_PREFIX,
247
- useValue: 'myOwnRenderFallback',
248
- };
249
- ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tramvai/module-page-render-mode",
3
- "version": "2.72.3",
3
+ "version": "2.72.4",
4
4
  "description": "Enable different rendering modes for pages",
5
5
  "main": "./lib/server.js",
6
6
  "module": "./lib/server.es.js",
@@ -30,18 +30,18 @@
30
30
  "peerDependencies": {
31
31
  "@tinkoff/utils": "^2.1.2",
32
32
  "@tinkoff/dippy": "0.8.13",
33
- "@tramvai/core": "2.72.3",
34
- "@tramvai/react": "2.72.3",
35
- "@tramvai/papi": "2.72.3",
36
- "@tramvai/module-router": "2.72.3",
37
- "@tramvai/module-client-hints": "2.72.3",
38
- "@tramvai/tokens-common": "2.72.3",
39
- "@tramvai/tokens-core": "2.72.3",
40
- "@tramvai/tokens-render": "2.72.3",
41
- "@tramvai/tokens-router": "2.72.3",
42
- "@tramvai/tokens-server": "2.72.3",
43
- "@tramvai/tokens-server-private": "2.72.3",
44
- "@tramvai/tokens-metrics": "2.72.3",
33
+ "@tramvai/core": "2.72.4",
34
+ "@tramvai/react": "2.72.4",
35
+ "@tramvai/papi": "2.72.4",
36
+ "@tramvai/module-router": "2.72.4",
37
+ "@tramvai/module-client-hints": "2.72.4",
38
+ "@tramvai/tokens-common": "2.72.4",
39
+ "@tramvai/tokens-core": "2.72.4",
40
+ "@tramvai/tokens-render": "2.72.4",
41
+ "@tramvai/tokens-router": "2.72.4",
42
+ "@tramvai/tokens-server": "2.72.4",
43
+ "@tramvai/tokens-server-private": "2.72.4",
44
+ "@tramvai/tokens-metrics": "2.72.4",
45
45
  "prom-client": "^12.0.0",
46
46
  "react": ">=16.14.0",
47
47
  "tslib": "^2.4.0"