Home / Function/ module() — react Function Reference

module() — react Function Reference

Architecture documentation for the module() function in render-to-buffer.js from the react codebase.

Entity Profile

Dependency Diagram

graph TD
  ffd46ff3_9446_d873_25d1_fe2cd9a5ca55["module()"]
  fbe0797f_1878_6a2d_3c20_5ad62120856d["render-to-buffer.js"]
  ffd46ff3_9446_d873_25d1_fe2cd9a5ca55 -->|defined in| fbe0797f_1878_6a2d_3c20_5ad62120856d
  a89e80c5_179f_e2d0_ab23_d6b3e6fdbcd2["HtmlWritable()"]
  ffd46ff3_9446_d873_25d1_fe2cd9a5ca55 -->|calls| a89e80c5_179f_e2d0_ab23_d6b3e6fdbcd2
  7c369bcf_87f9_fa27_60a1_878256a3ae1a["getHtml()"]
  ffd46ff3_9446_d873_25d1_fe2cd9a5ca55 -->|calls| 7c369bcf_87f9_fa27_60a1_878256a3ae1a
  style ffd46ff3_9446_d873_25d1_fe2cd9a5ca55 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

fixtures/fizz/server/render-to-buffer.js lines 40–83

module.exports = function render(url, res) {
  let writable = new HtmlWritable();
  res.socket.on('error', error => {
    console.error('Fatal', error);
  });
  let didError = false;
  let didFinish = false;

  writable.on('finish', () => {
    // If something errored before we started streaming, we set the error code appropriately.
    res.statusCode = didError ? 500 : 200;
    res.setHeader('Content-type', 'text/html');
    res.send(writable.getHtml());
  });

  const {pipe, abort} = renderToPipeableStream(<App assets={assets} />, {
    bootstrapScripts: [assets['main.js']],
    onAllReady() {
      // Full completion.
      // You can use this for SSG or crawlers.
      didFinish = true;
    },
    onShellReady() {
      // If something errored before we started streaming, we set the error code appropriately.
      pipe(writable);
    },
    onShellError(x) {
      // Something errored before we could complete the shell so we emit an alternative shell.
      res.statusCode = 500;
      res.send('<!doctype><p>Error</p>');
    },
    onError(x) {
      didError = true;
      console.error(x);
    },
  });
  // Abandon and switch to client rendering if enough time passes.
  // Try lowering this to see the client recover.
  setTimeout(() => {
    if (!didFinish) {
      abort();
    }
  }, ABORT_DELAY);
};

Domain

Subdomains

Frequently Asked Questions

What does module() do?
module() is a function in the react codebase, defined in fixtures/fizz/server/render-to-buffer.js.
Where is module() defined?
module() is defined in fixtures/fizz/server/render-to-buffer.js at line 40.
What does module() call?
module() calls 2 function(s): HtmlWritable, getHtml.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free