Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it('does not views alive when using static + string rendering', function() {
useStaticRendering(true);
let renderCount = 0;
const data = mobx.observable({
z: 'hi'
});
const TestComponent = observer(function testComponent() {
renderCount++;
return <div>{data.z}</div>;
});
const output = renderToStaticMarkup();
data.z = 'hello';
expect(output).toBe('<div>hi</div>');
expect(renderCount).toBe(1);
expect(getDNode(data, 'z').observers.length).toBe(0);
useStaticRendering(false);
});
});
it(test.description, () => {
const container = document.createElement('div');
const vDom = test.template('foo');
const output = renderToStaticMarkup(vDom);
document.body.appendChild(container);
container.innerHTML = output;
expect(output).toBe(test.result);
document.body.removeChild(container);
});
});
it('stateless has context as 2nd argument', () => {
function TestChild(props, context) {
return <p>{context.testContext}</p>;
}
const output = renderToStaticMarkup(
);
expect(output).toBe('<p>context-works</p>');
});
it(test.description, () => {
const container = document.createElement('div');
const vDom = test.template('foo');
const output = renderToStaticMarkup(vDom);
document.body.appendChild(container);
container.innerHTML = output;
expect(output).toBe(test.result);
document.body.removeChild(container);
});
});
}
render() {
return (
<div>
{this.state.foo}
</div>
);
}
}
const container = document.createElement('div');
const vDom = ;
const output = renderToStaticMarkup(vDom);
document.body.appendChild(container);
container.innerHTML = output;
expect(output).toBe('<div>bar2<div>bar2</div></div>');
document.body.removeChild(container);
});
});
const renderProps = match(routes, ctx.url)
const bundleURL = config.server.DEV ? `//localhost:2002` : ''
if (renderProps.redirect) {
return ctx.redirect(renderProps.redirect)
}
if (config.server.SSR) {
try {
await onEnter(renderProps, ctx.context)
} catch(error) {
throw error
}
}
const components = config.server.SSR ? renderToStaticMarkup(
) : ''
ctx.body = indexHTML
.replace(/{bundleURL}/g, bundleURL)
.replace('{title}', ctx.context.state.common.title)
.replace('{state}', JSON.stringify(ctx.context.state, null, 2))
.replace('{children}', components)
}
app.get('*', (req, res) => {
/** Generate props for the mathing components in the router */
const props = matchPath(routes, req.url)
const App = createElement(StaticRouter, props)
const MatchURL = URLs.filter(item => item.url == req.url)[0]
/** Render to string the generated JSX tree */
const JSX = renderToStaticMarkup(App)
/** Extract html, css string, plus an ids array for hydratation */
const { css, html, ids } = SSR.extract(JSX)
const IDs = JSON.stringify(ids)
/** Render the page to the user based on the template */
res.send(
TEMPLATE
.replace(/\r?\n|\r/g, '')
.replace('{{TITLE}}', MatchURL ? MatchURL.title : 'Page Not Found')
.replace('{{CSS}}', css)
.replace('{{HTML}}', html)
.replace('{{IDS}}', IDs)
)
})
function render(pathname, Markup, App, props) {
const styletron = new StyletronServer();
const appContent = InfernoServer.renderToString(createElement(App, {pathname, styletron}));
const styletronSheets = styletron.getStylesheets();
const markupProps = Object.assign({}, props, {appContent, styletronSheets});
return '' + InfernoServer.renderToStaticMarkup(createElement(Markup, markupProps));
}
async function app(ctx, next) {
const root = InfernoServer.renderToString();
ctx.body = InfernoServer.renderToStaticMarkup();
ctx.status = 200;
}