rari 0.2.0 → 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,2 @@
1
+ import { ErrorBoundaryProps, FileRouteInfo, HttpRuntimeClient, LayoutProps, Link, LinkProps, LoadingProps, Navigate, NavigationOptions, NavigationState, Outlet, PageComponent, PageProps, Route, RouteComponent, RouteGenerationOptions, RouteMatch, RouteMeta, RouteParams, RouterConfig, RouterContext, RouterProvider, RouterProviderProps, Routes, RuntimeClient, SearchParams, buildSearchString, buildUrl, createHttpRuntimeClient, extractParamNames, findMatchingRoute, isDynamicRoute, isPathActive, joinPaths, normalizePathname, parseSearchParams, parseUrl, useNavigation, useParams, usePathname, useRoute, useRouter, useSearchParams, withRouter } from "./runtime-client-P4vvSVPV.js";
2
+ export { type ErrorBoundaryProps, type FileRouteInfo, HttpRuntimeClient, type LayoutProps, Link, type LinkProps, type LoadingProps, Navigate, type NavigationOptions, type NavigationState, Outlet, type PageComponent, type PageProps, RouteComponent as Route, type RouteGenerationOptions, type RouteMatch, type RouteMeta, type RouteParams, type Route as RouteType, type RouterConfig, type RouterContext, RouterProvider, type RouterProviderProps, Routes, type RuntimeClient, type SearchParams, buildSearchString, buildUrl, createHttpRuntimeClient, extractParamNames, findMatchingRoute, isDynamicRoute, isPathActive, joinPaths, normalizePathname, parseSearchParams, parseUrl, useNavigation, useParams, usePathname, useRoute, useRouter, useSearchParams, withRouter };
@@ -0,0 +1,3 @@
1
+ import { HttpRuntimeClient, Link, Navigate, Outlet, RouteComponent, Routes, buildSearchString, buildUrl, createHttpRuntimeClient, extractParamNames, findMatchingRoute, isDynamicRoute, isPathActive, joinPaths, normalizePathname, parseSearchParams, parseUrl, router_default, useNavigation, useParams, usePathname, useRoute, useRouter, useSearchParams, withRouter } from "./runtime-client-CcEhh-F7.js";
2
+
3
+ export { HttpRuntimeClient, Link, Navigate, Outlet, RouteComponent as Route, router_default as RouterProvider, Routes, buildSearchString, buildUrl, createHttpRuntimeClient, extractParamNames, findMatchingRoute, isDynamicRoute, isPathActive, joinPaths, normalizePathname, parseSearchParams, parseUrl, useNavigation, useParams, usePathname, useRoute, useRouter, useSearchParams, withRouter };
package/dist/client.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- import { ErrorBoundaryProps, FileRouteInfo, HttpRuntimeClient, LayoutProps, Link, LinkProps, LoadingProps, Navigate, NavigationOptions, NavigationState, Outlet, PageComponent, PageProps, Route, RouteComponent, RouteGenerationOptions, RouteMatch, RouteMeta, RouteParams, RouterConfig, RouterContext, RouterProvider, RouterProviderProps, Routes, RuntimeClient, SearchParams, buildSearchString, buildUrl, createHttpRuntimeClient, extractParamNames, findMatchingRoute, isDynamicRoute, isPathActive, joinPaths, normalizePathname, parseSearchParams, parseUrl, useNavigation, useParams, usePathname, useRoute, useRouter, useSearchParams, withRouter } from "./runtime-client-BEWMJWMx.js";
1
+ import { ErrorBoundaryProps, FileRouteInfo, HttpRuntimeClient, LayoutProps, Link, LinkProps, LoadingProps, Navigate, NavigationOptions, NavigationState, Outlet, PageComponent, PageProps, Route, RouteComponent, RouteGenerationOptions, RouteMatch, RouteMeta, RouteParams, RouterConfig, RouterContext, RouterProvider, RouterProviderProps, Routes, RuntimeClient, SearchParams, buildSearchString, buildUrl, createHttpRuntimeClient, extractParamNames, findMatchingRoute, isDynamicRoute, isPathActive, joinPaths, normalizePathname, parseSearchParams, parseUrl, useNavigation, useParams, usePathname, useRoute, useRouter, useSearchParams, withRouter } from "./runtime-client-P4vvSVPV.js";
2
2
  export { type ErrorBoundaryProps, type FileRouteInfo, HttpRuntimeClient, type LayoutProps, Link, type LinkProps, type LoadingProps, Navigate, type NavigationOptions, type NavigationState, Outlet, type PageComponent, type PageProps, RouteComponent as Route, type RouteGenerationOptions, type RouteMatch, type RouteMeta, type RouteParams, type Route as RouteType, type RouterConfig, type RouterContext, RouterProvider, type RouterProviderProps, Routes, type RuntimeClient, type SearchParams, buildSearchString, buildUrl, createHttpRuntimeClient, extractParamNames, findMatchingRoute, isDynamicRoute, isPathActive, joinPaths, normalizePathname, parseSearchParams, parseUrl, useNavigation, useParams, usePathname, useRoute, useRouter, useSearchParams, withRouter };
package/dist/client.js CHANGED
@@ -1,3 +1,3 @@
1
- import { HttpRuntimeClient, Link, Navigate, Outlet, RouteComponent, Routes, buildSearchString, buildUrl, createHttpRuntimeClient, extractParamNames, findMatchingRoute, isDynamicRoute, isPathActive, joinPaths, normalizePathname, parseSearchParams, parseUrl, router_default, useNavigation, useParams, usePathname, useRoute, useRouter, useSearchParams, withRouter } from "./runtime-client-CC4YQweh.js";
1
+ import { HttpRuntimeClient, Link, Navigate, Outlet, RouteComponent, Routes, buildSearchString, buildUrl, createHttpRuntimeClient, extractParamNames, findMatchingRoute, isDynamicRoute, isPathActive, joinPaths, normalizePathname, parseSearchParams, parseUrl, router_default, useNavigation, useParams, usePathname, useRoute, useRouter, useSearchParams, withRouter } from "./runtime-client-CcEhh-F7.js";
2
2
 
3
3
  export { HttpRuntimeClient, Link, Navigate, Outlet, RouteComponent as Route, router_default as RouterProvider, Routes, buildSearchString, buildUrl, createHttpRuntimeClient, extractParamNames, findMatchingRoute, isDynamicRoute, isPathActive, joinPaths, normalizePathname, parseSearchParams, parseUrl, useNavigation, useParams, usePathname, useRoute, useRouter, useSearchParams, withRouter };
package/dist/index.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- import { ErrorBoundaryProps, FileRouteInfo, HttpRuntimeClient, LayoutProps, Link, LinkProps, LoadingProps, Navigate, NavigationOptions, NavigationState, Outlet, PageComponent, PageProps, Route, RouteComponent, RouteGenerationOptions, RouteMatch, RouteMeta, RouteParams, RouterConfig, RouterContext, RouterProvider, RouterProviderProps, Routes, RuntimeClient, SearchParams, buildSearchString, buildUrl, createHttpRuntimeClient, extractParamNames, findMatchingRoute, getRoutePriority, isDynamicRoute, isPathActive, joinPaths, normalizePathname, parseSearchParams, parseUrl, useNavigation, useParams, usePathname, useRoute, useRouter, useSearchParams, withRouter } from "./runtime-client-BEWMJWMx.js";
2
- import { FileRouteGenerator, convertFilePatternToRoutePattern, createRouteManifest, defineRariConfig, generateFileRoutes, loadRouteManifest, rari, rariRouter, validateRoutes, watchFileRoutes } from "./server-MY0-nRif.js";
3
- export { ErrorBoundaryProps, FileRouteGenerator, FileRouteInfo, HttpRuntimeClient, LayoutProps, Link, LinkProps, LoadingProps, Navigate, NavigationOptions, NavigationState, Outlet, PageComponent, PageProps, RouteComponent as Route, RouteGenerationOptions, RouteMatch, RouteMeta, RouteParams, Route as RouteType, RouterConfig, RouterContext, RouterProvider, RouterProviderProps, Routes, RuntimeClient, SearchParams, buildSearchString, buildUrl, convertFilePatternToRoutePattern, createHttpRuntimeClient, createRouteManifest, defineRariConfig, extractParamNames, findMatchingRoute, generateFileRoutes, getRoutePriority, isDynamicRoute, isPathActive, joinPaths, loadRouteManifest, normalizePathname, parseSearchParams, parseUrl, rari, rariRouter, useNavigation, useParams, usePathname, useRoute, useRouter, useSearchParams, validateRoutes, watchFileRoutes, withRouter };
1
+ import { ErrorBoundaryProps, FileRouteInfo, HttpRuntimeClient, LayoutProps, Link, LinkProps, LoadingProps, Navigate, NavigationOptions, NavigationState, Outlet, PageComponent, PageProps, Route, RouteComponent, RouteGenerationOptions, RouteMatch, RouteMeta, RouteParams, RouterConfig, RouterContext, RouterProvider, RouterProviderProps, Routes, RuntimeClient, SearchParams, buildSearchString, buildUrl, createHttpRuntimeClient, extractParamNames, findMatchingRoute, getRoutePriority, isDynamicRoute, isPathActive, joinPaths, normalizePathname, parseSearchParams, parseUrl, useNavigation, useParams, usePathname, useRoute, useRouter, useSearchParams, withRouter } from "./runtime-client-P4vvSVPV.js";
2
+ import { FileRouteGenerator, convertFilePatternToRoutePattern, createReactDOMOptimization, createRouteManifest, defineRariConfig, generateFileRoutes, loadRouteManifest, rari, rariRouter, validateRoutes, watchFileRoutes } from "./server-Do9Jt8NN.js";
3
+ export { ErrorBoundaryProps, FileRouteGenerator, FileRouteInfo, HttpRuntimeClient, LayoutProps, Link, LinkProps, LoadingProps, Navigate, NavigationOptions, NavigationState, Outlet, PageComponent, PageProps, RouteComponent as Route, RouteGenerationOptions, RouteMatch, RouteMeta, RouteParams, Route as RouteType, RouterConfig, RouterContext, RouterProvider, RouterProviderProps, Routes, RuntimeClient, SearchParams, buildSearchString, buildUrl, convertFilePatternToRoutePattern, createHttpRuntimeClient, createReactDOMOptimization, createRouteManifest, defineRariConfig, extractParamNames, findMatchingRoute, generateFileRoutes, getRoutePriority, isDynamicRoute, isPathActive, joinPaths, loadRouteManifest, normalizePathname, parseSearchParams, parseUrl, rari, rariRouter, useNavigation, useParams, usePathname, useRoute, useRouter, useSearchParams, validateRoutes, watchFileRoutes, withRouter };
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
- import { HttpRuntimeClient, Link, Navigate, Outlet, RouteComponent, Routes, buildSearchString, buildUrl, createHttpRuntimeClient, extractParamNames, findMatchingRoute, getRoutePriority, isDynamicRoute, isPathActive, joinPaths, normalizePathname, parseSearchParams, parseUrl, router_default, useNavigation, useParams, usePathname, useRoute, useRouter, useSearchParams, withRouter } from "./runtime-client-CC4YQweh.js";
2
- import { FileRouteGenerator, convertFilePatternToRoutePattern, createRouteManifest, defineRariConfig, generateFileRoutes, loadRouteManifest, rari, rariRouter, validateRoutes, watchFileRoutes } from "./server-CpI87WFQ.js";
1
+ import { HttpRuntimeClient, Link, Navigate, Outlet, RouteComponent, Routes, buildSearchString, buildUrl, createHttpRuntimeClient, extractParamNames, findMatchingRoute, getRoutePriority, isDynamicRoute, isPathActive, joinPaths, normalizePathname, parseSearchParams, parseUrl, router_default, useNavigation, useParams, usePathname, useRoute, useRouter, useSearchParams, withRouter } from "./runtime-client-CcEhh-F7.js";
2
+ import { FileRouteGenerator, convertFilePatternToRoutePattern, createReactDOMOptimization, createRouteManifest, defineRariConfig, generateFileRoutes, loadRouteManifest, rari, rariRouter, validateRoutes, watchFileRoutes } from "./server-CYRJ1imY.js";
3
3
  import "./server-build-DaBgiV55.js";
4
4
 
5
- export { FileRouteGenerator, HttpRuntimeClient, Link, Navigate, Outlet, RouteComponent as Route, router_default as RouterProvider, Routes, buildSearchString, buildUrl, convertFilePatternToRoutePattern, createHttpRuntimeClient, createRouteManifest, defineRariConfig, extractParamNames, findMatchingRoute, generateFileRoutes, getRoutePriority, isDynamicRoute, isPathActive, joinPaths, loadRouteManifest, normalizePathname, parseSearchParams, parseUrl, rari, rariRouter, useNavigation, useParams, usePathname, useRoute, useRouter, useSearchParams, validateRoutes, watchFileRoutes, withRouter };
5
+ export { FileRouteGenerator, HttpRuntimeClient, Link, Navigate, Outlet, RouteComponent as Route, router_default as RouterProvider, Routes, buildSearchString, buildUrl, convertFilePatternToRoutePattern, createHttpRuntimeClient, createReactDOMOptimization, createRouteManifest, defineRariConfig, extractParamNames, findMatchingRoute, generateFileRoutes, getRoutePriority, isDynamicRoute, isPathActive, joinPaths, loadRouteManifest, normalizePathname, parseSearchParams, parseUrl, rari, rariRouter, useNavigation, useParams, usePathname, useRoute, useRouter, useSearchParams, validateRoutes, watchFileRoutes, withRouter };
@@ -228,8 +228,7 @@ function RouterProvider({ config = DEFAULT_CONFIG, routes = DEFAULT_ROUTES, chil
228
228
  caseSensitive: false,
229
229
  ...config
230
230
  }), [config]);
231
- const [currentRoute, setCurrentRoute] = useState(null);
232
- const updateCurrentRoute = useCallback((url) => {
231
+ const resolveRoute = useCallback((url) => {
233
232
  const { pathname, search, hash, searchParams } = parseUrl(url);
234
233
  const normalizedPathname = normalizePathname(pathname);
235
234
  const match = findMatchingRoute(normalizedPathname, routes);
@@ -241,15 +240,43 @@ function RouterProvider({ config = DEFAULT_CONFIG, routes = DEFAULT_ROUTES, chil
241
240
  hash
242
241
  };
243
242
  enhancedMatch.childMatch = findDeepestChildMatch(enhancedMatch, normalizedPathname);
244
- setCurrentRoute(enhancedMatch);
245
- } else setCurrentRoute(null);
243
+ return enhancedMatch;
244
+ }
245
+ return null;
246
246
  }, [routes]);
247
+ const [routerState, setRouterState] = useState(() => {
248
+ if (typeof window === "undefined") return {
249
+ currentRoute: null,
250
+ isReady: false
251
+ };
252
+ const url = mergedConfig.useHash ? window.location.hash.slice(1) || "/" : window.location.pathname + window.location.search + window.location.hash;
253
+ let initialRoute;
254
+ try {
255
+ initialRoute = resolveRoute(url);
256
+ } catch (error) {
257
+ console.error("Error resolving initial route:", error);
258
+ initialRoute = null;
259
+ }
260
+ const isReady$1 = true;
261
+ return {
262
+ currentRoute: initialRoute,
263
+ isReady: isReady$1
264
+ };
265
+ });
266
+ const currentRoute = routerState.currentRoute;
267
+ const isReady = routerState.isReady;
268
+ const updateCurrentRoute = useCallback((url) => {
269
+ const route = resolveRoute(url);
270
+ setRouterState({
271
+ currentRoute: route,
272
+ isReady: true
273
+ });
274
+ }, [resolveRoute]);
247
275
  useEffect(() => {
248
276
  const handleLocationChange = () => {
249
277
  const url = mergedConfig.useHash ? window.location.hash.slice(1) || "/" : window.location.pathname + window.location.search + window.location.hash;
250
278
  updateCurrentRoute(url);
251
279
  };
252
- handleLocationChange();
253
280
  const handlePopState = () => {
254
281
  handleLocationChange();
255
282
  };
@@ -299,16 +326,19 @@ function RouterProvider({ config = DEFAULT_CONFIG, routes = DEFAULT_ROUTES, chil
299
326
  if (!currentRoute) return false;
300
327
  return isPathActive(currentRoute.pathname, path, exact);
301
328
  }, [currentRoute]);
302
- const contextValue = useMemo(() => ({
303
- currentRoute,
304
- routes,
305
- navigate,
306
- back,
307
- forward,
308
- replace,
309
- isActive,
310
- config: mergedConfig
311
- }), [
329
+ const contextValue = useMemo(() => {
330
+ return {
331
+ currentRoute,
332
+ routes,
333
+ navigate,
334
+ back,
335
+ forward,
336
+ replace,
337
+ isActive,
338
+ config: mergedConfig,
339
+ isReady
340
+ };
341
+ }, [
312
342
  currentRoute,
313
343
  routes,
314
344
  navigate,
@@ -316,7 +346,8 @@ function RouterProvider({ config = DEFAULT_CONFIG, routes = DEFAULT_ROUTES, chil
316
346
  forward,
317
347
  replace,
318
348
  isActive,
319
- mergedConfig
349
+ mergedConfig,
350
+ isReady
320
351
  ]);
321
352
  return /* @__PURE__ */ jsx(RouterContext, {
322
353
  value: contextValue,
@@ -356,8 +387,7 @@ function useParams() {
356
387
  return currentRoute?.params || {};
357
388
  }
358
389
  function useSearchParams() {
359
- const { currentRoute } = useRouter();
360
- const { navigate } = useRouter();
390
+ const { currentRoute, navigate } = useRouter();
361
391
  const searchParams = currentRoute?.searchParams || {};
362
392
  const setSearchParams = useCallback((params, options = DEFAULT_CONFIG) => {
363
393
  const newParams = typeof params === "function" ? params(searchParams) : params;
@@ -72,6 +72,7 @@ interface RouterContext {
72
72
  replace: (path: string, options?: Omit<NavigationOptions, 'replace'>) => void;
73
73
  isActive: (path: string, exact?: boolean) => boolean;
74
74
  config: RouterConfig;
75
+ isReady: boolean;
75
76
  }
76
77
  interface NavigationState {
77
78
  isNavigating: boolean;
@@ -1,11 +1,12 @@
1
1
  import { __commonJS, __require, __toESM } from "./chunk-BLXvPPr8.js";
2
- import { analyzeFilePath } from "./runtime-client-CC4YQweh.js";
2
+ import { analyzeFilePath } from "./runtime-client-CcEhh-F7.js";
3
3
  import { createServerBuildPlugin } from "./server-build-DaBgiV55.js";
4
4
  import fs, { promises } from "node:fs";
5
5
  import path from "node:path";
6
6
  import process$1 from "node:process";
7
7
  import { spawn } from "node:child_process";
8
8
  import * as acorn from "acorn";
9
+ import { minify } from "rollup-plugin-esbuild";
9
10
 
10
11
  //#region ../../node_modules/.pnpm/picomatch@2.3.1/node_modules/picomatch/lib/constants.js
11
12
  var require_constants$2 = __commonJS({ "../../node_modules/.pnpm/picomatch@2.3.1/node_modules/picomatch/lib/constants.js"(exports, module) {
@@ -5742,7 +5743,6 @@ function rari(options = {}) {
5742
5743
  }
5743
5744
  newCode += `
5744
5745
 
5745
- // HMR acceptance for server components
5746
5746
  if (import.meta.hot) {
5747
5747
  import.meta.hot.accept(() => {
5748
5748
  // Server component updated, no need to reload
@@ -5832,6 +5832,14 @@ if (import.meta.hot) {
5832
5832
  const existingDedupe = Array.isArray(config.resolve.dedupe) ? config.resolve.dedupe : [];
5833
5833
  const toAdd = ["react", "react-dom"];
5834
5834
  config.resolve.dedupe = Array.from(new Set([...existingDedupe || [], ...toAdd]));
5835
+ const existingResolveAlias = config.resolve.alias || {};
5836
+ config.resolve.alias = {
5837
+ ...existingResolveAlias,
5838
+ "react-dom/server": "react-dom/server.browser",
5839
+ "react-dom$": "react-dom/client",
5840
+ "react-dom/cjs/react-dom.production.min.js": "react-dom/client",
5841
+ "react-dom/cjs/react-dom.development.js": "react-dom/client"
5842
+ };
5835
5843
  const existingAlias = Array.isArray(config.resolve.alias) ? config.resolve.alias : [];
5836
5844
  const aliasFinds = new Set(existingAlias.map((a) => String(a.find)));
5837
5845
  try {
@@ -5880,13 +5888,17 @@ if (import.meta.hot) {
5880
5888
  config.optimizeDeps = config.optimizeDeps || {};
5881
5889
  config.optimizeDeps.include = config.optimizeDeps.include || [];
5882
5890
  if (!config.optimizeDeps.include.includes("react-dom/server")) config.optimizeDeps.include.push("react-dom/server");
5891
+ if (!config.optimizeDeps.include.includes("react")) config.optimizeDeps.include.push("react");
5892
+ if (!config.optimizeDeps.include.includes("react-dom/client")) config.optimizeDeps.include.push("react-dom/client");
5893
+ config.optimizeDeps.exclude = config.optimizeDeps.exclude || [];
5894
+ if (!config.optimizeDeps.exclude.includes("virtual:rsc-integration")) config.optimizeDeps.exclude.push("virtual:rsc-integration");
5883
5895
  if (command === "build") for (const envName of [
5884
5896
  "rsc",
5885
5897
  "ssr",
5886
5898
  "client"
5887
5899
  ]) {
5888
5900
  const env = config.environments[envName];
5889
- if (env && env.build) env.build.rollupOptions = env.build.rollupOptions || {};
5901
+ if (env && env.build) env.build.rolldownOptions = env.build.rolldownOptions || {};
5890
5902
  }
5891
5903
  config.server = config.server || {};
5892
5904
  config.server.proxy = config.server.proxy || {};
@@ -5912,19 +5924,193 @@ if (import.meta.hot) {
5912
5924
  };
5913
5925
  if (command === "build") {
5914
5926
  config.build = config.build || {};
5915
- config.build.rollupOptions = config.build.rollupOptions || {};
5916
- if (!config.build.rollupOptions.input) config.build.rollupOptions.input = { main: "./index.html" };
5927
+ config.build.rolldownOptions = config.build.rolldownOptions || {};
5928
+ config.build.rolldownOptions.plugins = config.build.rolldownOptions.plugins || [];
5929
+ if (Array.isArray(config.build.rolldownOptions.plugins)) {
5930
+ config.build.rolldownOptions.plugins.push(minify());
5931
+ config.build.rolldownOptions.plugins.push({
5932
+ name: "html-css-optimizer",
5933
+ generateBundle(options$1, bundle) {
5934
+ Object.keys(bundle).forEach((fileName) => {
5935
+ const file = bundle[fileName];
5936
+ if (file.type === "asset" && fileName.endsWith(".html")) {
5937
+ let html = file.source;
5938
+ html = html.replace(/<link\s+rel="stylesheet"\s+crossorigin\s+href="([^"]+\.css)"\s*>/g, (match, href) => {
5939
+ return `<link rel="preload" as="style" crossorigin href="${href}" fetchpriority="high" onload="this.onload=null;this.rel='stylesheet'">
5940
+ <noscript><link rel="stylesheet" crossorigin href="${href}"></noscript>`;
5941
+ });
5942
+ const scriptMatch = html.match(/<script\s+type="module"\s+crossorigin\s+src="([^"]+)"\s*><\/script>/);
5943
+ if (scriptMatch) {
5944
+ const mainJsHref = scriptMatch[1];
5945
+ html = html.replace(scriptMatch[0], `<link rel="preload" as="script" crossorigin href="${mainJsHref}" fetchpriority="high">
5946
+ <script type="module" crossorigin src="${mainJsHref}" fetchpriority="high"><\/script>`);
5947
+ }
5948
+ const preconnectDomains = options$1.preconnectDomains || [];
5949
+ if (preconnectDomains.length > 0) {
5950
+ const preconnectHints = preconnectDomains.map((domain) => ` <link rel="dns-prefetch" href="//${domain}">`).join("\n");
5951
+ html = html.replace("</head>", ` <!-- Performance optimizations -->
5952
+ ${preconnectHints}
5953
+ </head>`);
5954
+ }
5955
+ file.source = html;
5956
+ }
5957
+ });
5958
+ }
5959
+ });
5960
+ }
5961
+ if (!config.build.rolldownOptions.input) config.build.rolldownOptions.input = { main: "./index.html" };
5962
+ config.build.rolldownOptions.output = config.build.rolldownOptions.output || {};
5963
+ const outputConfig = Array.isArray(config.build.rolldownOptions.output) ? config.build.rolldownOptions.output[0] || {} : config.build.rolldownOptions.output;
5964
+ outputConfig.assetFileNames = (assetInfo) => {
5965
+ if (assetInfo.name?.endsWith(".css")) return "assets/[name]-[hash][extname]";
5966
+ return "assets/[name]-[hash][extname]";
5967
+ };
5968
+ outputConfig.manualChunks = (id) => {
5969
+ if (id.includes("node_modules/react-dom") || id.includes("react-dom/client") || id.includes("react-dom/server") || id.includes("react-dom/")) return "react-dom";
5970
+ if ((id.includes("node_modules/react") || id.includes("react/")) && !id.includes("react-dom")) return "react";
5971
+ if (id.includes("scheduler") && id.includes("node_modules")) return "scheduler";
5972
+ if (id.includes("markdown-it") || id.includes("shiki")) return "vendor";
5973
+ if (id.includes("node_modules")) return "vendor";
5974
+ };
5975
+ config.build.rolldownOptions.treeshake = config.build.rolldownOptions.treeshake || {
5976
+ moduleSideEffects: (id) => {
5977
+ if (id.includes(".css") || id.includes("polyfill")) return true;
5978
+ if (id.includes("react-dom") || id.includes("react") || id.includes("scheduler") || id.includes("react-dom/client") || id.includes("react-dom/server")) return false;
5979
+ return false;
5980
+ },
5981
+ unknownGlobalSideEffects: false
5982
+ };
5983
+ const existingExternal = config.build.rolldownOptions?.external || [];
5984
+ const reactDomExternals = [
5985
+ "react-dom/profiling",
5986
+ "react-dom/test-utils",
5987
+ "react-dom/server",
5988
+ "react-dom/server.browser",
5989
+ "react-dom/server.node",
5990
+ "react/jsx-dev-runtime",
5991
+ "scheduler/tracing",
5992
+ "scheduler/unstable_mock",
5993
+ "react/cjs/react.development.js",
5994
+ "react/cjs/react.production.min.js",
5995
+ "react-dom/cjs/react-dom.development.js",
5996
+ "react-dom/cjs/react-dom.production.min.js",
5997
+ "react-dom/src/client/ReactDOMRoot.js",
5998
+ "react-dom/src/events/plugins",
5999
+ "react-dom/src/shared/HTMLDOMPropertyConfig.js",
6000
+ "react-dom/src/shared/DOMPropertyOperations.js"
6001
+ ];
6002
+ if (Array.isArray(existingExternal)) {
6003
+ const external = [...existingExternal];
6004
+ external.push(...reactDomExternals.filter((dep) => !external.includes(dep)));
6005
+ config.build.rolldownOptions.external = external;
6006
+ } else if (typeof existingExternal === "function") {
6007
+ const originalExternal = existingExternal;
6008
+ config.build.rolldownOptions.external = (id, parentId, isResolved) => {
6009
+ if (reactDomExternals.includes(id)) return true;
6010
+ return originalExternal(id, parentId, isResolved);
6011
+ };
6012
+ } else config.build.rolldownOptions.external = [...Array.isArray(existingExternal) ? existingExternal : [existingExternal], ...reactDomExternals].filter(Boolean);
6013
+ config.build.minify = true;
6014
+ config.build.target = config.build.target || [
6015
+ "es2020",
6016
+ "edge88",
6017
+ "firefox78",
6018
+ "chrome87",
6019
+ "safari14"
6020
+ ];
6021
+ config.build.cssMinify = config.build.cssMinify !== false ? "esbuild" : false;
6022
+ config.build.cssCodeSplit = true;
6023
+ config.build.assetsInlineLimit = 4096;
6024
+ config.build.chunkSizeWarningLimit = 1e3;
6025
+ config.build.sourcemap = config.build.sourcemap !== void 0 ? config.build.sourcemap : true;
6026
+ config.build.terserOptions = config.build.terserOptions || {
6027
+ compress: {
6028
+ drop_console: true,
6029
+ drop_debugger: true,
6030
+ pure_funcs: [
6031
+ "console.log",
6032
+ "console.info",
6033
+ "console.debug",
6034
+ "console.warn",
6035
+ "invariant",
6036
+ "warning",
6037
+ "__DEV__",
6038
+ "ReactDOM.render",
6039
+ "ReactDOM.unmountComponentAtNode",
6040
+ "ReactDOM.findDOMNode",
6041
+ "ReactDOM.createPortal"
6042
+ ],
6043
+ passes: 3,
6044
+ unsafe: true,
6045
+ unsafe_comps: true,
6046
+ unsafe_Function: true,
6047
+ unsafe_math: true,
6048
+ unsafe_symbols: true,
6049
+ unsafe_methods: true,
6050
+ unsafe_proto: true,
6051
+ unsafe_regexp: true,
6052
+ unsafe_undefined: true,
6053
+ dead_code: true,
6054
+ side_effects: false
6055
+ },
6056
+ mangle: {
6057
+ safari10: true,
6058
+ properties: { regex: /^_/ }
6059
+ },
6060
+ format: { comments: false }
6061
+ };
6062
+ outputConfig.format = outputConfig.format || "es";
6063
+ outputConfig.minify = true;
6064
+ if (Array.isArray(config.build.rolldownOptions.output)) config.build.rolldownOptions.output[0] = outputConfig;
6065
+ else config.build.rolldownOptions.output = outputConfig;
5917
6066
  }
5918
6067
  if (config.environments && config.environments.client) {
5919
6068
  if (!config.environments.client.build) config.environments.client.build = {};
5920
- if (!config.environments.client.build.rollupOptions) config.environments.client.build.rollupOptions = {};
5921
- if (!config.environments.client.build.rollupOptions.input) config.environments.client.build.rollupOptions.input = {};
5922
- if (typeof config.environments.client.build.rollupOptions.input === "object" && !Array.isArray(config.environments.client.build.rollupOptions.input)) config.environments.client.build.rollupOptions.input["client-components"] = "virtual:rsc-client-components";
6069
+ if (!config.environments.client.build.rolldownOptions) config.environments.client.build.rolldownOptions = {};
6070
+ if (!config.environments.client.build.rolldownOptions.input) config.environments.client.build.rolldownOptions.input = {};
6071
+ if (typeof config.environments.client.build.rolldownOptions.input === "object" && !Array.isArray(config.environments.client.build.rolldownOptions.input)) config.environments.client.build.rolldownOptions.input["client-components"] = "virtual:rsc-client-components";
6072
+ config.environments.client.build.rolldownOptions.plugins = config.environments.client.build.rolldownOptions.plugins || [];
6073
+ if (Array.isArray(config.environments.client.build.rolldownOptions.plugins)) config.environments.client.build.rolldownOptions.plugins.push(minify());
6074
+ config.environments.client.build.minify = true;
6075
+ config.environments.client.build.target = config.environments.client.build.target || [
6076
+ "es2020",
6077
+ "edge88",
6078
+ "firefox78",
6079
+ "chrome87",
6080
+ "safari14"
6081
+ ];
6082
+ config.environments.client.build.cssMinify = "esbuild";
6083
+ config.environments.client.build.cssCodeSplit = true;
6084
+ config.environments.client.build.assetsInlineLimit = 4096;
6085
+ config.environments.client.build.rolldownOptions.treeshake = {
6086
+ moduleSideEffects: false,
6087
+ unknownGlobalSideEffects: false
6088
+ };
6089
+ config.environments.client.build.rolldownOptions.output = config.environments.client.build.rolldownOptions.output || {};
6090
+ const clientOutputConfig = Array.isArray(config.environments.client.build.rolldownOptions.output) ? config.environments.client.build.rolldownOptions.output[0] || {} : config.environments.client.build.rolldownOptions.output;
6091
+ clientOutputConfig.manualChunks = (id) => {
6092
+ if (id.includes("node_modules/react-dom") || id.includes("react-dom/client") || id.includes("react-dom/server") || id.includes("react-dom/")) return "react-dom";
6093
+ if ((id.includes("node_modules/react") || id.includes("react/")) && !id.includes("react-dom")) return "react";
6094
+ if (id.includes("scheduler") && id.includes("node_modules")) return "scheduler";
6095
+ if (id.includes("rari") && (id.includes("router") || id.includes("navigation"))) return "router";
6096
+ if (id.includes("markdown-it") || id.includes("shiki")) return "vendor";
6097
+ if (id.includes("node_modules")) return "vendor";
6098
+ };
6099
+ clientOutputConfig.format = clientOutputConfig.format || "es";
6100
+ clientOutputConfig.minify = true;
6101
+ if (Array.isArray(config.environments.client.build.rolldownOptions.output)) config.environments.client.build.rolldownOptions.output[0] = clientOutputConfig;
6102
+ else config.environments.client.build.rolldownOptions.output = clientOutputConfig;
5923
6103
  }
5924
6104
  return config;
5925
6105
  },
5926
6106
  transform(code, id) {
5927
6107
  if (!/\.(?:tsx?|jsx?)$/.test(id)) return null;
6108
+ if (code.includes("react-dom")) {
6109
+ code = code.replace(/import\s+ReactDOM\s+from\s+['"]react-dom\/client['"];?/g, "import { createRoot, hydrateRoot } from 'react-dom/client';");
6110
+ code = code.replace(/import\s+ReactDOM\s+from\s+['"]react-dom['"];?/g, "import { createRoot, hydrateRoot } from 'react-dom/client';");
6111
+ code = code.replace(/ReactDOM\.createRoot/g, "createRoot");
6112
+ code = code.replace(/ReactDOM\.hydrateRoot/g, "hydrateRoot");
6113
+ }
5928
6114
  const environment = this.environment;
5929
6115
  if (hasTopLevelDirective(code, "use client")) {
5930
6116
  componentTypeCache.set(id, "client");
@@ -6374,7 +6560,6 @@ export const __CLIENT_REFERENCE_REGISTRY__ = clientReferenceRegistry;
6374
6560
  export const __SERVER_REFERENCE_REGISTRY__ = serverReferenceRegistry;
6375
6561
  export const __CLIENT_COMPONENT_REGISTRY__ = clientComponentRegistry;
6376
6562
 
6377
- // Module map for React Server Components
6378
6563
  export function createClientModuleMap() {
6379
6564
  const moduleMap = {};
6380
6565
 
@@ -6397,7 +6582,6 @@ export function createClientModuleMap() {
6397
6582
  if (id === "virtual:rsc-integration") return `
6398
6583
  import React, { useState, useEffect, Suspense } from 'react';
6399
6584
 
6400
- // Client component registration for RSC system compatibility
6401
6585
  if (typeof globalThis.__clientComponents === 'undefined') {
6402
6586
  globalThis.__clientComponents = {};
6403
6587
  }
@@ -6415,7 +6599,6 @@ export function registerClientComponent(componentFunction, id, exportName) {
6415
6599
 
6416
6600
  const componentId = componentName;
6417
6601
 
6418
- // Register in global registry for RSC traversal
6419
6602
  globalThis.__clientComponents[componentId] = {
6420
6603
  id: componentId,
6421
6604
  path: id,
@@ -6511,11 +6694,9 @@ async function loadRscClient() {
6511
6694
  createFromReadableStream = rscModule.createFromReadableStream;
6512
6695
 
6513
6696
  if (typeof createFromReadableStream !== 'function') {
6514
- console.warn('createFromReadableStream is not available in react-dom/client');
6515
6697
  createFromReadableStream = null;
6516
6698
  }
6517
6699
  if (typeof createFromFetch !== 'function') {
6518
- console.warn('createFromFetch is not available in react-dom/client');
6519
6700
  createFromFetch = null;
6520
6701
  }
6521
6702
 
@@ -6609,11 +6790,13 @@ class RscClient {
6609
6790
  await loadRscClient();
6610
6791
 
6611
6792
  const endpoints = (() => {
6612
- const list = [
6613
- 'http://127.0.0.1:3000/api/rsc/stream',
6614
- 'http://localhost:3000/api/rsc/stream',
6615
- '/api/rsc/stream',
6616
- ];
6793
+ const list = ['/api/rsc/stream'];
6794
+ try {
6795
+ const isLocalHost = typeof window !== 'undefined' && (window.location.hostname === 'localhost' || window.location.hostname === '127.0.0.1');
6796
+ if (isLocalHost) {
6797
+ list.push('http://127.0.0.1:3000/api/rsc/stream', 'http://localhost:3000/api/rsc/stream');
6798
+ }
6799
+ } catch {}
6617
6800
  return list;
6618
6801
  })();
6619
6802
  let response = null;
@@ -7176,7 +7359,7 @@ class RscClient {
7176
7359
  const processedChildren = value.map((child, index) => {
7177
7360
  const result = this.reconstructElementFromRscData(child, modules);
7178
7361
  return result;
7179
- }).filter(child => child !== null && child !== undefined); // Remove null/undefined children
7362
+ }).filter(child => child !== null && child !== undefined);
7180
7363
 
7181
7364
  if (processedChildren.length === 0) {
7182
7365
  processed[key] = null;
@@ -7321,7 +7504,6 @@ function ServerComponentWrapper({
7321
7504
  }
7322
7505
 
7323
7506
  function createServerComponentWrapper(componentName, importPath) {
7324
- // Use a global refresh counter to force re-mounting when components change
7325
7507
  let globalRefreshCounter = 0;
7326
7508
 
7327
7509
  if (typeof window !== 'undefined') {
@@ -7335,7 +7517,6 @@ function createServerComponentWrapper(componentName, importPath) {
7335
7517
  const ServerComponent = (props) => {
7336
7518
  const [mountKey, setMountKey] = useState(globalRefreshCounter);
7337
7519
 
7338
- // Force re-mount when component is invalidated
7339
7520
  useEffect(() => {
7340
7521
  const handleRscInvalidate = (event) => {
7341
7522
  const detail = event.detail;
@@ -7356,7 +7537,7 @@ function createServerComponentWrapper(componentName, importPath) {
7356
7537
  return React.createElement(Suspense, {
7357
7538
  fallback: null
7358
7539
  }, React.createElement(ServerComponentWrapper, {
7359
- key: componentName + '-' + mountKey, // Force re-mount with key change
7540
+ key: componentName + '-' + mountKey,
7360
7541
  componentId: componentName,
7361
7542
  props: props,
7362
7543
  fallback: null
@@ -7373,9 +7554,7 @@ function createServerComponentWrapper(componentName, importPath) {
7373
7554
  export const fetchServerComponent = (componentId, props) =>
7374
7555
  rscClient.fetchServerComponent(componentId, props);
7375
7556
 
7376
- // Helper function to check if a file is a server component (client-side)
7377
7557
  function isServerComponent(filePath) {
7378
- // Simple client-side check based on file path patterns
7379
7558
  return filePath && (
7380
7559
  filePath.includes('ServerWithClient') ||
7381
7560
  filePath.includes('server') ||
@@ -7383,32 +7562,26 @@ function isServerComponent(filePath) {
7383
7562
  );
7384
7563
  }
7385
7564
 
7386
- // HMR support for RSC cache invalidation
7387
7565
  if (import.meta.hot) {
7388
- // Listen for Vite's beforeFullReload event for server components
7389
7566
  import.meta.hot.on('vite:beforeFullReload', async (data) => {
7390
7567
  if (data?.path && isServerComponent(data.path)) {
7391
- // Immediately invalidate cache and trigger re-registration before reload
7392
7568
  await invalidateRscCache({ filePath: data.path, forceReload: true });
7393
7569
  }
7394
7570
  });
7395
7571
 
7396
7572
 
7397
7573
 
7398
- // Helper function to invalidate RSC cache and trigger component re-registration
7399
7574
  async function invalidateRscCache(data) {
7400
7575
  const filePath = data?.filePath || data;
7401
7576
 
7402
- // Wait for server to be ready
7403
7577
  const waitForServerReady = async () => {
7404
- for (let i = 0; i < 20; i++) { // Try for up to 2 seconds
7578
+ for (let i = 0; i < 20; i++) {
7405
7579
  try {
7406
7580
  const response = await fetch('/_rsc_status');
7407
7581
  if (response.ok) {
7408
7582
  return true;
7409
7583
  }
7410
7584
  } catch (e) {
7411
- // Server not ready yet
7412
7585
  }
7413
7586
  await new Promise(resolve => setTimeout(resolve, 100));
7414
7587
  }
@@ -7417,10 +7590,8 @@ if (import.meta.hot) {
7417
7590
 
7418
7591
  const serverReady = await waitForServerReady();
7419
7592
  if (serverReady) {
7420
- // Clear client-side RSC cache immediately
7421
7593
  rscClient.clearCache();
7422
7594
 
7423
- // Trigger immediate server component re-registration
7424
7595
  try {
7425
7596
  await fetch('/api/rsc/hmr-register', {
7426
7597
  method: 'POST',
@@ -7432,14 +7603,10 @@ if (import.meta.hot) {
7432
7603
  })
7433
7604
  });
7434
7605
 
7435
- // Wait a bit for the server to re-register the component
7436
- // The server now immediately reads and re-registers the component
7437
7606
  await new Promise(resolve => setTimeout(resolve, 300));
7438
7607
  } catch (error) {
7439
- // Fallback to existing timeout-based approach
7440
7608
  }
7441
7609
 
7442
- // Trigger re-render of active server components
7443
7610
  if (typeof window !== 'undefined') {
7444
7611
  const event = new CustomEvent('rari:rsc-invalidate', {
7445
7612
  detail: { filePath }
@@ -7509,6 +7676,73 @@ ${registrations.join("\n")}
7509
7676
  const serverBuildPlugin = createServerBuildPlugin(options.serverBuild);
7510
7677
  return [mainPlugin, serverBuildPlugin];
7511
7678
  }
7679
+ function createReactDOMOptimization() {
7680
+ return { build: {
7681
+ rollupOptions: {
7682
+ output: { manualChunks: (id) => {
7683
+ if (id.includes("node_modules/react-dom") || id.includes("react-dom/client") || id.includes("react-dom/server") || id.includes("react-dom/")) return "react-dom";
7684
+ if ((id.includes("node_modules/react") || id.includes("react/")) && !id.includes("react-dom")) return "react";
7685
+ if (id.includes("scheduler") && id.includes("node_modules")) return "scheduler";
7686
+ if (id.includes("markdown-it") || id.includes("shiki")) return "vendor";
7687
+ if (id.includes("node_modules")) return "vendor";
7688
+ } },
7689
+ treeshake: {
7690
+ moduleSideEffects: (id) => {
7691
+ if (id.includes(".css") || id.includes("polyfill")) return true;
7692
+ if (id.includes("react-dom") || id.includes("react") || id.includes("scheduler") || id.includes("react-dom/client") || id.includes("react-dom/server")) return false;
7693
+ return false;
7694
+ },
7695
+ unknownGlobalSideEffects: false
7696
+ }
7697
+ },
7698
+ minify: "terser",
7699
+ target: [
7700
+ "es2020",
7701
+ "edge88",
7702
+ "firefox78",
7703
+ "chrome87",
7704
+ "safari14"
7705
+ ],
7706
+ cssMinify: "esbuild",
7707
+ sourcemap: false,
7708
+ terserOptions: {
7709
+ compress: {
7710
+ drop_console: true,
7711
+ drop_debugger: true,
7712
+ pure_funcs: [
7713
+ "console.log",
7714
+ "console.info",
7715
+ "console.debug",
7716
+ "console.warn",
7717
+ "invariant",
7718
+ "warning",
7719
+ "__DEV__",
7720
+ "ReactDOM.render",
7721
+ "ReactDOM.unmountComponentAtNode",
7722
+ "ReactDOM.findDOMNode",
7723
+ "ReactDOM.createPortal"
7724
+ ],
7725
+ passes: 3,
7726
+ unsafe: true,
7727
+ unsafe_comps: true,
7728
+ unsafe_Function: true,
7729
+ unsafe_math: true,
7730
+ unsafe_symbols: true,
7731
+ unsafe_methods: true,
7732
+ unsafe_proto: true,
7733
+ unsafe_regexp: true,
7734
+ unsafe_undefined: true,
7735
+ dead_code: true,
7736
+ side_effects: false
7737
+ },
7738
+ mangle: {
7739
+ safari10: true,
7740
+ properties: { regex: /^_/ }
7741
+ },
7742
+ format: { comments: false }
7743
+ }
7744
+ } };
7745
+ }
7512
7746
  function defineRariConfig(config) {
7513
7747
  return {
7514
7748
  plugins: [rari(), ...config.plugins || []],
@@ -7517,4 +7751,4 @@ function defineRariConfig(config) {
7517
7751
  }
7518
7752
 
7519
7753
  //#endregion
7520
- export { FileRouteGenerator, convertFilePatternToRoutePattern, createRouteManifest, defineRariConfig, generateFileRoutes, loadRouteManifest, rari, rariRouter, validateRoutes, watchFileRoutes };
7754
+ export { FileRouteGenerator, convertFilePatternToRoutePattern, createReactDOMOptimization, createRouteManifest, defineRariConfig, generateFileRoutes, loadRouteManifest, rari, rariRouter, validateRoutes, watchFileRoutes };