Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
constructor() {
// Create a sheetsRegistry instance.
this.sheetsRegistry = new SheetsRegistry();
// Create a theme instance.
this.theme = createMuiTheme({
palette: {
primary: green,
accent: red,
type: 'light'
}
});
this.generateClassName = createGenerateClassName();
this.grabCss = this.grabCss.bind(this);
}
export function renderOnServer(componant, theme, req, context, store) {
// Create a sheetsRegistry instance.
const sheetsRegistry = new SheetsRegistry();
const generateClassName = createGenerateClassName();
const html = renderToString(
{componant}
);
const css = sheetsRegistry.toString();
function render(req: $Subtype<$Request>, res: $Response) {
const history = createHistory({initialEntries: [req.path]})
const initialPath = history.location.pathname
const store = createStore(history)
const jss = createJss(jssPreset())
const sheetsRegistry = new SheetsRegistry()
const matchedRoute = flattenedRoutes.find(route => matchPath(req.url, routeProps(route)))
const promises = []
if (matchedRoute && matchedRoute.loadData) {
promises.push(...matchedRoute.loadData.map(loadData => loadData(store.dispatch, req, res)))
}
return Promise.all(promises).then(() => {
// Server's node instance can't reload files (HMR is for serving files to the client) so SSR is disabled during development to avoid getting out of sync.
const html = renderToString(
// You can access redux through react-redux connect
store,
storeSubscription: null,
// Apollo Client for use with react-apollo
client: apolloClient,
};
const route = await router.resolve(context);
if (route.redirect) {
res.redirect(route.status || 302, route.redirect);
return;
}
const data = { ...route };
const sheetsRegistry = new SheetsRegistry();
const sheetsManager = new Map();
const generateClassName = createGenerateClassName();
const rootComponent = (
{route.component}
);
await getDataFromTree(rootComponent);
renderToHtml: (render, Comp, meta) => {
// Create a sheetsRegistry instance.
const sheetsRegistry = new SheetsRegistry()
// Create a MUI theme instance.
const muiTheme = createMuiTheme(theme)
const generateClassName = createGenerateClassName()
const html = render(
)
meta.jssStyles = sheetsRegistry.toString()
router.get('*', isAuthenticated, (req, res) => {
const sheetsRegistry = new SheetsRegistry();
// Set initial state of store
let initialState = InitialState;
initialState.memberState.displayName = req.user.displayName;
const store = configureStore(InitialState);
// Component
const component = (req, store, i18n) => {
return (
);
};
const cssGenerator = () => {
const renderPage = (ctx: Object, pageData?: Object = {}) => {
const sheetsRegistry = new SheetsRegistry()
const generateClassName = createGenerateClassName()
const store = createStore(() => ({ page: pageData, general: getGeneralData(ctx) }))
const routerContext = {}
const appHtml = ReactDOMServer.renderToString(
,
)
if (routerContext.action === 'REPLACE') {
ctx.redirect(routerContext.url)
function wrapWithMuiTheme (app, { req, res, store, apolloClient }) {
const sheetsRegistry = new SheetsRegistry();
req.sheetsRegistry = sheetsRegistry;
const sheetsManager = new Map();
const theme = getCurrentTheme();
const generateClassName = createGenerateClassName({ seed: '0' });
return (
{app}