@tramvai/module-server 7.0.3 → 7.2.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.
@@ -6,21 +6,23 @@ import { prepareLogsForError } from './prepareLogsForError.es.js';
6
6
  import { renderErrorBoundaryPageToString } from './renderErrorBoundaryPageToString.es.js';
7
7
 
8
8
  const errorHandler = async (app, { log, beforeError, afterError, fetchWebpackStats, staticRootErrorBoundaryError, }) => {
9
- const webpackStats = await fetchWebpackStats();
10
9
  const RootErrorBoundary = getRootErrorBoundary();
11
10
  const isRootErrorBoundaryExist = RootErrorBoundary !== null;
12
11
  if (process.env.TRAMVAI_CLI_COMMAND === 'static' && isRootErrorBoundaryExist) {
13
12
  serveRootErrorBoundary({
14
- response: renderErrorBoundaryPageToString({
15
- element: RootErrorBoundary,
16
- requestUrl: '/5xx.html',
17
- error: staticRootErrorBoundaryError ?? {
18
- name: 'STATIC_ROOT_ERROR_BOUNDARY_ERROR',
19
- message: 'Default error for root error boundary',
20
- },
21
- httpStatus: 500,
22
- webpackStats,
23
- }),
13
+ render: async () => {
14
+ const webpackStats = await fetchWebpackStats();
15
+ return renderErrorBoundaryPageToString({
16
+ element: RootErrorBoundary,
17
+ requestUrl: '/5xx.html',
18
+ error: staticRootErrorBoundaryError ?? {
19
+ name: 'STATIC_ROOT_ERROR_BOUNDARY_ERROR',
20
+ message: 'Default error for root error boundary',
21
+ },
22
+ httpStatus: 500,
23
+ webpackStats,
24
+ });
25
+ },
24
26
  app,
25
27
  });
26
28
  }
@@ -61,6 +63,7 @@ More information about redirects - https://tramvai.dev/docs/features/routing/red
61
63
  reply.status(httpStatus);
62
64
  if (isRootErrorBoundaryExist) {
63
65
  try {
66
+ const webpackStats = await fetchWebpackStats();
64
67
  const response = renderErrorBoundaryPageToString({
65
68
  element: RootErrorBoundary,
66
69
  requestUrl: requestInfo.url,
@@ -14,21 +14,23 @@ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'defau
14
14
  var isNil__default = /*#__PURE__*/_interopDefaultLegacy(isNil);
15
15
 
16
16
  const errorHandler = async (app, { log, beforeError, afterError, fetchWebpackStats, staticRootErrorBoundaryError, }) => {
17
- const webpackStats = await fetchWebpackStats();
18
17
  const RootErrorBoundary = utils.getRootErrorBoundary();
19
18
  const isRootErrorBoundaryExist = RootErrorBoundary !== null;
20
19
  if (process.env.TRAMVAI_CLI_COMMAND === 'static' && isRootErrorBoundaryExist) {
21
20
  serveRootErrorBoundary.serveRootErrorBoundary({
22
- response: renderErrorBoundaryPageToString.renderErrorBoundaryPageToString({
23
- element: RootErrorBoundary,
24
- requestUrl: '/5xx.html',
25
- error: staticRootErrorBoundaryError ?? {
26
- name: 'STATIC_ROOT_ERROR_BOUNDARY_ERROR',
27
- message: 'Default error for root error boundary',
28
- },
29
- httpStatus: 500,
30
- webpackStats,
31
- }),
21
+ render: async () => {
22
+ const webpackStats = await fetchWebpackStats();
23
+ return renderErrorBoundaryPageToString.renderErrorBoundaryPageToString({
24
+ element: RootErrorBoundary,
25
+ requestUrl: '/5xx.html',
26
+ error: staticRootErrorBoundaryError ?? {
27
+ name: 'STATIC_ROOT_ERROR_BOUNDARY_ERROR',
28
+ message: 'Default error for root error boundary',
29
+ },
30
+ httpStatus: 500,
31
+ webpackStats,
32
+ });
33
+ },
32
34
  app,
33
35
  });
34
36
  }
@@ -69,6 +71,7 @@ More information about redirects - https://tramvai.dev/docs/features/routing/red
69
71
  reply.status(httpStatus);
70
72
  if (isRootErrorBoundaryExist) {
71
73
  try {
74
+ const webpackStats = await fetchWebpackStats();
72
75
  const response = renderErrorBoundaryPageToString.renderErrorBoundaryPageToString({
73
76
  element: RootErrorBoundary,
74
77
  requestUrl: requestInfo.url,
@@ -1,6 +1,6 @@
1
1
  import type { FastifyInstance } from 'fastify';
2
- export declare function serveRootErrorBoundary({ response, app, }: {
3
- response: string;
2
+ export declare function serveRootErrorBoundary({ render, app, }: {
3
+ render: () => Promise<string>;
4
4
  app: FastifyInstance;
5
5
  }): void;
6
6
  //# sourceMappingURL=serveRootErrorBoundary.d.ts.map
@@ -1,6 +1,20 @@
1
- function serveRootErrorBoundary({ response, app, }) {
1
+ function serveRootErrorBoundary({ render, app, }) {
2
+ // Error page is static so we can cache it
3
+ let response;
4
+ // Warm up error page on startup
5
+ setTimeout(() => {
6
+ if (!response) {
7
+ // eslint-disable-next-line promise/catch-or-return
8
+ render().then((res) => {
9
+ response = res;
10
+ });
11
+ }
12
+ }, 0);
2
13
  app.register(async (instance) => {
3
- instance.all('/_errors/5xx', (request, reply) => {
14
+ instance.all('/_errors/5xx', async (request, reply) => {
15
+ if (!response) {
16
+ response = await render();
17
+ }
4
18
  reply.status(200);
5
19
  reply.header('Content-Type', 'text/html; charset=utf-8');
6
20
  reply.header('Content-Length', Buffer.byteLength(response, 'utf8'));
@@ -2,9 +2,23 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- function serveRootErrorBoundary({ response, app, }) {
5
+ function serveRootErrorBoundary({ render, app, }) {
6
+ // Error page is static so we can cache it
7
+ let response;
8
+ // Warm up error page on startup
9
+ setTimeout(() => {
10
+ if (!response) {
11
+ // eslint-disable-next-line promise/catch-or-return
12
+ render().then((res) => {
13
+ response = res;
14
+ });
15
+ }
16
+ }, 0);
6
17
  app.register(async (instance) => {
7
- instance.all('/_errors/5xx', (request, reply) => {
18
+ instance.all('/_errors/5xx', async (request, reply) => {
19
+ if (!response) {
20
+ response = await render();
21
+ }
8
22
  reply.status(200);
9
23
  reply.header('Content-Type', 'text/html; charset=utf-8');
10
24
  reply.header('Content-Length', Buffer.byteLength(response, 'utf8'));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tramvai/module-server",
3
- "version": "7.0.3",
3
+ "version": "7.2.0",
4
4
  "description": "",
5
5
  "browser": "lib/browser.js",
6
6
  "main": "lib/server.js",
@@ -30,29 +30,29 @@
30
30
  "@tinkoff/monkeypatch": "7.0.1",
31
31
  "@tinkoff/terminus": "0.6.1",
32
32
  "@tinkoff/url": "0.13.1",
33
- "@tramvai/module-cache-warmup": "7.0.3",
34
- "@tramvai/module-metrics": "7.0.3",
35
- "@tramvai/papi": "7.0.3",
33
+ "@tramvai/module-cache-warmup": "7.2.0",
34
+ "@tramvai/module-metrics": "7.2.0",
35
+ "@tramvai/papi": "7.2.0",
36
36
  "@tramvai/safe-strings": "0.10.1",
37
- "@tramvai/tokens-router": "7.0.3",
38
- "@tramvai/tokens-server": "7.0.3",
39
- "@tramvai/tokens-server-private": "7.0.3",
37
+ "@tramvai/tokens-router": "7.2.0",
38
+ "@tramvai/tokens-server": "7.2.0",
39
+ "@tramvai/tokens-server-private": "7.2.0",
40
40
  "afterframe": "^1.0.2",
41
41
  "fastify": "^5.6.2",
42
42
  "http-proxy-middleware": "^2.0.2",
43
- "undici": "^7.16.0"
43
+ "undici": "^7.18.2"
44
44
  },
45
45
  "peerDependencies": {
46
46
  "@tinkoff/dippy": "0.13.1",
47
47
  "@tinkoff/utils": "^2.1.2",
48
- "@tramvai/cli": "7.0.3",
49
- "@tramvai/core": "7.0.3",
50
- "@tramvai/module-common": "7.0.3",
51
- "@tramvai/module-environment": "7.0.3",
52
- "@tramvai/react": "7.0.3",
53
- "@tramvai/tokens-common": "7.0.3",
54
- "@tramvai/tokens-core-private": "7.0.3",
55
- "@tramvai/tokens-render": "7.0.3",
48
+ "@tramvai/cli": "7.2.0",
49
+ "@tramvai/core": "7.2.0",
50
+ "@tramvai/module-common": "7.2.0",
51
+ "@tramvai/module-environment": "7.2.0",
52
+ "@tramvai/react": "7.2.0",
53
+ "@tramvai/tokens-common": "7.2.0",
54
+ "@tramvai/tokens-core-private": "7.2.0",
55
+ "@tramvai/tokens-render": "7.2.0",
56
56
  "react": ">=16.14.0",
57
57
  "react-dom": ">=16.14.0",
58
58
  "tslib": "^2.4.0"