Repository: expo/expo
File: docs/next.config.ts (TypeScript)

Code before:
            remarkPlugins: [
              remarkMDX,
              remarkGFM,
              [remarkMdxDisableExplicitJsx, { whiteList: ['kbd'] }],
              remarkFrontmatter,
              [remarkMDXFrontmatter, { name: 'meta' }],
              remarkCodeTitle,
              remarkExportHeadings,
              remarkLinkRewrite,
              remarkSDKCompatibility,
              [remarkCreateStaticProps, `{ meta: meta || {}, headings: headings || [] }`],
            ],
            rehypePlugins: [rehypeSlug],
          },
        },
      ],
    });

    // Fix inline or browser MDX usage
    config.resolve.fallback = { fs: false, path: 'path-browserify' };
    // Replace next/link with a shim that renders consistent href values between
    // SSR and client hydration (avoids trailingSlash normalization mismatch).
    config.resolve.alias = {
      ...(config.resolve.alias ?? {}),
      'next/link$': join(__dirname, 'common/next-link.cjs'),
    };

    config.output.environment = { ...config.output.environment, asyncFunction: true };
    config.experiments = { ...config.experiments, topLevelAwait: true };

    return config;
  },

  // Create a map of all pages to export
  // https://nextjs.org/docs/pages/api-reference/config/next-config-js/exportPathMap
  async exportPathMap(defaultPathMap, { dev, outDir }) {
    if (dev) {
      return defaultPathMap;
    }

    if (!outDir) {
      error('Output directory is not defined! Falling back to the default export map.');
      return defaultPathMap;
    }

    const pathMap = Object.assign(
      {},
      ...Object.entries(defaultPathMap).map(([pathname, page]) => {
        if (pathname.includes('unversioned')) {
          // Remove unversioned pages from the exported site
          return undefined;

Review comment (suggestion):
Is there another option, other than replacing `next/link` globally? This seems quite fragile, and we'd need to maintain it going forward.

Code after:
            remarkPlugins: [
              remarkMDX,
              remarkGFM,
              [remarkMdxDisableExplicitJsx, { whiteList: ['kbd'] }],
              remarkFrontmatter,
              [remarkMDXFrontmatter, { name: 'meta' }],
              remarkCodeTitle,
              remarkExportHeadings,
              remarkLinkRewrite,
              remarkSDKCompatibility,
              [remarkCreateStaticProps, `{ meta: meta || {}, headings: headings || [] }`],
            ],
            rehypePlugins: [rehypeSlug],
          },
        },
      ],
    });

    // Fix inline or browser MDX usage
    config.resolve.fallback = { fs: false, path: 'path-browserify' };

    config.output.environment = { ...config.output.environment, asyncFunction: true };
    config.experiments = { ...config.experiments, topLevelAwait: true };

    return config;
  },

  // Create a map of all pages to export
  // https://nextjs.org/docs/pages/api-reference/config/next-config-js/exportPathMap
  async exportPathMap(defaultPathMap, { dev, outDir }) {
    if (dev) {
      return defaultPathMap;
    }

    if (!outDir) {
      error('Output directory is not defined! Falling back to the default export map.');
      return defaultPathMap;
    }

    const pathMap = Object.assign(
      {},
      ...Object.entries(defaultPathMap).map(([pathname, page]) => {
        if (pathname.includes('unversioned')) {
          // Remove unversioned pages from the exported site
          return undefined;
        } else {
          // Remove newer unreleased versions from the exported side
          const versionMatch = pathname.match(/\/v(\d\d\.\d\.\d)\//);
          if (versionMatch?.[1] && semver.gt(versionMatch[1], newestVersion, false)) {
            return undefined;
          }