Repository: remix-run/react-router
File: packages/react-router-dev/vite/plugin.ts (TypeScript)

Code before:
              es6: true,
            })};`;
          }
          case VirtualModule.resolve(browserManifestId): {
            if (viteCommand === "build") {
              throw new Error("This module only exists in development");
            }

            let reactRouterManifest = await getReactRouterManifestForDev();
            let reactRouterManifestString = jsesc(reactRouterManifest, {
              es6: true,
            });

            return `window.__remixManifest=${reactRouterManifestString};`;
          }
        }
      },
    },
    {
      name: "react-router-define-route",
      enforce: "pre",
      async transform(code, id, options) {
        if (id.endsWith(BUILD_CLIENT_ROUTE_QUERY_STRING)) return;
        if (!code.includes("defineRoute")) return; // temporary back compat

        if (options?.ssr) return; // TODO: why is `ctx` undefined otherwise?
        let route = getRoute(ctx.reactRouterConfig, id);
        if (!route) return defineRoute.assertNotImported(code);

        defineRoute.transform(code);
      },
    },
    {
      name: "react-router-dot-server",
      enforce: "pre",
      async resolveId(id, importer, options) {
        if (options?.ssr) return;

        let isResolving = options?.custom?.["react-router-dot-server"] ?? false;
        if (isResolving) return;
        options.custom = { ...options.custom, "react-router-dot-server": true };
        let resolved = await this.resolve(id, importer, options);
        if (!resolved) return;

        let serverFileRE = /\.server(\.[cm]?[jt]sx?)?$/;
        let serverDirRE = /\/\.server\//;
        let isDotServer =
          serverFileRE.test(resolved!.id) || serverDirRE.test(resolved!.id);
        if (!isDotServer) return;

        if (!importer) return;

Review comment (suggestion):
@markdalgleish I guess we never ran into this before just out of luck, but seems like `ctx` is `undefined` when `ssr` is set to `true` which causes a bunch of issues. Seems surprising to me, so might be missing something

not a blocker here since we only need to check these things once during client build

Code after:
              es6: true,
            })};`;
          }
          case VirtualModule.resolve(browserManifestId): {
            if (viteCommand === "build") {
              throw new Error("This module only exists in development");
            }

            let reactRouterManifest = await getReactRouterManifestForDev();
            let reactRouterManifestString = jsesc(reactRouterManifest, {
              es6: true,
            });

            return `window.__remixManifest=${reactRouterManifestString};`;
          }
        }
      },
    },
    {
      name: "react-router-define-route",
      enforce: "pre",
      async transform(code, id, options) {
        if (options?.ssr) return;

        if (id.endsWith(BUILD_CLIENT_ROUTE_QUERY_STRING)) return;

        let route = getRoute(ctx.reactRouterConfig, id);
        if (!route && code.includes("defineRoute")) {
          return defineRoute.assertNotImported(code);
        }

        if (!code.includes("defineRoute")) return; // temporary back compat, remove once old style routes are unsupported
        defineRoute.transform(code);
      },
    },
    {
      name: "react-router-dot-server",
      enforce: "pre",
      async resolveId(id, importer, options) {
        if (options?.ssr) return;

        let isResolving = options?.custom?.["react-router-dot-server"] ?? false;
        if (isResolving) return;
        options.custom = { ...options.custom, "react-router-dot-server": true };
        let resolved = await this.resolve(id, importer, options);
        if (!resolved) return;

        let serverFileRE = /\.server(\.[cm]?[jt]sx?)?$/;
        let serverDirRE = /\/\.server\//;
        let isDotServer =
          serverFileRE.test(resolved!.id) || serverDirRE.test(resolved!.id);