<commit_before>require("@babel/polyfill");
require("./mdx-override"); // convert mdx to jsx on import()
const babelConfig = require("./babel.config");
require("@babel/register")({
  extensions: [".js", ".jsx", ".tsx", ".ts"],
  ...babelConfig
});
require("ignore-styles"); // ignore css/scss imports on server side.
const ISDEV = process.env.NODE_ENV !== "production";
const debug = require("debug")("react");
const fs = require("fs");
const path = require("path");
const React = require("react");
const { renderToString } = require("react-dom/server");

// we use client's helmet instance to avoid two Helmet instances to be loaded.
// see: https://github.com/nfl/react-helmet/issues/125
// and https://stackoverflow.com/questions/45822925/react-helmet-outputting-empty-strings-on-server-side
const { Helmet } = require(require("path").join(
  process.env.BUILDPATH,
  "/node_modules/react-helmet"
));

const jsonStringify = require("json-stringify-safe");
// const bundle = require('./bundle')
// var bundleInfo = false
var ssrCrashWarned = false;

async function generateComponent(
  req,
  res,
  componentPath,
  bundlePath,
  basePath,
  bundleInfo
) {
  // invalidate node module's cache in dev mode
  // TODO: invalidate nested requires too.
  // TODO: only invalidate if file has changed and not on each refresh
  if (ISDEV) {
    delete require.cache[require.resolve(componentPath)];
    //console.log("CACHE", require.cache)
    //delete require.cache
  }

  try {
    var App = require(componentPath);
  } catch (e) {
    console.log(e);
  }

  App = App && App.default ? App.default : App; // cater export default class...
  if (!App) {
    // component failed to load or was not exported.

    if (bundleInfo && bundleInfo.js) {
      // atleast we have a bundle. Disable SSR for this endpoint.
      if (!ssrCrashWarned)
        console.warn(
          `\n\n⚠️ SSR didn't work for ${basePath}. Some component might not be SSR compatible.`
        );
      ssrCrashWarned = true;
      var markup = `<!DOCTYPE html>
        <html>
          <head>
            <meta charset="utf-8"/>
            ${
              bundleInfo.css
                ? `<link rel="stylesheet" href="/${bundleInfo.css}">`<commit_msg>show ssr error only once<commit_after>require("@babel/polyfill");
require("./mdx-override"); // convert mdx to jsx on import()
const babelConfig = require("./babel.config");
require("@babel/register")({
  extensions: [".js", ".jsx", ".tsx", ".ts"],
  ...babelConfig
});
require("ignore-styles"); // ignore css/scss imports on server side.
const ISDEV = process.env.NODE_ENV !== "production";
const debug = require("debug")("react");
const fs = require("fs");
const path = require("path");
const React = require("react");
const { renderToString } = require("react-dom/server");

// we use client's helmet instance to avoid two Helmet instances to be loaded.
// see: https://github.com/nfl/react-helmet/issues/125
// and https://stackoverflow.com/questions/45822925/react-helmet-outputting-empty-strings-on-server-side
const { Helmet } = require(require("path").join(
  process.env.BUILDPATH,
  "/node_modules/react-helmet"
));

const jsonStringify = require("json-stringify-safe");
// const bundle = require('./bundle')
// var bundleInfo = false
var ssrCrashWarned = false;

async function generateComponent(
  req,
  res,
  componentPath,
  bundlePath,
  basePath,
  bundleInfo
) {
  // invalidate node module's cache in dev mode
  // TODO: invalidate nested requires too.
  // TODO: only invalidate if file has changed and not on each refresh
  if (ISDEV) {
    delete require.cache[require.resolve(componentPath)];
    //console.log("CACHE", require.cache)
    //delete require.cache
  }

  try {
    var App = require(componentPath);
  } catch (e) {
    if (!ssrCrashWarned) console.log(e);
  }

  App = App && App.default ? App.default : App; // cater export default class...
  if (!App) {
    // component failed to load or was not exported.

    if (bundleInfo && bundleInfo.js) {
      // atleast we have a bundle. Disable SSR for this endpoint.
      if (!ssrCrashWarned)
        console.warn(
          `\n\n⚠️ SSR didn't work for ${basePath}. Some component might not be SSR compatible.`
        );
      ssrCrashWarned = true;
      var markup = `<!DOCTYPE html>
        <html>
          <head>
            <meta charset="utf-8"/>
            ${
              bundleInfo.css
                ? `<link rel="stylesheet" href="/${bundleInfo.css}">`
{'fraction_non_alphanumeric': 0.1511835640911121, 'fraction_numerical': 0.005359535506922733, 'mean_word_length': 3.075523202911738, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1355265', 'n_tokens_mistral': 1401, 'n_tokens_neox': 1361, 'n_words': 381}