rari 0.2.7 → 0.2.9

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-Ph4oyo0B.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-_LR44Mbg.js";
3
- import "./server-build-DyMLcQhk.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-MkYb94pQ.js";
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";
3
- import { createServerBuildPlugin } from "./server-build-DyMLcQhk.js";
2
+ import { analyzeFilePath } from "./runtime-client-CcEhh-F7.js";
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,183 @@ 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
+ file.source = html;
5949
+ }
5950
+ });
5951
+ }
5952
+ });
5953
+ }
5954
+ if (!config.build.rolldownOptions.input) config.build.rolldownOptions.input = { main: "./index.html" };
5955
+ config.build.rolldownOptions.output = config.build.rolldownOptions.output || {};
5956
+ const outputConfig = Array.isArray(config.build.rolldownOptions.output) ? config.build.rolldownOptions.output[0] || {} : config.build.rolldownOptions.output;
5957
+ outputConfig.manualChunks = (id) => {
5958
+ if (id.includes("node_modules/react-dom") || id.includes("react-dom/client") || id.includes("react-dom/server") || id.includes("react-dom/")) return "react-dom";
5959
+ if ((id.includes("node_modules/react") || id.includes("react/")) && !id.includes("react-dom")) return "react";
5960
+ if (id.includes("scheduler") && id.includes("node_modules")) return "scheduler";
5961
+ if (id.includes("markdown-it") || id.includes("shiki")) return "vendor";
5962
+ if (id.includes("node_modules")) return "vendor";
5963
+ };
5964
+ config.build.rolldownOptions.treeshake = config.build.rolldownOptions.treeshake || {
5965
+ moduleSideEffects: (id) => {
5966
+ if (id.includes(".css") || id.includes("polyfill")) return true;
5967
+ if (id.includes("react-dom") || id.includes("react") || id.includes("scheduler") || id.includes("react-dom/client") || id.includes("react-dom/server")) return true;
5968
+ if (id.includes("node_modules") && !id.includes("react")) return false;
5969
+ return true;
5970
+ },
5971
+ unknownGlobalSideEffects: false
5972
+ };
5973
+ const existingExternal = config.build.rolldownOptions?.external || [];
5974
+ const reactDomExternals = [
5975
+ "react-dom/profiling",
5976
+ "react-dom/test-utils",
5977
+ "react-dom/server",
5978
+ "react-dom/server.browser",
5979
+ "react-dom/server.node",
5980
+ "react/jsx-dev-runtime",
5981
+ "scheduler/tracing",
5982
+ "scheduler/unstable_mock",
5983
+ "react/cjs/react.development.js",
5984
+ "react/cjs/react.production.min.js",
5985
+ "react-dom/cjs/react-dom.development.js",
5986
+ "react-dom/cjs/react-dom.production.min.js",
5987
+ "react-dom/src/client/ReactDOMRoot.js",
5988
+ "react-dom/src/events/plugins",
5989
+ "react-dom/src/shared/HTMLDOMPropertyConfig.js",
5990
+ "react-dom/src/shared/DOMPropertyOperations.js"
5991
+ ];
5992
+ if (Array.isArray(existingExternal)) {
5993
+ const external = [...existingExternal];
5994
+ external.push(...reactDomExternals.filter((dep) => !external.includes(dep)));
5995
+ config.build.rolldownOptions.external = external;
5996
+ } else if (typeof existingExternal === "function") {
5997
+ const originalExternal = existingExternal;
5998
+ config.build.rolldownOptions.external = (id, parentId, isResolved) => {
5999
+ if (reactDomExternals.includes(id)) return true;
6000
+ return originalExternal(id, parentId, isResolved);
6001
+ };
6002
+ } else config.build.rolldownOptions.external = [...Array.isArray(existingExternal) ? existingExternal : [existingExternal], ...reactDomExternals].filter(Boolean);
6003
+ config.build.minify = true;
6004
+ config.build.target = config.build.target || [
6005
+ "es2020",
6006
+ "edge88",
6007
+ "firefox78",
6008
+ "chrome87",
6009
+ "safari14"
6010
+ ];
6011
+ config.build.cssMinify = config.build.cssMinify !== false ? "esbuild" : false;
6012
+ config.build.cssCodeSplit = true;
6013
+ config.build.assetsInlineLimit = 4096;
6014
+ config.build.chunkSizeWarningLimit = 1e3;
6015
+ config.build.sourcemap = config.build.sourcemap !== void 0 ? config.build.sourcemap : true;
6016
+ config.build.terserOptions = config.build.terserOptions || {
6017
+ compress: {
6018
+ drop_console: true,
6019
+ drop_debugger: true,
6020
+ pure_funcs: [
6021
+ "console.log",
6022
+ "console.info",
6023
+ "console.debug",
6024
+ "console.warn",
6025
+ "invariant",
6026
+ "warning",
6027
+ "__DEV__",
6028
+ "ReactDOM.render",
6029
+ "ReactDOM.unmountComponentAtNode",
6030
+ "ReactDOM.findDOMNode",
6031
+ "ReactDOM.createPortal"
6032
+ ],
6033
+ passes: 3,
6034
+ unsafe: true,
6035
+ unsafe_comps: true,
6036
+ unsafe_Function: true,
6037
+ unsafe_math: true,
6038
+ unsafe_symbols: true,
6039
+ unsafe_methods: true,
6040
+ unsafe_proto: true,
6041
+ unsafe_regexp: true,
6042
+ unsafe_undefined: true,
6043
+ dead_code: true,
6044
+ side_effects: false
6045
+ },
6046
+ mangle: {
6047
+ safari10: true,
6048
+ properties: { regex: /^_/ }
6049
+ },
6050
+ format: { comments: false }
6051
+ };
6052
+ outputConfig.format = outputConfig.format || "es";
6053
+ outputConfig.minify = true;
6054
+ if (Array.isArray(config.build.rolldownOptions.output)) config.build.rolldownOptions.output[0] = outputConfig;
6055
+ else config.build.rolldownOptions.output = outputConfig;
5917
6056
  }
5918
6057
  if (config.environments && config.environments.client) {
5919
6058
  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";
6059
+ if (!config.environments.client.build.rolldownOptions) config.environments.client.build.rolldownOptions = {};
6060
+ if (!config.environments.client.build.rolldownOptions.input) config.environments.client.build.rolldownOptions.input = {};
6061
+ 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";
6062
+ config.environments.client.build.rolldownOptions.plugins = config.environments.client.build.rolldownOptions.plugins || [];
6063
+ if (Array.isArray(config.environments.client.build.rolldownOptions.plugins)) config.environments.client.build.rolldownOptions.plugins.push(minify());
6064
+ config.environments.client.build.minify = true;
6065
+ config.environments.client.build.target = config.environments.client.build.target || [
6066
+ "es2020",
6067
+ "edge88",
6068
+ "firefox78",
6069
+ "chrome87",
6070
+ "safari14"
6071
+ ];
6072
+ config.environments.client.build.cssMinify = "esbuild";
6073
+ config.environments.client.build.cssCodeSplit = true;
6074
+ config.environments.client.build.assetsInlineLimit = 4096;
6075
+ config.environments.client.build.rolldownOptions.treeshake = {
6076
+ moduleSideEffects: false,
6077
+ unknownGlobalSideEffects: false
6078
+ };
6079
+ config.environments.client.build.rolldownOptions.output = config.environments.client.build.rolldownOptions.output || {};
6080
+ const clientOutputConfig = Array.isArray(config.environments.client.build.rolldownOptions.output) ? config.environments.client.build.rolldownOptions.output[0] || {} : config.environments.client.build.rolldownOptions.output;
6081
+ clientOutputConfig.manualChunks = (id) => {
6082
+ if (id.includes("node_modules/react-dom") || id.includes("react-dom/client") || id.includes("react-dom/server") || id.includes("react-dom/")) return "react-dom";
6083
+ if ((id.includes("node_modules/react") || id.includes("react/")) && !id.includes("react-dom")) return "react";
6084
+ if (id.includes("scheduler") && id.includes("node_modules")) return "scheduler";
6085
+ if (id.includes("rari") && (id.includes("router") || id.includes("navigation"))) return "router";
6086
+ if (id.includes("markdown-it") || id.includes("shiki")) return "vendor";
6087
+ if (id.includes("node_modules")) return "vendor";
6088
+ };
6089
+ clientOutputConfig.format = clientOutputConfig.format || "es";
6090
+ clientOutputConfig.minify = true;
6091
+ if (Array.isArray(config.environments.client.build.rolldownOptions.output)) config.environments.client.build.rolldownOptions.output[0] = clientOutputConfig;
6092
+ else config.environments.client.build.rolldownOptions.output = clientOutputConfig;
5923
6093
  }
5924
6094
  return config;
5925
6095
  },
5926
6096
  transform(code, id) {
5927
6097
  if (!/\.(?:tsx?|jsx?)$/.test(id)) return null;
6098
+ if (code.includes("react-dom")) {
6099
+ code = code.replace(/import\s+ReactDOM\s+from\s+['"]react-dom\/client['"];?/g, "import { createRoot, hydrateRoot } from 'react-dom/client';");
6100
+ code = code.replace(/import\s+ReactDOM\s+from\s+['"]react-dom['"];?/g, "import { createRoot, hydrateRoot } from 'react-dom/client';");
6101
+ code = code.replace(/ReactDOM\.createRoot/g, "createRoot");
6102
+ code = code.replace(/ReactDOM\.hydrateRoot/g, "hydrateRoot");
6103
+ }
5928
6104
  const environment = this.environment;
5929
6105
  if (hasTopLevelDirective(code, "use client")) {
5930
6106
  componentTypeCache.set(id, "client");
@@ -6028,7 +6204,7 @@ const ${componentName$1} = registerClientReference(
6028
6204
  const srcDir = path.join(projectRoot, "src");
6029
6205
  const discoverAndRegisterComponents = async () => {
6030
6206
  try {
6031
- const { ServerComponentBuilder, scanDirectory } = await import("./server-build-CLt2Us53.js");
6207
+ const { ServerComponentBuilder, scanDirectory } = await import("./server-build-Cp6_RdeA.js");
6032
6208
  const builder = new ServerComponentBuilder(projectRoot, {
6033
6209
  outDir: "temp",
6034
6210
  serverDir: "server",
@@ -6162,7 +6338,7 @@ const ${componentName$1} = registerClientReference(
6162
6338
  };
6163
6339
  const handleServerComponentHMR = async (filePath) => {
6164
6340
  try {
6165
- const { ServerComponentBuilder } = await import("./server-build-CLt2Us53.js");
6341
+ const { ServerComponentBuilder } = await import("./server-build-Cp6_RdeA.js");
6166
6342
  const builder = new ServerComponentBuilder(projectRoot, {
6167
6343
  outDir: "temp",
6168
6344
  serverDir: "server",
@@ -6374,7 +6550,6 @@ export const __CLIENT_REFERENCE_REGISTRY__ = clientReferenceRegistry;
6374
6550
  export const __SERVER_REFERENCE_REGISTRY__ = serverReferenceRegistry;
6375
6551
  export const __CLIENT_COMPONENT_REGISTRY__ = clientComponentRegistry;
6376
6552
 
6377
- // Module map for React Server Components
6378
6553
  export function createClientModuleMap() {
6379
6554
  const moduleMap = {};
6380
6555
 
@@ -6397,7 +6572,6 @@ export function createClientModuleMap() {
6397
6572
  if (id === "virtual:rsc-integration") return `
6398
6573
  import React, { useState, useEffect, Suspense } from 'react';
6399
6574
 
6400
- // Client component registration for RSC system compatibility
6401
6575
  if (typeof globalThis.__clientComponents === 'undefined') {
6402
6576
  globalThis.__clientComponents = {};
6403
6577
  }
@@ -6415,7 +6589,6 @@ export function registerClientComponent(componentFunction, id, exportName) {
6415
6589
 
6416
6590
  const componentId = componentName;
6417
6591
 
6418
- // Register in global registry for RSC traversal
6419
6592
  globalThis.__clientComponents[componentId] = {
6420
6593
  id: componentId,
6421
6594
  path: id,
@@ -7176,7 +7349,7 @@ class RscClient {
7176
7349
  const processedChildren = value.map((child, index) => {
7177
7350
  const result = this.reconstructElementFromRscData(child, modules);
7178
7351
  return result;
7179
- }).filter(child => child !== null && child !== undefined); // Remove null/undefined children
7352
+ }).filter(child => child !== null && child !== undefined);
7180
7353
 
7181
7354
  if (processedChildren.length === 0) {
7182
7355
  processed[key] = null;
@@ -7321,7 +7494,6 @@ function ServerComponentWrapper({
7321
7494
  }
7322
7495
 
7323
7496
  function createServerComponentWrapper(componentName, importPath) {
7324
- // Use a global refresh counter to force re-mounting when components change
7325
7497
  let globalRefreshCounter = 0;
7326
7498
 
7327
7499
  if (typeof window !== 'undefined') {
@@ -7335,7 +7507,6 @@ function createServerComponentWrapper(componentName, importPath) {
7335
7507
  const ServerComponent = (props) => {
7336
7508
  const [mountKey, setMountKey] = useState(globalRefreshCounter);
7337
7509
 
7338
- // Force re-mount when component is invalidated
7339
7510
  useEffect(() => {
7340
7511
  const handleRscInvalidate = (event) => {
7341
7512
  const detail = event.detail;
@@ -7356,7 +7527,7 @@ function createServerComponentWrapper(componentName, importPath) {
7356
7527
  return React.createElement(Suspense, {
7357
7528
  fallback: null
7358
7529
  }, React.createElement(ServerComponentWrapper, {
7359
- key: componentName + '-' + mountKey, // Force re-mount with key change
7530
+ key: componentName + '-' + mountKey,
7360
7531
  componentId: componentName,
7361
7532
  props: props,
7362
7533
  fallback: null
@@ -7373,9 +7544,7 @@ function createServerComponentWrapper(componentName, importPath) {
7373
7544
  export const fetchServerComponent = (componentId, props) =>
7374
7545
  rscClient.fetchServerComponent(componentId, props);
7375
7546
 
7376
- // Helper function to check if a file is a server component (client-side)
7377
7547
  function isServerComponent(filePath) {
7378
- // Simple client-side check based on file path patterns
7379
7548
  return filePath && (
7380
7549
  filePath.includes('ServerWithClient') ||
7381
7550
  filePath.includes('server') ||
@@ -7383,32 +7552,26 @@ function isServerComponent(filePath) {
7383
7552
  );
7384
7553
  }
7385
7554
 
7386
- // HMR support for RSC cache invalidation
7387
7555
  if (import.meta.hot) {
7388
- // Listen for Vite's beforeFullReload event for server components
7389
7556
  import.meta.hot.on('vite:beforeFullReload', async (data) => {
7390
7557
  if (data?.path && isServerComponent(data.path)) {
7391
- // Immediately invalidate cache and trigger re-registration before reload
7392
7558
  await invalidateRscCache({ filePath: data.path, forceReload: true });
7393
7559
  }
7394
7560
  });
7395
7561
 
7396
7562
 
7397
7563
 
7398
- // Helper function to invalidate RSC cache and trigger component re-registration
7399
7564
  async function invalidateRscCache(data) {
7400
7565
  const filePath = data?.filePath || data;
7401
7566
 
7402
- // Wait for server to be ready
7403
7567
  const waitForServerReady = async () => {
7404
- for (let i = 0; i < 20; i++) { // Try for up to 2 seconds
7568
+ for (let i = 0; i < 20; i++) {
7405
7569
  try {
7406
7570
  const response = await fetch('/_rsc_status');
7407
7571
  if (response.ok) {
7408
7572
  return true;
7409
7573
  }
7410
7574
  } catch (e) {
7411
- // Server not ready yet
7412
7575
  }
7413
7576
  await new Promise(resolve => setTimeout(resolve, 100));
7414
7577
  }
@@ -7417,10 +7580,8 @@ if (import.meta.hot) {
7417
7580
 
7418
7581
  const serverReady = await waitForServerReady();
7419
7582
  if (serverReady) {
7420
- // Clear client-side RSC cache immediately
7421
7583
  rscClient.clearCache();
7422
7584
 
7423
- // Trigger immediate server component re-registration
7424
7585
  try {
7425
7586
  await fetch('/api/rsc/hmr-register', {
7426
7587
  method: 'POST',
@@ -7432,14 +7593,10 @@ if (import.meta.hot) {
7432
7593
  })
7433
7594
  });
7434
7595
 
7435
- // Wait a bit for the server to re-register the component
7436
- // The server now immediately reads and re-registers the component
7437
7596
  await new Promise(resolve => setTimeout(resolve, 300));
7438
7597
  } catch (error) {
7439
- // Fallback to existing timeout-based approach
7440
7598
  }
7441
7599
 
7442
- // Trigger re-render of active server components
7443
7600
  if (typeof window !== 'undefined') {
7444
7601
  const event = new CustomEvent('rari:rsc-invalidate', {
7445
7602
  detail: { filePath }
@@ -7509,6 +7666,73 @@ ${registrations.join("\n")}
7509
7666
  const serverBuildPlugin = createServerBuildPlugin(options.serverBuild);
7510
7667
  return [mainPlugin, serverBuildPlugin];
7511
7668
  }
7669
+ function createReactDOMOptimization() {
7670
+ return { build: {
7671
+ rollupOptions: {
7672
+ output: { manualChunks: (id) => {
7673
+ if (id.includes("node_modules/react-dom") || id.includes("react-dom/client") || id.includes("react-dom/server") || id.includes("react-dom/")) return "react-dom";
7674
+ if ((id.includes("node_modules/react") || id.includes("react/")) && !id.includes("react-dom")) return "react";
7675
+ if (id.includes("scheduler") && id.includes("node_modules")) return "scheduler";
7676
+ if (id.includes("markdown-it") || id.includes("shiki")) return "vendor";
7677
+ if (id.includes("node_modules")) return "vendor";
7678
+ } },
7679
+ treeshake: {
7680
+ moduleSideEffects: (id) => {
7681
+ if (id.includes(".css") || id.includes("polyfill")) return true;
7682
+ if (id.includes("react-dom") || id.includes("react") || id.includes("scheduler") || id.includes("react-dom/client") || id.includes("react-dom/server")) return false;
7683
+ return false;
7684
+ },
7685
+ unknownGlobalSideEffects: false
7686
+ }
7687
+ },
7688
+ minify: "terser",
7689
+ target: [
7690
+ "es2020",
7691
+ "edge88",
7692
+ "firefox78",
7693
+ "chrome87",
7694
+ "safari14"
7695
+ ],
7696
+ cssMinify: "esbuild",
7697
+ sourcemap: false,
7698
+ terserOptions: {
7699
+ compress: {
7700
+ drop_console: true,
7701
+ drop_debugger: true,
7702
+ pure_funcs: [
7703
+ "console.log",
7704
+ "console.info",
7705
+ "console.debug",
7706
+ "console.warn",
7707
+ "invariant",
7708
+ "warning",
7709
+ "__DEV__",
7710
+ "ReactDOM.render",
7711
+ "ReactDOM.unmountComponentAtNode",
7712
+ "ReactDOM.findDOMNode",
7713
+ "ReactDOM.createPortal"
7714
+ ],
7715
+ passes: 3,
7716
+ unsafe: true,
7717
+ unsafe_comps: true,
7718
+ unsafe_Function: true,
7719
+ unsafe_math: true,
7720
+ unsafe_symbols: true,
7721
+ unsafe_methods: true,
7722
+ unsafe_proto: true,
7723
+ unsafe_regexp: true,
7724
+ unsafe_undefined: true,
7725
+ dead_code: true,
7726
+ side_effects: false
7727
+ },
7728
+ mangle: {
7729
+ safari10: true,
7730
+ properties: { regex: /^_/ }
7731
+ },
7732
+ format: { comments: false }
7733
+ }
7734
+ } };
7735
+ }
7512
7736
  function defineRariConfig(config) {
7513
7737
  return {
7514
7738
  plugins: [rari(), ...config.plugins || []],
@@ -7517,4 +7741,4 @@ function defineRariConfig(config) {
7517
7741
  }
7518
7742
 
7519
7743
  //#endregion
7520
- export { FileRouteGenerator, convertFilePatternToRoutePattern, createRouteManifest, defineRariConfig, generateFileRoutes, loadRouteManifest, rari, rariRouter, validateRoutes, watchFileRoutes };
7744
+ export { FileRouteGenerator, convertFilePatternToRoutePattern, createReactDOMOptimization, createRouteManifest, defineRariConfig, generateFileRoutes, loadRouteManifest, rari, rariRouter, validateRoutes, watchFileRoutes };