@tramvai/module-render 2.98.0 → 2.100.0

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.
package/lib/browser.js CHANGED
@@ -1,10 +1,11 @@
1
1
  import { __decorate } from 'tslib';
2
2
  import { Module, provide, commandLineListTokens, DI_TOKEN } from '@tramvai/core';
3
3
  import { STORE_TOKEN, LOGGER_TOKEN, CONTEXT_TOKEN } from '@tramvai/tokens-common';
4
- import { RESOURCES_REGISTRY, CUSTOM_RENDER, EXTEND_RENDER, RENDERER_CALLBACK, USE_REACT_STRICT_MODE, RENDER_MODE } from '@tramvai/tokens-render';
4
+ import { RESOURCES_REGISTRY, CUSTOM_RENDER, EXTEND_RENDER, RENDERER_CALLBACK, USE_REACT_STRICT_MODE, RENDER_MODE, MODERN_SATISFIES_TOKEN } from '@tramvai/tokens-render';
5
5
  export * from '@tramvai/tokens-render';
6
6
  import { beforeResolveHooksToken, PageErrorStore, setPageErrorEvent } from '@tramvai/module-router';
7
7
  export { PageErrorStore, setPageErrorEvent } from '@tramvai/module-router';
8
+ import { COOKIE_MANAGER_TOKEN } from '@tramvai/module-common';
8
9
  import { rendering } from './client/index.browser.js';
9
10
  import { LayoutModule } from './shared/LayoutModule.browser.js';
10
11
  import { providers } from './shared/providers.browser.js';
@@ -107,6 +108,16 @@ RenderModule = RenderModule_1 = __decorate([
107
108
  provide: RENDER_MODE,
108
109
  useValue: 'legacy',
109
110
  }),
111
+ provide({
112
+ provide: MODERN_SATISFIES_TOKEN,
113
+ useFactory: ({ cookieManager }) => {
114
+ const result = cookieManager.get('_t_modern');
115
+ return result === 'true' || result === 'false' ? JSON.parse(result) : false;
116
+ },
117
+ deps: {
118
+ cookieManager: COOKIE_MANAGER_TOKEN,
119
+ },
120
+ }),
110
121
  ],
111
122
  })
112
123
  ], RenderModule);
@@ -2,6 +2,8 @@ import debounce from '@tinkoff/utils/function/debounce';
2
2
  import { createElement } from 'react';
3
3
  import { useIsomorphicLayoutEffect } from '@tinkoff/react-hooks';
4
4
 
5
+ const reactMinifiedErrorRegex = /Minified React error #(\d+);/;
6
+ const shortenErrorStackTrace = (stackTrace) => stackTrace.split('\n').slice(0, 15).join('\n');
5
7
  let hydrateRoot;
6
8
  let startTransition;
7
9
  try {
@@ -36,8 +38,18 @@ const renderer = ({ element, container, callback, log }) => {
36
38
  return startTransition(() => {
37
39
  hydrateRoot(container, wrappedElement, {
38
40
  onRecoverableError: (error, errorInfo) => {
39
- // deduplicate by unique important string values
40
- allErrors.set((error === null || error === void 0 ? void 0 : error.message) + (errorInfo === null || errorInfo === void 0 ? void 0 : errorInfo.componentStack), { error, errorInfo });
41
+ var _a, _b;
42
+ const match = ((_a = error === null || error === void 0 ? void 0 : error.message) !== null && _a !== void 0 ? _a : '').match(reactMinifiedErrorRegex);
43
+ const key = (_b = match === null || match === void 0 ? void 0 : match[1]) !== null && _b !== void 0 ? _b : error === null || error === void 0 ? void 0 : error.message;
44
+ // deduplicate by error type - too much noise otherwise
45
+ if (!allErrors.has(key)) {
46
+ // also too long stack traces are not very helpful but heavy for log collection
47
+ if (typeof (errorInfo === null || errorInfo === void 0 ? void 0 : errorInfo.componentStack) === 'string') {
48
+ // eslint-disable-next-line no-param-reassign
49
+ errorInfo.componentStack = shortenErrorStackTrace(errorInfo.componentStack);
50
+ }
51
+ allErrors.set(key, { error, errorInfo });
52
+ }
41
53
  logHydrateRecoverableError();
42
54
  },
43
55
  });
package/lib/server.es.js CHANGED
@@ -10,6 +10,7 @@ import { satisfies } from '@tinkoff/user-agent';
10
10
  import { isRedirectFoundError } from '@tinkoff/errors';
11
11
  import { setPageErrorEvent, PageErrorStore, deserializeError } from '@tramvai/module-router';
12
12
  export { PageErrorStore, setPageErrorEvent } from '@tramvai/module-router';
13
+ import { COOKIE_MANAGER_TOKEN } from '@tramvai/module-common';
13
14
  import { ResourcesInliner } from './resourcesInliner/resourcesInliner.es.js';
14
15
  import { RESOURCE_INLINER, RESOURCES_REGISTRY_CACHE } from './resourcesInliner/tokens.es.js';
15
16
  import { ResourcesRegistry } from './resourcesRegistry/index.es.js';
@@ -251,19 +252,24 @@ Page Error Boundary will be rendered for the client`,
251
252
  }),
252
253
  provide({
253
254
  provide: MODERN_SATISFIES_TOKEN,
254
- useFactory: ({ requestManager, userAgent, cache }) => {
255
+ useFactory: ({ requestManager, userAgent, cache, cookieManager }) => {
255
256
  const reqUserAgent = requestManager.getHeader('user-agent');
257
+ let result;
256
258
  if (cache.has(reqUserAgent)) {
257
- return cache.get(reqUserAgent);
259
+ result = cache.get(reqUserAgent);
258
260
  }
259
- const result = satisfies(userAgent, null, { env: 'modern' });
260
- cache.set(reqUserAgent, result);
261
+ else {
262
+ result = satisfies(userAgent, null, { env: 'modern' });
263
+ cache.set(reqUserAgent, result);
264
+ }
265
+ cookieManager.set({ name: '_t_modern', value: JSON.stringify(result) });
261
266
  return result;
262
267
  },
263
268
  deps: {
264
269
  requestManager: REQUEST_MANAGER_TOKEN,
265
270
  userAgent: USER_AGENT_TOKEN,
266
271
  cache: 'modernSatisfiesLruCache',
272
+ cookieManager: COOKIE_MANAGER_TOKEN,
267
273
  },
268
274
  }),
269
275
  provide({
package/lib/server.js CHANGED
@@ -12,6 +12,7 @@ var dippy = require('@tinkoff/dippy');
12
12
  var userAgent = require('@tinkoff/user-agent');
13
13
  var errors = require('@tinkoff/errors');
14
14
  var moduleRouter = require('@tramvai/module-router');
15
+ var moduleCommon = require('@tramvai/module-common');
15
16
  var resourcesInliner = require('./resourcesInliner/resourcesInliner.js');
16
17
  var tokens = require('./resourcesInliner/tokens.js');
17
18
  var index = require('./resourcesRegistry/index.js');
@@ -252,19 +253,24 @@ Page Error Boundary will be rendered for the client`,
252
253
  }),
253
254
  core.provide({
254
255
  provide: tokensRender.MODERN_SATISFIES_TOKEN,
255
- useFactory: ({ requestManager, userAgent: userAgent$1, cache }) => {
256
+ useFactory: ({ requestManager, userAgent: userAgent$1, cache, cookieManager }) => {
256
257
  const reqUserAgent = requestManager.getHeader('user-agent');
258
+ let result;
257
259
  if (cache.has(reqUserAgent)) {
258
- return cache.get(reqUserAgent);
260
+ result = cache.get(reqUserAgent);
259
261
  }
260
- const result = userAgent.satisfies(userAgent$1, null, { env: 'modern' });
261
- cache.set(reqUserAgent, result);
262
+ else {
263
+ result = userAgent.satisfies(userAgent$1, null, { env: 'modern' });
264
+ cache.set(reqUserAgent, result);
265
+ }
266
+ cookieManager.set({ name: '_t_modern', value: JSON.stringify(result) });
262
267
  return result;
263
268
  },
264
269
  deps: {
265
270
  requestManager: tokensCommon.REQUEST_MANAGER_TOKEN,
266
271
  userAgent: moduleClientHints.USER_AGENT_TOKEN,
267
272
  cache: 'modernSatisfiesLruCache',
273
+ cookieManager: moduleCommon.COOKIE_MANAGER_TOKEN,
268
274
  },
269
275
  }),
270
276
  core.provide({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tramvai/module-render",
3
- "version": "2.98.0",
3
+ "version": "2.100.0",
4
4
  "description": "",
5
5
  "browser": "lib/browser.js",
6
6
  "main": "lib/server.js",
@@ -26,14 +26,14 @@
26
26
  "@tinkoff/layout-factory": "0.3.8",
27
27
  "@tinkoff/errors": "0.3.8",
28
28
  "@tinkoff/url": "0.8.6",
29
- "@tinkoff/user-agent": "0.4.277",
30
- "@tramvai/module-client-hints": "2.98.0",
31
- "@tramvai/module-page-render-mode": "2.98.0",
32
- "@tramvai/module-router": "2.98.0",
33
- "@tramvai/react": "2.98.0",
29
+ "@tinkoff/user-agent": "0.4.283",
30
+ "@tramvai/module-client-hints": "2.100.0",
31
+ "@tramvai/module-page-render-mode": "2.100.0",
32
+ "@tramvai/module-router": "2.100.0",
33
+ "@tramvai/react": "2.100.0",
34
34
  "@tramvai/safe-strings": "0.5.9",
35
- "@tramvai/tokens-render": "2.98.0",
36
- "@tramvai/experiments": "2.98.0",
35
+ "@tramvai/tokens-render": "2.100.0",
36
+ "@tramvai/experiments": "2.100.0",
37
37
  "@types/loadable__server": "^5.12.6",
38
38
  "node-fetch": "^2.6.1"
39
39
  },
@@ -41,14 +41,14 @@
41
41
  "@tinkoff/dippy": "0.8.15",
42
42
  "@tinkoff/utils": "^2.1.2",
43
43
  "@tinkoff/react-hooks": "0.1.6",
44
- "@tramvai/cli": "2.98.0",
45
- "@tramvai/core": "2.98.0",
46
- "@tramvai/module-common": "2.98.0",
47
- "@tramvai/state": "2.98.0",
48
- "@tramvai/test-helpers": "2.98.0",
49
- "@tramvai/tokens-common": "2.98.0",
50
- "@tramvai/tokens-router": "2.98.0",
51
- "@tramvai/tokens-server-private": "2.98.0",
44
+ "@tramvai/cli": "2.100.0",
45
+ "@tramvai/core": "2.100.0",
46
+ "@tramvai/module-common": "2.100.0",
47
+ "@tramvai/state": "2.100.0",
48
+ "@tramvai/test-helpers": "2.100.0",
49
+ "@tramvai/tokens-common": "2.100.0",
50
+ "@tramvai/tokens-router": "2.100.0",
51
+ "@tramvai/tokens-server-private": "2.100.0",
52
52
  "express": "^4.17.1",
53
53
  "prop-types": "^15.6.2",
54
54
  "react": ">=16.14.0",