-
-
Notifications
You must be signed in to change notification settings - Fork 32.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[core] Add a real life benchmark (#13244)
- Loading branch information
1 parent
611c6c1
commit 24a9be1
Showing
3 changed files
with
96 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* eslint-disable no-console */ | ||
|
||
import express from 'express'; | ||
import React from 'react'; | ||
import ReactDOMServer from 'react-dom/server'; | ||
import { SheetsRegistry } from 'react-jss/lib/jss'; | ||
import JssProvider from 'react-jss/lib/JssProvider'; | ||
import { | ||
MuiThemeProvider, | ||
createMuiTheme, | ||
createGenerateClassName, | ||
} from '@material-ui/core/styles'; | ||
import green from '@material-ui/core/colors/green'; | ||
import red from '@material-ui/core/colors/red'; | ||
import Pricing from 'docs/src/pages/page-layout-examples/pricing/Pricing'; | ||
|
||
function renderFullPage(html, css) { | ||
return ` | ||
<!doctype html> | ||
<html> | ||
<head> | ||
<title>Material-UI</title> | ||
</head> | ||
<body> | ||
<div id="root">${html}</div> | ||
<style id="jss-server-side">${css}</style> | ||
</body> | ||
</html> | ||
`; | ||
} | ||
|
||
const sheetsCache = new Map(); | ||
|
||
const theme = createMuiTheme({ | ||
palette: { | ||
primary: green, | ||
accent: red, | ||
type: 'light', | ||
}, | ||
typography: { | ||
useNextVariants: true, | ||
}, | ||
}); | ||
|
||
function handleRender(req, res) { | ||
const sheetsRegistry = new SheetsRegistry(); | ||
const generateClassName = createGenerateClassName(); | ||
const html = ReactDOMServer.renderToString( | ||
<JssProvider registry={sheetsRegistry} generateClassName={generateClassName}> | ||
<MuiThemeProvider theme={theme} sheetsManager={new Map()} sheetsCache={sheetsCache}> | ||
<Pricing /> | ||
</MuiThemeProvider> | ||
</JssProvider>, | ||
); | ||
const css = sheetsRegistry.toString(); | ||
res.send(renderFullPage(html, css)); | ||
} | ||
|
||
const app = express(); | ||
app.use(handleRender); | ||
|
||
const port = 3001; | ||
app.listen(port, () => { | ||
console.log(`listening on port ${port}`); | ||
}); |