Home / Function/ module() — react Function Reference

module() — react Function Reference

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

Entity Profile

Dependency Diagram

graph TD
  0afb0ee6_050f_913b_ead2_4bd3afb465e5["module()"]
  d469dba5_b6ac_21d6_fd11_39f7311bf17b["render-to-stream.js"]
  0afb0ee6_050f_913b_ead2_4bd3afb465e5 -->|defined in| d469dba5_b6ac_21d6_fd11_39f7311bf17b
  style 0afb0ee6_050f_913b_ead2_4bd3afb465e5 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

fixtures/fizz/server/render-to-stream.js lines 20–57

module.exports = function render(url, res) {
  // The new wiring is a bit more involved.
  res.socket.on('error', error => {
    console.error('Fatal', error);
  });
  let didError = false;
  let didFinish = false;
  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.
      res.statusCode = didError ? 500 : 200;
      res.setHeader('Content-type', 'text/html');
      setImmediate(() => pipe(res));
    },
    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-stream.js.
Where is module() defined?
module() is defined in fixtures/fizz/server/render-to-stream.js at line 20.

Analyze Your Own Codebase

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

Try Supermodel Free