@shuvi/platform-web 1.0.0-rc.9 → 1.0.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/esm/shared/appTypes.d.ts +9 -5
- package/esm/shared/configTypes.d.ts +1 -3
- package/esm/shared/constants.d.ts +8 -0
- package/esm/shared/constants.js +8 -0
- package/esm/shared/htmlRenderer.d.ts +33 -0
- package/esm/shared/{serverTypes.js → htmlRenderer.js} +0 -0
- package/esm/shared/index.d.ts +2 -1
- package/esm/shared/index.js +2 -1
- package/esm/shared/renderTypes.d.ts +4 -4
- package/esm/shuvi-app/app/client.d.ts +2 -3
- package/esm/shuvi-app/app/client.js +4 -4
- package/esm/shuvi-app/app/server.js +9 -6
- package/esm/shuvi-app/dev/index.d.ts +2 -2
- package/esm/shuvi-app/entry/client/app.d.ts +1 -1
- package/esm/shuvi-app/entry/client/app.js +4 -4
- package/esm/shuvi-app/entry/client/index.js +1 -1
- package/esm/shuvi-app/entry/client/run.dev.js +12 -13
- package/esm/shuvi-app/helper/serializeServerError.d.ts +1 -1
- package/esm/shuvi-app/helper/serializeServerError.js +2 -2
- package/esm/shuvi-app/react/AppContainer.d.ts +2 -2
- package/esm/shuvi-app/react/AppContainer.jsx +1 -1
- package/esm/shuvi-app/react/ApplicationContext.d.ts +7 -0
- package/esm/shuvi-app/react/{applicationContext.jsx → ApplicationContext.jsx} +0 -0
- package/esm/shuvi-app/react/Error.jsx +4 -1
- package/esm/shuvi-app/react/Link.d.ts +2 -1
- package/esm/shuvi-app/react/Link.jsx +1 -1
- package/esm/shuvi-app/react/view/ReactView.server.jsx +17 -5
- package/lib/node/features/custom-server/server.js +20 -11
- package/lib/node/features/filesystem-routes/api/apiRouteHandler.js +5 -1
- package/lib/node/features/filesystem-routes/api/middleware.js +5 -2
- package/lib/node/features/filesystem-routes/hooks.d.ts +2 -1
- package/lib/node/features/filesystem-routes/hooks.js +2 -1
- package/lib/node/features/filesystem-routes/index.js +39 -39
- package/lib/node/features/filesystem-routes/middleware/middleware.js +5 -2
- package/lib/node/features/filesystem-routes/page/routes.js +2 -7
- package/lib/node/features/html-render/index.d.ts +2 -1
- package/lib/node/features/html-render/index.js +66 -24
- package/lib/node/features/html-render/lib/buildHtml.js +2 -1
- package/lib/node/features/html-render/lib/generateFilesByRoutId.d.ts +1 -1
- package/lib/node/features/html-render/lib/generateResource.js +12 -8
- package/lib/node/features/html-render/lib/getPageMiddleware.d.ts +1 -1
- package/lib/node/features/html-render/lib/getPageMiddleware.js +18 -13
- package/lib/node/features/html-render/lib/index.d.ts +0 -1
- package/lib/node/features/html-render/lib/index.js +0 -1
- package/lib/node/features/html-render/lib/renderToHTML.js +7 -6
- package/lib/node/features/html-render/lib/renderer/base.d.ts +3 -4
- package/lib/node/features/html-render/lib/renderer/base.js +16 -8
- package/lib/node/features/html-render/lib/renderer/index.js +10 -4
- package/lib/node/features/html-render/lib/renderer/ssr.d.ts +1 -1
- package/lib/node/features/html-render/lib/renderer/ssr.js +7 -8
- package/lib/node/features/html-render/lib/renderer/types.d.ts +4 -5
- package/lib/node/features/html-render/lib/webpack/build-manifest-plugin.d.ts +27 -0
- package/lib/node/features/html-render/lib/webpack/build-manifest-plugin.js +223 -0
- package/lib/node/features/html-render/serverHooks.d.ts +6 -1
- package/lib/node/features/html-render/serverHooks.js +1 -2
- package/lib/node/features/middlewares.d.ts +1 -1
- package/lib/node/features/middlewares.js +12 -3
- package/lib/node/features/model/index.js +3 -27
- package/lib/node/features/model/runtime.js +0 -1
- package/lib/node/features/on-demand-compile-page/onDemandRouteManager.js +3 -3
- package/lib/node/index.d.ts +1 -0
- package/lib/node/index.js +16 -2
- package/lib/node/shuvi-runtime-server.d.ts +15 -7
- package/lib/node/shuvi-type-extensions-node.d.ts +19 -18
- package/lib/node/targets/react/bundler/index.js +14 -13
- package/lib/node/targets/react/index.d.ts +0 -1
- package/lib/node/targets/react/index.js +1 -5
- package/lib/node/targets/react/model/index.js +3 -26
- package/lib/node/version.d.ts +1 -0
- package/lib/node/version.js +13 -0
- package/lib/shared/appTypes.d.ts +9 -5
- package/lib/shared/configTypes.d.ts +1 -3
- package/lib/shared/constants.d.ts +8 -0
- package/lib/shared/constants.js +15 -0
- package/lib/shared/htmlRenderer.d.ts +33 -0
- package/lib/shared/{serverTypes.js → htmlRenderer.js} +0 -0
- package/lib/shared/index.d.ts +2 -1
- package/lib/shared/index.js +2 -1
- package/lib/shared/renderTypes.d.ts +4 -4
- package/package.json +35 -26
- package/polyfills/polyfills.js +1 -0
- package/esm/shared/serverTypes.d.ts +0 -6
- package/esm/shuvi-app/react/applicationContext.d.ts +0 -7
- package/esm/shuvi-app/shuvi-runtime-index.d.ts +0 -4
- package/esm/shuvi-app/shuvi-runtime-index.js +0 -2
- package/lib/node/features/html-render/lib/pageLoader.d.ts +0 -1
- package/lib/node/features/html-render/lib/pageLoader.js +0 -42
- package/lib/shared/serverTypes.d.ts +0 -6
package/esm/shared/appTypes.d.ts
CHANGED
|
@@ -1,17 +1,21 @@
|
|
|
1
|
-
import { IPageRouteRecord, IAppData, IAppState } from '@shuvi/platform-shared/shared';
|
|
2
|
-
import {
|
|
1
|
+
import { IPageRouteRecord, IAppData, IAppState, Application as _Application } from '@shuvi/platform-shared/shared';
|
|
2
|
+
import { ApplicationImpl as _ApplicationImpl } from '@shuvi/platform-shared/shuvi-app/application';
|
|
3
3
|
import type { ShuviRequest } from '@shuvi/service';
|
|
4
|
+
export interface AppConfig {
|
|
5
|
+
ssr: boolean;
|
|
6
|
+
}
|
|
7
|
+
export declare type InternalApplication = _ApplicationImpl<AppConfig>;
|
|
8
|
+
export declare type Application = _Application<AppConfig>;
|
|
4
9
|
export interface CreateAppServer {
|
|
5
10
|
(options: {
|
|
6
11
|
req: ShuviRequest;
|
|
7
12
|
ssr: boolean;
|
|
8
|
-
|
|
9
|
-
}): Application;
|
|
13
|
+
}): InternalApplication;
|
|
10
14
|
}
|
|
11
15
|
export interface CreateAppClient {
|
|
12
16
|
(options: {
|
|
13
17
|
routes: IPageRouteRecord[];
|
|
14
18
|
appComponent: any;
|
|
15
19
|
appData: IAppData<any, IAppState>;
|
|
16
|
-
}):
|
|
20
|
+
}): InternalApplication;
|
|
17
21
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { IRouterHistoryMode, IPageRouteConfig
|
|
1
|
+
import { IRouterHistoryMode, IPageRouteConfig } from '@shuvi/platform-shared/shared';
|
|
2
2
|
export interface IRouterConfig {
|
|
3
3
|
history: IRouterHistoryMode | 'auto';
|
|
4
4
|
}
|
|
@@ -6,8 +6,6 @@ export interface PlatformWebCustomConfig {
|
|
|
6
6
|
ssr: boolean;
|
|
7
7
|
router: IRouterConfig;
|
|
8
8
|
routes?: IPageRouteConfig[];
|
|
9
|
-
middlewareRoutes?: IMiddlewareRouteConfig[];
|
|
10
|
-
apiRoutes?: IApiRouteConfig[];
|
|
11
9
|
conventionRoutes: {
|
|
12
10
|
exclude?: string[];
|
|
13
11
|
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { BUNDLER_TARGET_CLIENT, BUNDLER_TARGET_SERVER, CLIENT_OUTPUT_DIR, SERVER_OUTPUT_DIR } from '@shuvi/shared/lib/constants';
|
|
2
|
+
export declare const CLIENT_BUILD_MANIFEST_PATH = "../build-manifest.client.json";
|
|
3
|
+
export declare const SERVER_BUILD_MANIFEST_PATH = "../build-manifest.server.json";
|
|
4
|
+
export declare const BUILD_CLIENT_RUNTIME_POLYFILLS = "static/polyfills";
|
|
5
|
+
export declare const BUILD_CLIENT_RUNTIME_POLYFILLS_SYMBOL: unique symbol;
|
|
6
|
+
export declare const BUILD_CLIENT_RUNTIME_WEBPACK = "static/webpack-runtime";
|
|
7
|
+
export declare const BUILD_CLIENT_RUNTIME_MAIN = "static/main";
|
|
8
|
+
export declare const BUILD_SERVER_FILE_SERVER = "server";
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { BUNDLER_TARGET_CLIENT, BUNDLER_TARGET_SERVER, CLIENT_OUTPUT_DIR, SERVER_OUTPUT_DIR } from '@shuvi/shared/lib/constants';
|
|
2
|
+
export const CLIENT_BUILD_MANIFEST_PATH = '../build-manifest.client.json';
|
|
3
|
+
export const SERVER_BUILD_MANIFEST_PATH = '../build-manifest.server.json';
|
|
4
|
+
export const BUILD_CLIENT_RUNTIME_POLYFILLS = `static/polyfills`;
|
|
5
|
+
export const BUILD_CLIENT_RUNTIME_POLYFILLS_SYMBOL = Symbol(`polyfills`);
|
|
6
|
+
export const BUILD_CLIENT_RUNTIME_WEBPACK = `static/webpack-runtime`;
|
|
7
|
+
export const BUILD_CLIENT_RUNTIME_MAIN = `static/main`;
|
|
8
|
+
export const BUILD_SERVER_FILE_SERVER = `server`;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
export interface IModuleItem {
|
|
2
|
+
id: string;
|
|
3
|
+
name: string;
|
|
4
|
+
}
|
|
5
|
+
export interface IModule {
|
|
6
|
+
files: string[];
|
|
7
|
+
children: IModuleItem[];
|
|
8
|
+
}
|
|
9
|
+
export declare type IAssetMap = {
|
|
10
|
+
js: string[];
|
|
11
|
+
css?: string[];
|
|
12
|
+
} & {
|
|
13
|
+
[ext: string]: string[];
|
|
14
|
+
};
|
|
15
|
+
export interface IChunk {
|
|
16
|
+
file: string;
|
|
17
|
+
request: string;
|
|
18
|
+
}
|
|
19
|
+
export interface IManifest {
|
|
20
|
+
polyfillFiles?: string[];
|
|
21
|
+
entries: {
|
|
22
|
+
[s: string]: IAssetMap;
|
|
23
|
+
};
|
|
24
|
+
bundles: {
|
|
25
|
+
[name: string]: string;
|
|
26
|
+
};
|
|
27
|
+
chunkRequest: {
|
|
28
|
+
[file: string]: string;
|
|
29
|
+
};
|
|
30
|
+
loadble: {
|
|
31
|
+
[s: string]: IModule;
|
|
32
|
+
};
|
|
33
|
+
}
|
|
File without changes
|
package/esm/shared/index.d.ts
CHANGED
package/esm/shared/index.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { IManifest } from '@shuvi/toolpack/lib/webpack/types';
|
|
2
1
|
import type { ShuviRequest } from '@shuvi/service';
|
|
3
|
-
import { Response,
|
|
2
|
+
import { Response, IAppData } from '@shuvi/platform-shared/shared';
|
|
3
|
+
import { IManifest } from '../shared';
|
|
4
|
+
import { Application } from './appTypes';
|
|
4
5
|
export declare type IRenderViewOptions = {
|
|
5
|
-
app:
|
|
6
|
+
app: Application;
|
|
6
7
|
};
|
|
7
8
|
export interface IRenderOptions extends IRenderViewOptions {
|
|
8
9
|
}
|
|
@@ -37,7 +38,6 @@ export interface IClientRendererOptions<ExtraAppData = {}> extends IRenderOption
|
|
|
37
38
|
export interface IServerRendererOptions extends IRenderOptions {
|
|
38
39
|
req: ShuviRequest;
|
|
39
40
|
manifest: IManifest;
|
|
40
|
-
isDev?: boolean;
|
|
41
41
|
}
|
|
42
42
|
export interface IViewClient<ExtraAppData = {}> extends IView<IClientRendererOptions<ExtraAppData>> {
|
|
43
43
|
}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
export { Application };
|
|
1
|
+
import { InternalApplication, CreateAppClient } from '../../shared';
|
|
2
|
+
export { InternalApplication };
|
|
4
3
|
export declare const createApp: CreateAppClient;
|
|
@@ -9,14 +9,13 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
};
|
|
10
10
|
import { getRoutes } from '@shuvi/app/core/platform';
|
|
11
11
|
import { runPreload, runLoaders, getRouteMatchesWithInvalidLoader, isRedirect, isResponse } from '@shuvi/platform-shared/shared';
|
|
12
|
-
import application
|
|
12
|
+
import application from '@shuvi/platform-shared/shuvi-app/application';
|
|
13
13
|
import { createRouter, createBrowserHistory, createHashHistory } from '@shuvi/router';
|
|
14
14
|
import pageLoaders from '@shuvi/app/files/page-loaders';
|
|
15
15
|
import { historyMode } from '@shuvi/app/files/routerConfig';
|
|
16
16
|
import { SHUVI_ERROR } from '@shuvi/shared/lib/constants';
|
|
17
17
|
import { serializeServerError } from '../helper/serializeServerError';
|
|
18
18
|
let app;
|
|
19
|
-
export { Application };
|
|
20
19
|
export const createApp = ({ routes, appData, appComponent }) => {
|
|
21
20
|
// app is a singleton in client side
|
|
22
21
|
if (app) {
|
|
@@ -37,7 +36,8 @@ export const createApp = ({ routes, appData, appComponent }) => {
|
|
|
37
36
|
app = application({
|
|
38
37
|
initialState: appState,
|
|
39
38
|
AppComponent: appComponent,
|
|
40
|
-
router
|
|
39
|
+
router,
|
|
40
|
+
config: { ssr }
|
|
41
41
|
});
|
|
42
42
|
const loadersData = app.getLoadersData();
|
|
43
43
|
const hasHydrateData = Object.keys(loadersData).length > 0;
|
|
@@ -109,7 +109,7 @@ export const createApp = ({ routes, appData, appComponent }) => {
|
|
|
109
109
|
next();
|
|
110
110
|
return;
|
|
111
111
|
}
|
|
112
|
-
app.setError(serializeServerError(error
|
|
112
|
+
app.setError(serializeServerError(error));
|
|
113
113
|
next();
|
|
114
114
|
return;
|
|
115
115
|
}
|
|
@@ -13,10 +13,10 @@ import { runLoaders, getRouteMatchesWithInvalidLoader, isResponse, isRedirect }
|
|
|
13
13
|
import pageLoaders from '@shuvi/app/files/page-loaders';
|
|
14
14
|
import application from '@shuvi/platform-shared/shuvi-app/application';
|
|
15
15
|
import { createRouter, createMemoryHistory } from '@shuvi/router';
|
|
16
|
-
import
|
|
16
|
+
import logger from '@shuvi/utils/lib/logger';
|
|
17
17
|
import { serializeServerError } from '../helper/serializeServerError';
|
|
18
18
|
export const createApp = options => {
|
|
19
|
-
const { req, ssr
|
|
19
|
+
const { req, ssr } = options;
|
|
20
20
|
const history = createMemoryHistory({
|
|
21
21
|
initialEntries: [(req && req.url) || '/'],
|
|
22
22
|
initialIndex: 0
|
|
@@ -50,10 +50,10 @@ export const createApp = options => {
|
|
|
50
50
|
next();
|
|
51
51
|
return;
|
|
52
52
|
}
|
|
53
|
-
if (
|
|
54
|
-
|
|
53
|
+
if (process.env.NODE_ENV === 'development') {
|
|
54
|
+
logger.error(error.stack);
|
|
55
55
|
}
|
|
56
|
-
app.setError(serializeServerError(error
|
|
56
|
+
app.setError(serializeServerError(error));
|
|
57
57
|
next();
|
|
58
58
|
return;
|
|
59
59
|
}
|
|
@@ -62,7 +62,10 @@ export const createApp = options => {
|
|
|
62
62
|
}
|
|
63
63
|
app = application({
|
|
64
64
|
AppComponent,
|
|
65
|
-
router
|
|
65
|
+
router,
|
|
66
|
+
config: {
|
|
67
|
+
ssr
|
|
68
|
+
}
|
|
66
69
|
});
|
|
67
70
|
return app;
|
|
68
71
|
};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { InternalApplication } from '../../shared';
|
|
2
2
|
import { HotDevClient } from './hotDevClient';
|
|
3
|
-
export declare const initHMRAndDevClient: (app:
|
|
3
|
+
export declare const initHMRAndDevClient: (app: InternalApplication) => HotDevClient;
|
|
@@ -20,17 +20,17 @@ const app = createApp({
|
|
|
20
20
|
routes,
|
|
21
21
|
appData
|
|
22
22
|
});
|
|
23
|
-
const render = () => {
|
|
23
|
+
const render = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
24
24
|
const appContainer = document.getElementById(CLIENT_CONTAINER_ID);
|
|
25
|
-
view.renderApp({
|
|
25
|
+
yield view.renderApp({
|
|
26
26
|
app: app.getPublicAPI(),
|
|
27
27
|
appData,
|
|
28
28
|
appContainer
|
|
29
29
|
});
|
|
30
|
-
};
|
|
30
|
+
});
|
|
31
31
|
const run = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
32
32
|
yield app.init();
|
|
33
|
-
render();
|
|
33
|
+
yield render();
|
|
34
34
|
});
|
|
35
35
|
export { run, app };
|
|
36
36
|
if (module.hot) {
|
|
@@ -8,23 +8,22 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
10
|
/// <reference lib="dom" />
|
|
11
|
-
import { DEV_STYLE_HIDE_FOUC
|
|
11
|
+
import { DEV_STYLE_HIDE_FOUC } from '@shuvi/shared/lib/constants';
|
|
12
12
|
import { initHMRAndDevClient } from '../../dev';
|
|
13
13
|
import { run, app } from './app';
|
|
14
|
+
function applyStyle() {
|
|
15
|
+
document
|
|
16
|
+
.querySelectorAll(`[${DEV_STYLE_HIDE_FOUC}]`)
|
|
17
|
+
.forEach(el => { var _a; return (_a = el.parentElement) === null || _a === void 0 ? void 0 : _a.removeChild(el); });
|
|
18
|
+
}
|
|
14
19
|
function init() {
|
|
15
20
|
return __awaiter(this, void 0, void 0, function* () {
|
|
16
21
|
initHMRAndDevClient(app);
|
|
17
|
-
// reduce FOUC caused by style-loader
|
|
18
|
-
const styleReady = new Promise(resolve => {
|
|
19
|
-
(window.requestAnimationFrame || setTimeout)(() => __awaiter(this, void 0, void 0, function* () {
|
|
20
|
-
yield window[DEV_STYLE_PREPARE];
|
|
21
|
-
document
|
|
22
|
-
.querySelectorAll(`[${DEV_STYLE_HIDE_FOUC}]`)
|
|
23
|
-
.forEach(el => { var _a; return (_a = el.parentElement) === null || _a === void 0 ? void 0 : _a.removeChild(el); });
|
|
24
|
-
resolve();
|
|
25
|
-
}));
|
|
26
|
-
});
|
|
27
|
-
yield styleReady;
|
|
28
22
|
});
|
|
29
23
|
}
|
|
30
|
-
init()
|
|
24
|
+
init()
|
|
25
|
+
.then(() => run())
|
|
26
|
+
.finally(() => {
|
|
27
|
+
// reduce FOUC caused by style-loader
|
|
28
|
+
applyStyle();
|
|
29
|
+
});
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { IError } from '@shuvi/platform-shared/shared';
|
|
2
|
-
export declare function serializeServerError(err: Error
|
|
2
|
+
export declare function serializeServerError(err: Error): IError;
|
|
@@ -9,8 +9,8 @@ function errorToJSON(err) {
|
|
|
9
9
|
stack: err.stack
|
|
10
10
|
};
|
|
11
11
|
}
|
|
12
|
-
export function serializeServerError(err
|
|
13
|
-
if (
|
|
12
|
+
export function serializeServerError(err) {
|
|
13
|
+
if (process.env.NODE_ENV === 'development') {
|
|
14
14
|
return errorToJSON(err);
|
|
15
15
|
}
|
|
16
16
|
return {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import { Application } from '../../shared';
|
|
3
3
|
export default function AppContainer({ app, children }: React.PropsWithChildren<{
|
|
4
|
-
app:
|
|
4
|
+
app: Application;
|
|
5
5
|
}>): JSX.Element;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { errorModel } from '@shuvi/platform-shared/shared';
|
|
3
|
-
import { AppProvider } from './
|
|
3
|
+
import { AppProvider } from './ApplicationContext';
|
|
4
4
|
import ErrorPage from './ErrorPage';
|
|
5
5
|
import { ErrorBoundary } from './ErrorBoundary';
|
|
6
6
|
import { Provider, useSharedModel } from './store';
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { Application } from '../../shared';
|
|
3
|
+
export declare const ApplicationContext: React.Context<Application>;
|
|
4
|
+
export declare function AppProvider({ app, children }: React.PropsWithChildren<{
|
|
5
|
+
app: Application;
|
|
6
|
+
}>): JSX.Element;
|
|
7
|
+
export declare function useApp(): Application;
|
|
File without changes
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { Head } from './head';
|
|
3
|
+
import { useApp } from './ApplicationContext';
|
|
3
4
|
const style = {
|
|
4
5
|
container: {
|
|
5
6
|
color: '#000',
|
|
@@ -25,13 +26,15 @@ const style = {
|
|
|
25
26
|
}
|
|
26
27
|
};
|
|
27
28
|
export default function Error({ errorCode, errorDesc }) {
|
|
29
|
+
const app = useApp();
|
|
28
30
|
return (<div style={style.container}>
|
|
29
31
|
<Head>
|
|
30
32
|
<title>Page Error</title>
|
|
31
33
|
</Head>
|
|
32
34
|
|
|
33
35
|
<div style={style.error}>
|
|
34
|
-
|
|
36
|
+
{/* 500 will cause confusion for SPA application, so only show error code on SSR */}
|
|
37
|
+
{app.config.ssr && <div style={style.errorCode}>{errorCode}</div>}
|
|
35
38
|
<div style={style.errorDesc}>{errorDesc || 'Error'}</div>
|
|
36
39
|
</div>
|
|
37
40
|
</div>);
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import { LinkProps } from '@shuvi/router-react';
|
|
3
|
-
export declare const Link: ({
|
|
3
|
+
export declare const Link: ({ to, ref, prefetch, onMouseEnter, ...rest }: LinkWrapperProps) => JSX.Element;
|
|
4
4
|
interface LinkWrapperProps extends LinkProps {
|
|
5
|
+
prefetch?: boolean;
|
|
5
6
|
ref?: any;
|
|
6
7
|
}
|
|
7
8
|
export {};
|
|
@@ -71,7 +71,7 @@ const isAbsoluteUrl = (url) => {
|
|
|
71
71
|
return ABSOLUTE_URL_REGEX.test(url);
|
|
72
72
|
};
|
|
73
73
|
export const Link = function LinkWithPrefetch(_a) {
|
|
74
|
-
var {
|
|
74
|
+
var { to, ref, prefetch, onMouseEnter } = _a, rest = __rest(_a, ["to", "ref", "prefetch", "onMouseEnter"]);
|
|
75
75
|
const isHrefValid = typeof to === 'string' && !isAbsoluteUrl(to);
|
|
76
76
|
const previousHref = React.useRef(to);
|
|
77
77
|
const [setIntersectionRef, isVisible, resetVisible] = useIntersection({});
|
|
@@ -12,14 +12,14 @@ import { renderToString } from 'react-dom/server';
|
|
|
12
12
|
import { redirect } from '@shuvi/platform-shared/shared';
|
|
13
13
|
import { SHUVI_ERROR } from '@shuvi/shared/lib/constants';
|
|
14
14
|
import { Router } from '@shuvi/router-react';
|
|
15
|
-
import
|
|
15
|
+
import logger from '@shuvi/utils/lib/logger';
|
|
16
16
|
import Loadable, { LoadableContext } from '../loadable';
|
|
17
17
|
import AppContainer from '../AppContainer';
|
|
18
18
|
import { Head } from '../head';
|
|
19
19
|
import { serializeServerError } from '../../helper/serializeServerError';
|
|
20
20
|
export class ReactServerView {
|
|
21
21
|
constructor() {
|
|
22
|
-
this.renderApp = ({ req, app, manifest
|
|
22
|
+
this.renderApp = ({ req, app, manifest }) => __awaiter(this, void 0, void 0, function* () {
|
|
23
23
|
yield Loadable.preloadAll();
|
|
24
24
|
const { router, appComponent: AppComponent, setError: setAppError } = app;
|
|
25
25
|
yield router.ready;
|
|
@@ -46,10 +46,10 @@ export class ReactServerView {
|
|
|
46
46
|
htmlContent = renderToString(RootApp);
|
|
47
47
|
}
|
|
48
48
|
catch (error) {
|
|
49
|
-
if (
|
|
50
|
-
|
|
49
|
+
if (process.env.NODE_ENV === 'development') {
|
|
50
|
+
logger.error(error.stack);
|
|
51
51
|
}
|
|
52
|
-
setAppError(serializeServerError(error
|
|
52
|
+
setAppError(serializeServerError(error));
|
|
53
53
|
htmlContent = renderToString(RootApp); // Consistency on both server and client side
|
|
54
54
|
}
|
|
55
55
|
finally {
|
|
@@ -72,6 +72,18 @@ export class ReactServerView {
|
|
|
72
72
|
const preloadDynamicChunks = [];
|
|
73
73
|
const styles = [];
|
|
74
74
|
for (const file of dynamicImportChunkSet) {
|
|
75
|
+
// Safari Bug: https://bugs.webkit.org/show_bug.cgi?id=187726
|
|
76
|
+
// If a request is preloaded, Safari will always retrieve it from the
|
|
77
|
+
// cache, regardless of the cache headers for that request.
|
|
78
|
+
// disable preload for safari on dev
|
|
79
|
+
if (process.env.NODE_ENV === 'development') {
|
|
80
|
+
const ua = req.headers['user-agent'] || '';
|
|
81
|
+
if (/safari/i.test(ua) && !/chrome/i.test(ua)) {
|
|
82
|
+
if (/\.js$/.test(file)) {
|
|
83
|
+
continue;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
75
87
|
if (/\.js$/.test(file)) {
|
|
76
88
|
preloadDynamicChunks.push({
|
|
77
89
|
tagName: 'link',
|
|
@@ -8,21 +8,30 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
11
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
15
|
const service_1 = require("@shuvi/service");
|
|
13
|
-
const resources_1 = require("@shuvi/service/lib/resources");
|
|
16
|
+
const resources_1 = __importDefault(require("@shuvi/service/lib/resources"));
|
|
17
|
+
const logger_1 = __importDefault(require("@shuvi/utils/lib/logger"));
|
|
18
|
+
let isWarnedhandlePageRequest = false;
|
|
14
19
|
exports.default = (0, service_1.createServerPlugin)({
|
|
15
|
-
getPageData:
|
|
16
|
-
var _a, _b;
|
|
17
|
-
return ((_b = (_a = resources_1.server === null ||
|
|
20
|
+
getPageData: appContext => {
|
|
21
|
+
var _a, _b, _c;
|
|
22
|
+
return ((_c = (_b = (_a = resources_1.default.server) === null || _a === void 0 ? void 0 : _a.server) === null || _b === void 0 ? void 0 : _b.getPageData) === null || _c === void 0 ? void 0 : _c.call(_b, appContext)) || {};
|
|
18
23
|
},
|
|
19
|
-
handlePageRequest:
|
|
20
|
-
var _a, _b;
|
|
21
|
-
|
|
22
|
-
|
|
24
|
+
handlePageRequest: originalHandlePageRequest => {
|
|
25
|
+
var _a, _b, _c, _d, _e;
|
|
26
|
+
if (!isWarnedhandlePageRequest &&
|
|
27
|
+
((_b = (_a = resources_1.default.server) === null || _a === void 0 ? void 0 : _a.server) === null || _b === void 0 ? void 0 : _b.handlePageRequest) !== undefined) {
|
|
28
|
+
isWarnedhandlePageRequest = true;
|
|
29
|
+
logger_1.default.warn('Warning: handlePageRequest is an experimental feature, please use with caution.');
|
|
30
|
+
}
|
|
31
|
+
return (((_e = (_d = (_c = resources_1.default.server) === null || _c === void 0 ? void 0 : _c.server) === null || _d === void 0 ? void 0 : _d.handlePageRequest) === null || _e === void 0 ? void 0 : _e.call(_d, originalHandlePageRequest)) || originalHandlePageRequest);
|
|
23
32
|
},
|
|
24
|
-
modifyHtml: (document, context
|
|
25
|
-
var _a, _b;
|
|
26
|
-
yield ((_b = (_a = resources_1.server === null ||
|
|
33
|
+
modifyHtml: (document, context) => __awaiter(void 0, void 0, void 0, function* () {
|
|
34
|
+
var _a, _b, _c;
|
|
35
|
+
yield ((_c = (_b = (_a = resources_1.default.server) === null || _a === void 0 ? void 0 : _a.server) === null || _b === void 0 ? void 0 : _b.modifyHtml) === null || _c === void 0 ? void 0 : _c.call(_b, document, context));
|
|
27
36
|
})
|
|
28
37
|
});
|
|
@@ -31,6 +31,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
31
31
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
32
|
});
|
|
33
33
|
};
|
|
34
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
35
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
36
|
+
};
|
|
34
37
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
35
38
|
exports.ApiError = exports.sendJson = exports.sendData = exports.redirect = exports.sendStatusCode = exports.getCookieParser = exports.parseBody = exports.apiRouteHandler = void 0;
|
|
36
39
|
const stream_1 = require("stream");
|
|
@@ -38,6 +41,7 @@ const querystring = __importStar(require("querystring"));
|
|
|
38
41
|
const cookie = __importStar(require("cookie"));
|
|
39
42
|
const getRawBody = require('raw-body');
|
|
40
43
|
const contentType = __importStar(require("content-type"));
|
|
44
|
+
const logger_1 = __importDefault(require("@shuvi/utils/lib/logger"));
|
|
41
45
|
function apiRouteHandler(req, res, resolver, apiRoutesConfig) {
|
|
42
46
|
return __awaiter(this, void 0, void 0, function* () {
|
|
43
47
|
try {
|
|
@@ -66,7 +70,7 @@ function apiRouteHandler(req, res, resolver, apiRoutesConfig) {
|
|
|
66
70
|
if (process.env.NODE_ENV !== 'production' &&
|
|
67
71
|
!(res.finished || res.headersSent) &&
|
|
68
72
|
!wasPiped) {
|
|
69
|
-
|
|
73
|
+
logger_1.default.warn(`API resolved without sending a response for ${req.url}, this may result in stalled requests.`);
|
|
70
74
|
}
|
|
71
75
|
}
|
|
72
76
|
catch (err) {
|
|
@@ -8,15 +8,18 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
11
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
15
|
exports.middleware = void 0;
|
|
13
16
|
const router_1 = require("@shuvi/router");
|
|
14
|
-
const resources_1 = require("@shuvi/service/lib/resources");
|
|
17
|
+
const resources_1 = __importDefault(require("@shuvi/service/lib/resources"));
|
|
15
18
|
const apiRouteHandler_1 = require("./apiRouteHandler");
|
|
16
19
|
function middleware(_ctx) {
|
|
17
20
|
return function (req, res, next) {
|
|
18
21
|
return __awaiter(this, void 0, void 0, function* () {
|
|
19
|
-
const { apiRoutes } = resources_1.server;
|
|
22
|
+
const { apiRoutes } = resources_1.default.server;
|
|
20
23
|
let tempApiModule;
|
|
21
24
|
for (const { path, api } of apiRoutes) {
|
|
22
25
|
const match = (0, router_1.matchPathname)(path, req.pathname);
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
import { IPageRouteConfig, IMiddlewareRouteConfig } from '@shuvi/platform-shared/shared';
|
|
1
|
+
import { IPageRouteConfig, IMiddlewareRouteConfig, IApiRouteConfig } from '@shuvi/platform-shared/shared';
|
|
2
2
|
export declare const addRoutes: import("@shuvi/hook").AsyncParallelHook<void, void, IPageRouteConfig[]>;
|
|
3
3
|
export declare const addMiddlewareRoutes: import("@shuvi/hook").AsyncParallelHook<void, void, IMiddlewareRouteConfig[]>;
|
|
4
|
+
export declare const addApiRoutes: import("@shuvi/hook").AsyncParallelHook<void, void, IApiRouteConfig[]>;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.addMiddlewareRoutes = exports.addRoutes = void 0;
|
|
3
|
+
exports.addApiRoutes = exports.addMiddlewareRoutes = exports.addRoutes = void 0;
|
|
4
4
|
const hook_1 = require("@shuvi/hook");
|
|
5
5
|
exports.addRoutes = (0, hook_1.createAsyncParallelHook)();
|
|
6
6
|
exports.addMiddlewareRoutes = (0, hook_1.createAsyncParallelHook)();
|
|
7
|
+
exports.addApiRoutes = (0, hook_1.createAsyncParallelHook)();
|