Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export default async function prerenderObj(obj) {
// Tell helmet to pretend to run on a node server, not in a browser
// See https://github.com/nfl/react-helmet/issues/310 for details
Helmet.canUseDOM = false;
const { result, preloadDump } = await Scrivito.renderPage(obj, () => {
const bodyContent = ReactDOMServer.renderToString();
const helmet = Helmet.renderStatic();
return {
objId: obj.id(),
objUrl: Scrivito.urlFor(obj),
htmlAttributes: helmet.htmlAttributes.toString(),
headContent: `
${helmet.title.toString()}
${helmet.meta.toString()}
${helmet.link.toString()}
`,
bodyAttributes: helmet.bodyAttributes.toString(),
bodyContent,
test('render', () => {
global.webpackIsomorphicTools = { assets: () => ({ javascript: { app: 'app.xxx.js' } }) };
Helmet.canUseDOM = false;
expect(render(<div>)).toMatchSnapshot();
});
</div>
afterEach() {
Helmet.canUseDOM = this.helmetCanUseDOM;
NestedStatus.canUseDOM = this.nestedStatusCanUseDOM;
global.document = this.document;
delete global.webpackIsomorphicTools;
}
describe(__filename, () => {
const _helmetCanUseDOM = Helmet.canUseDOM;
beforeEach(() => {
Helmet.canUseDOM = false;
});
afterEach(() => {
Helmet.canUseDOM = _helmetCanUseDOM;
});
const createFakeChunkExtractor = (props = {}) => {
return {
getLinkElements: sinon.stub(),
getMainAssets: sinon.stub().returns([]),
getPreAssets: sinon.stub().returns([]),
getRequiredChunksScriptElement: sinon.stub(),
...props,
constructor() {
this.helmetCanUseDOM = Helmet.canUseDOM;
this.nestedStatusCanUseDOM = NestedStatus.canUseDOM;
this.document = global.document;
}
afterEach(() => {
Helmet.canUseDOM = _helmetCanUseDOM;
});
import React from 'react'
import Enzyme from 'enzyme'
import Adapter from 'enzyme-adapter-react-16'
import toJson from 'enzyme-to-json'
import Helmet from 'react-helmet'
Enzyme.configure({ adapter: new Adapter() })
global.React = React
global.mount = Enzyme.mount
global.shallow = Enzyme.shallow
global.render = Enzyme.render
global.snapshot = toJson
Helmet.canUseDOM = false