How to use the rax-server-renderer.renderToString function in rax-server-renderer

To help you get started, we’ve selected a few rax-server-renderer 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 alibaba / rax / packages / rax-plugin-app / src / plugins / UniversalDocumentPlugin.js View on Github external
Object.keys(entryObj).forEach(entry => {
        // get document html string
        const pageSource = '' + renderToString(createElement(documentElement, {
          publicPath,
          styles: [],
          scripts: [`web/${entry}.js`]
        }));

        // insert html file
        compilation.assets[`web/${entry}.html`] = new RawSource(pageSource);
      });
github alibaba / rax / packages / rax-pwa-webpack-plugin / src / DocumentHandler.js View on Github external
if (skeletonTemplate) {
        _htmlValue = _htmlValue.replace(
          '',
          ``
        );
      }

      const jsTagStr = _htmlAssets.js.map(src => ``).join('') || '';
      const cssTagStr = _htmlAssets.css.map(src => ``).join('') || '';
      _htmlValue = _htmlValue
        .replace('', `${cssTagStr}`)
        .replace('', `${jsTagStr}`);
    } else {
      // Use document.js
      _htmlPath = this.documentJsFilePath;
      _htmlValue = renderer.renderToString(
        createElement(interopRequire(eval(fs.readFileSync(this.tempHtmlFilePath, 'utf-8'))), {
          scripts: _htmlAssets.js,
          styles: _htmlAssets.css,
          title: title,
          pageData: JSON.stringify({}),
          pageHtml: appShellTemplate
        })
      );
      if (skeletonTemplate) {
        _htmlValue = _htmlValue.replace(
          '${skeletonTemplate}
github alibaba / rax / packages / rax-ssr-webpack-plugin / src / ClientPlugin.js View on Github external
webpack(getShellConfig(pathConfig)).run((err) => {
        if (err) {
          console.error(err);
          return false;
        }
        const shellJsPath = path.resolve(pathConfig.appBuild, './shells.js');
        const component = require(shellJsPath).default;

        this.AppShellTemplate = renderer.renderToString(createElement(component, {}, createElement('div', { id: 'root-page' })));
        fs.unlinkSync(shellJsPath);
        callback();
      });
    });
github alibaba / rax / packages / rax-server / index.js View on Github external
let pageData;
  let pageHtml;

  if (shell && shell.component) {
    const result = await renderShell({
      ctx,
      shell,
      component,
      renderOpts
    });
    pageData = result.data;
    pageHtml = result.html;
  } else {
    pageData = await getInitialProps(component, ctx);
    const pageElement = createElement(component, pageData);
    pageHtml = renderer.renderToString(pageElement, renderOpts);
  }

  const documentComponent = document.component || Document;
  const pageTitle = title || document.title;
  const documentData = await getInitialProps(documentComponent, ctx);
  const documentElement = createElement(documentComponent, {
    title: pageTitle,
    pageHtml,
    pageData: JSON.stringify(pageData),
    styles,
    scripts,
    ...documentData
  });

  const html = '' + renderer.renderToString(documentElement, renderOpts);
github alibaba / beidou / packages / beidou-view-rax / app / view-middlewares / rax-render.js View on Github external
module.exports = async function (viewCtx, next) {
  const { Component, props } = viewCtx;

  const instance = Rax.createElement(Component, props);
  viewCtx.html += RaxServer.renderToString(instance);
  await next();
};
github raxjs / server-side-rendering-comparison / benchmarks / renderToString.js View on Github external
.add(`Rax(${raxPkg.version})#renderToString`, function() {
    raxRenderToString(Rax.createElement(RaxApp, data));
  })
  .add(`Inferno(${infernoPkg.version})#renderToString`, function() {
github alibaba / rax / packages / rax-server / index.js View on Github external
shell,
    component,
    renderOpts
  } = options;

  const shellComponent = shell.component;
  const data = await getInitialProps(shellComponent, {
    ...ctx,
    Component: component
  });

  const shellElement = createElement(shellComponent, {
    ...data,
    Component: component
  });
  const html = renderer.renderToString(shellElement, renderOpts);

  return {
    data,
    html
  };
}
github Financial-Times / x-dash / private / ssr-benchmark / controllers / rax / index.js View on Github external
module.exports = (req, res) => {
    res.type('text/html').code(200);

    res.send(
        renderToString(render())
    );
};
github alibaba / rax / packages / rax-server / index.js View on Github external
pageHtml = renderer.renderToString(pageElement, renderOpts);
  }

  const documentComponent = document.component || Document;
  const pageTitle = title || document.title;
  const documentData = await getInitialProps(documentComponent, ctx);
  const documentElement = createElement(documentComponent, {
    title: pageTitle,
    pageHtml,
    pageData: JSON.stringify(pageData),
    styles,
    scripts,
    ...documentData
  });

  const html = '' + renderer.renderToString(documentElement, renderOpts);

  return html;
}
github i-like-robots / hyperons / benchmark / engines / rax.js View on Github external
module.exports = () => renderToString(factory(createElement))

rax-server-renderer

Rax renderer for server-side render.

BSD-3-Clause
Latest version published 4 years ago

Package Health Score

57 / 100
Full package analysis

Popular rax-server-renderer functions

Similar packages