Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export function getPageHTML(nonce: string, state: Partial, scripts: Array): string {
const store = makeStore(state);
const { name } = store.getState();
// @ts-ignore
const { element, getStyleElement } = AppRegistry.getApplication('App', { initialProps: { store } });
const html = ReactDOMServer.renderToString(element);
const css = ReactDOMServer.renderToStaticMarkup(getStyleElement({ nonce }));
return `
<title>${name === 'Build Tracker' ? name : `${name} : Build Tracker`}</title>
<style nonce="${nonce}">html,body{height:100%;overflow-y:hidden;}#root{display:flex;height:100%;}</style>
${css}
<div id="root">${html}</div>
<div id="menuPortal"></div>
<div id="tooltipPortal"></div>
<div id="snackbarPortal"></div>
static async getInitialProps({ renderPage }) {
AppRegistry.registerComponent('Main', () => Main);
const { getStyleElement } = AppRegistry.getApplication('Main');
const page = renderPage();
const styles = [
<style>,
getStyleElement(),
];
return { ...page, styles };
}
</style>
App,
props,
res,
path,
docID,
clientAgent,
clientScriptID,
) {
res.set("content-type", "text/html");
// Horrible horrible horrible hacks to support react native web styles:
const appKey = `App-${docID}-${path}`;
const appKeys = AppRegistry.getAppKeys();
if (appKeys.indexOf(appKey) === -1) {
AppRegistry.registerComponent(appKey, () => App);
}
const { element, getStyleElement } = AppRegistry.getApplication(appKey, {
initialProps: props,
});
const appHtml = ReactDOMServer.renderToString(element);
const css = ReactDOMServer.renderToStaticMarkup(getStyleElement());
const title = App.title;
const html = `
<title>${title}</title>
${css}
async function htmlRender({page, initialProps, CONTAINER_ID}) {
/*
AppRegistry.registerComponent('App', () => page.view);
/*/
const viewElement = React.createElement(page.view, initialProps);
AppRegistry.registerComponent('App', () => () => viewElement);
//*/
const { element, getStyleElement } = AppRegistry.getApplication('App', { initialProps });
const viewHtml = ReactDOMServer.renderToStaticMarkup(element);
// Bug: `styleHtml` doesn't inlcude user defined styles
// Likely solution: make sure that all of react-native-web is compiled with webpack
const styleHtml = ReactDOMServer.renderToStaticMarkup(getStyleElement());
return {
head: [
styleHtml,
],
body: [
'<div id="'+CONTAINER_ID+'">'+viewHtml+'</div>',
]
};
}
static async getInitialProps(context: DocumentContext & PropContext) {
const locale = context.req.locale
const userAgent = context.req.headers['user-agent']
setDimensionsForScreen(userAgent)
AppRegistry.registerComponent('Main', () => Main)
// Use RTL layout for appropriate locales. Remember to do this client-side too.
I18nManager.setPreferredLanguageRTL(isLocaleRTL(locale))
// Get the html and styles needed to render this page.
const { getStyleElement } = AppRegistry.getApplication('Main')
const page = context.renderPage()
const styles = React.Children.toArray([
// <style>,
getStyleElement(),
])
if (context.err) {
Sentry.captureException(context.err)
}
return { ...page, locale, styles: React.Children.toArray(styles), pathname: context.pathname }
}
</style>
export function renderIndex({ scriptFilename }) {
AppRegistry.registerComponent('Main', () => Root);
const { getStyleElement } = AppRegistry.getApplication('Main');
const content = renderToStaticMarkup();
const style = renderToStaticMarkup(getStyleElement());
return `
<title>Jobs Done!</title>
static async getInitialProps({ renderPage }) {
AppRegistry.registerComponent("Main", () => Main);
const { getStyleElement } = AppRegistry.getApplication("Main");
const page = renderPage();
const styles = [
<style>,
getStyleElement()
];
return {
...page,
styles: React.Children.toArray(styles)
};
}
</style>