How to use the react-helmet.canUseDOM function in react-helmet

To help you get started, we’ve selected a few react-helmet examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Scrivito / scrivito_example_app_js / src / prerenderContent / prerenderObj.js View on Github external
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,
github blueberryapps / haystack / src / server / frontend / __tests__ / render.spec.js View on Github external
test('render', () => {
  global.webpackIsomorphicTools = { assets: () => ({ javascript: { app: 'app.xxx.js' } }) };
  Helmet.canUseDOM = false;
  expect(render(<div>)).toMatchSnapshot();
});
</div>
github mozilla / addons-frontend / tests / unit / core / server / test_base.js View on Github external
afterEach() {
    Helmet.canUseDOM = this.helmetCanUseDOM;
    NestedStatus.canUseDOM = this.nestedStatusCanUseDOM;
    global.document = this.document;
    delete global.webpackIsomorphicTools;
  }
github mozilla / addons-frontend / tests / unit / core / components / TestServerHtml.js View on Github external
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,
github mozilla / addons-frontend / tests / unit / core / server / test_base.js View on Github external
constructor() {
    this.helmetCanUseDOM = Helmet.canUseDOM;
    this.nestedStatusCanUseDOM = NestedStatus.canUseDOM;
    this.document = global.document;
  }
github oayres / react-ssr / config / jest.config.js View on Github external
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