Skip to content

Commit d5921b6

Browse files
author
Dennis Miasoutov
committed
Performance optimizations and debug.
1 parent 853a26d commit d5921b6

File tree

22 files changed

+253
-85
lines changed

22 files changed

+253
-85
lines changed

.vscode/launch.json

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
{
2+
// Use IntelliSense to learn about possible attributes.
3+
// Hover to view descriptions of existing attributes.
4+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5+
"version": "0.2.0",
6+
"configurations": [
7+
{
8+
"type": "node",
9+
"request": "launch",
10+
"name": "Debug: Basic Build",
11+
"cwd": "${workspaceRoot}",
12+
"runtimeArgs": ["-r", "ts-node/register"],
13+
"program": "${workspaceRoot}/src/cli/index.ts",
14+
"args": [
15+
"build",
16+
"./examples/basic"
17+
]
18+
},
19+
{
20+
"type": "node",
21+
"request": "launch",
22+
"name": "Debug: Basic Serve",
23+
"cwd": "${workspaceRoot}",
24+
"runtimeArgs": ["-r", "ts-node/register"],
25+
"program": "${workspaceRoot}/src/cli/index.ts",
26+
"args": [
27+
"serve",
28+
"./examples/basic"
29+
]
30+
} ,
31+
{
32+
"type": "node",
33+
"request": "launch",
34+
"name": "Debug: Async Redux Serve",
35+
"cwd": "${workspaceRoot}",
36+
"runtimeArgs": ["-r", "ts-node/register"],
37+
"program": "${workspaceRoot}/src/cli/index.ts",
38+
"args": [
39+
"serve",
40+
"./examples/router-redux-async"
41+
]
42+
}
43+
]
44+
}

app/client.tsx

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,3 @@ const context: Context = AppModule.createContext();
1010
const element = document.getElementById("app");
1111

1212
ReactDOM.hydrate(<AppModule.App context={context} />, element);
13-
14-
if (module.hot) {
15-
module.hot.accept(["injected-flavor-module"], () => {
16-
const newModule = require<typeof AppModule>("injected-flavor-module");
17-
ReactDOM.hydrate(<newModule.App context={context} />, element);
18-
});
19-
}

app/entry/index.dev.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// @ts-ignore
2+
import * as AppModule from "injected-app-module";
3+
import { hot } from "react-hot-loader/root";
4+
5+
export default hot(AppModule.App);

app/entry/index.prod.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// @ts-nocheck
2+
import * as AppModule from "injected-app-module";
3+
export default AppModule.App;

app/flavors/basic/app.tsx

Lines changed: 2 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -3,40 +3,13 @@ import { AppProps } from "../../common";
33
import { HelmetWrapper } from "../../components";
44

55
// @ts-ignore
6-
import * as AppModule from "injected-app-module";
7-
8-
interface AppState {
9-
injectedApp: React.ComponentType;
10-
}
6+
import InjectedApp from "injected-app-entry";
117

128
export class App extends React.Component<AppProps> {
13-
/**
14-
*
15-
*/
16-
// constructor(props: AppProps) {
17-
// super(props);
18-
19-
// this.state = {
20-
// injectedApp: AppModule.App,
21-
// };
22-
// }
23-
// public componentDidMount() {
24-
// if (module.hot) {
25-
// console.log("setting up");
26-
// console.log(module.hot.data);
27-
// module.hot.accept(["injected-app-module"], () => {
28-
// const newModule = require<typeof AppModule>("injected-app-module");
29-
// this.setState({ injectedApp: newModule.App });
30-
// console.log("fire");
31-
// });
32-
// module.hot.accept();
33-
// }
34-
// }
359
public render(): React.ReactNode {
36-
// const InjectedApp = this.state.injectedApp;
3710
return (
3811
<HelmetWrapper helmetContext={this.props.context.helmetContext}>
39-
<AppModule.App />
12+
<InjectedApp />
4013
</HelmetWrapper>
4114
);
4215
}

app/flavors/router-redux-async/render.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,16 @@ export function render(callback: RenderCallback, props: RenderFuncProps): void {
1818
context.helmetContext = {}; // init helmet for ssr
1919
const app = <App context={context} />;
2020
let firstError: any = null;
21+
const timeoutTimer = setTimeout(() => {
22+
callback(new Error("Cannot complete prerendering withing 5 second"));
23+
}, 5000);
2124
domainTaskRun(
2225
() => {
2326
domainTaskBaseUrl("http://localhost:5000");
2427
renderToString(app);
2528
},
2629
/* completion callback */ errorOrNothing => {
30+
clearTimeout(timeoutTimer);
2731
if (firstError) {
2832
return;
2933
}

app/flavors/router-redux/app.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@ import { AppProps } from "../../common";
55
import { HelmetWrapper } from "../../components";
66

77
// @ts-ignore
8-
import * as AppModule from "injected-app-module";
8+
import InjectedApp from "injected-app-entry";
99

1010
export class App extends React.Component<AppProps> {
1111
public render(): React.ReactNode {
1212
return (
1313
<HelmetWrapper helmetContext={this.props.context.helmetContext}>
1414
<Provider store={this.props.context.store}>
1515
<ConnectedRouter history={this.props.context.history}>
16-
<AppModule.App />
16+
<InjectedApp />
1717
</ConnectedRouter>
1818
</Provider>
1919
</HelmetWrapper>

app/server.tsx renamed to app/server.ts

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import * as React from "react";
2-
import * as ReactDom from "react-dom/server";
31
import * as Webpack from "webpack";
42
import {
53
RedirectResult,
@@ -15,6 +13,7 @@ interface ServerRenderStats {
1513

1614
function serverRenderer(stats: ServerRenderStats) {
1715
return (req: any, res: any, next: any) => {
16+
process.stdout.write(`Request ${req.url}\n`);
1817
if (req.url === "/") {
1918
const assets = res.locals.webpackStats.stats[0].toJson()
2019
.assetsByChunkName;
@@ -43,17 +42,4 @@ function serverRenderer(stats: ServerRenderStats) {
4342
};
4443
}
4544

46-
const renderError = (error: Error) => {
47-
return (
48-
<html>
49-
<head>
50-
<title>Error</title>
51-
</head>
52-
<body>
53-
<pre>{error.stack}</pre>
54-
</body>
55-
</html>
56-
);
57-
};
58-
5945
export default serverRenderer;

examples/basic/component.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import * as React from "react";
2+
3+
import img from "./image.png";
4+
5+
export class Component extends React.Component {
6+
public render(): React.ReactNode {
7+
return [
8+
<img key="image" src={img} alt="test-image" />,
9+
<span key="text">And happy new year!</span>,
10+
];
11+
}
12+
}

examples/basic/index.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
import * as React from "react";
22
import { Helmet } from "react-helmet-async";
3+
import { Component } from "./component";
34
import "./index.scss";
45

5-
import img from "./image.png";
6-
76
export class App extends React.Component {
87
public render(): JSX.Element {
98
return (
@@ -12,7 +11,7 @@ export class App extends React.Component {
1211
<title>Home Page</title>
1312
</Helmet>
1413
Hello World
15-
<img src={img} alt="test-image" />
14+
<Component />
1615
</div>
1716
);
1817
}

0 commit comments

Comments
 (0)