rari 0.2.12 → 0.2.14

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";
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, createRouteManifest, defineRariConfig, generateFileRoutes, loadRouteManifest, rari, rariRouter, validateRoutes, watchFileRoutes } from "./server-CpxpL2un.js";
3
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 };
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-C6qEeTPu.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, createRouteManifest, defineRariConfig, generateFileRoutes, loadRouteManifest, rari, rariRouter, validateRoutes, watchFileRoutes } from "./server-BrkE-3ny.js";
3
3
  import "./server-build-DaBgiV55.js";
4
4
 
5
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 };
@@ -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,5 +1,5 @@
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";
@@ -5110,7 +5110,7 @@ var require_chokidar = __commonJS({ "../../node_modules/.pnpm/chokidar@3.6.0/nod
5110
5110
 
5111
5111
  //#endregion
5112
5112
  //#region src/router/file-routes.ts
5113
- var import_chokidar$1 = __toESM(require_chokidar());
5113
+ var import_chokidar$1 = __toESM(require_chokidar(), 1);
5114
5114
  var FileRouteGenerator = class {
5115
5115
  pagesDir;
5116
5116
  extensions;
@@ -5419,7 +5419,7 @@ function convertFilePatternToRoutePattern(pattern) {
5419
5419
 
5420
5420
  //#endregion
5421
5421
  //#region src/router/vite-plugin.ts
5422
- var import_chokidar = __toESM(require_chokidar());
5422
+ var import_chokidar = __toESM(require_chokidar(), 1);
5423
5423
  const DEFAULT_OPTIONS = {
5424
5424
  pagesDir: "src/pages",
5425
5425
  extensions: [
@@ -1,4 +1,4 @@
1
- import { Route, RouteGenerationOptions } from "./runtime-client-BEWMJWMx.js";
1
+ import { Route, RouteGenerationOptions } from "./runtime-client-P4vvSVPV.js";
2
2
  import { Plugin, UserConfig } from "rolldown-vite";
3
3
 
4
4
  //#region src/router/file-routes.d.ts
package/dist/server.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";
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, createRouteManifest, defineRariConfig, generateFileRoutes, loadRouteManifest, rari, rariRouter, validateRoutes, watchFileRoutes } from "./server-CpxpL2un.js";
3
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 };
package/dist/server.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-C6qEeTPu.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, createRouteManifest, defineRariConfig, generateFileRoutes, loadRouteManifest, rari, rariRouter, validateRoutes, watchFileRoutes } from "./server-BrkE-3ny.js";
3
3
  import "./server-build-DaBgiV55.js";
4
4
 
5
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 };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "rari",
3
3
  "type": "module",
4
- "version": "0.2.12",
4
+ "version": "0.2.14",
5
5
  "description": "Runtime Accelerated Rendering Infrastructure (Rari)",
6
6
  "author": "Ryan Skinner",
7
7
  "license": "MIT",
@@ -43,6 +43,10 @@
43
43
  "types": "./dist/client.d.ts",
44
44
  "default": "./dist/client.js"
45
45
  },
46
+ "./client-dev": {
47
+ "types": "./dist/client-dev.d.ts",
48
+ "default": "./dist/client-dev.js"
49
+ },
46
50
  "./server": {
47
51
  "types": "./dist/server.d.ts",
48
52
  "default": "./dist/server.js"
@@ -74,14 +78,15 @@
74
78
  "dependencies": {
75
79
  "acorn": "^8.15.0",
76
80
  "esbuild": "^0.25.9",
77
- "picocolors": "^1.1.1"
81
+ "picocolors": "^1.1.1",
82
+ "rollup-plugin-esbuild": "^6.2.1"
78
83
  },
79
84
  "optionalDependencies": {
80
- "rari-darwin-arm64": "0.2.0",
81
- "rari-darwin-x64": "0.2.0",
82
- "rari-linux-arm64": "0.2.0",
83
- "rari-linux-x64": "0.2.0",
84
- "rari-win32-x64": "0.2.0"
85
+ "rari-darwin-arm64": "0.2.9",
86
+ "rari-darwin-x64": "0.2.9",
87
+ "rari-linux-arm64": "0.2.9",
88
+ "rari-linux-x64": "0.2.9",
89
+ "rari-win32-x64": "0.2.9"
85
90
  },
86
91
  "devDependencies": {
87
92
  "@types/node": "^24.2.1",
@@ -0,0 +1,59 @@
1
+ export { Link } from './router'
2
+
3
+ export {
4
+ buildSearchString,
5
+ buildUrl,
6
+ extractParamNames,
7
+ findMatchingRoute,
8
+ isDynamicRoute,
9
+ isPathActive,
10
+ joinPaths,
11
+ normalizePathname,
12
+ parseSearchParams,
13
+ parseUrl,
14
+ } from './router'
15
+
16
+ export {
17
+ Navigate,
18
+ Outlet,
19
+ RouteComponent as Route,
20
+ RouterProvider,
21
+ Routes,
22
+ useNavigation,
23
+ useParams,
24
+ usePathname,
25
+ useRoute,
26
+ useRouter,
27
+ useSearchParams,
28
+ withRouter,
29
+ } from './router'
30
+
31
+ export type {
32
+ ErrorBoundaryProps,
33
+ FileRouteInfo,
34
+ LayoutProps,
35
+ LinkProps,
36
+ LoadingProps,
37
+ NavigationOptions,
38
+ NavigationState,
39
+ PageComponent,
40
+ PageProps,
41
+ RouteGenerationOptions,
42
+ RouteMatch,
43
+ RouteMeta,
44
+ RouteParams,
45
+ RouterConfig,
46
+ RouterContext,
47
+ RouterProviderProps,
48
+ Route as RouteType,
49
+ SearchParams,
50
+ } from './router'
51
+
52
+ export {
53
+ createHttpRuntimeClient,
54
+ HttpRuntimeClient,
55
+ } from './runtime-client'
56
+
57
+ export type {
58
+ RuntimeClient,
59
+ } from './runtime-client'
package/src/client.ts CHANGED
@@ -1,6 +1,4 @@
1
- export {
2
- Link,
3
- } from './router'
1
+ export { Link } from './router'
4
2
 
5
3
  export {
6
4
  buildSearchString,
@@ -51,11 +49,6 @@ export type {
51
49
  SearchParams,
52
50
  } from './router'
53
51
 
54
- export {
55
- createHttpRuntimeClient,
56
- HttpRuntimeClient,
57
- } from './runtime-client'
52
+ export { createHttpRuntimeClient, HttpRuntimeClient } from './runtime-client'
58
53
 
59
- export type {
60
- RuntimeClient,
61
- } from './runtime-client'
54
+ export type { RuntimeClient } from './runtime-client'
@@ -1,12 +1,13 @@
1
1
  export {
2
- Link,
3
- Navigate,
4
2
  Outlet,
5
3
  RouteComponent,
6
4
  RouterContext,
7
5
  RouteRenderer,
8
6
  default as RouterProvider,
9
7
  Routes,
8
+ } from './router'
9
+
10
+ export {
10
11
  useNavigation,
11
12
  useParams,
12
13
  usePathname,
@@ -16,24 +17,29 @@ export {
16
17
  withRouter,
17
18
  } from './router'
18
19
 
20
+ export { Link, Navigate } from './router'
21
+
19
22
  export type * from './types'
20
23
 
24
+ export {
25
+ findMatchingRoute,
26
+ isDynamicRoute,
27
+ normalizePathname,
28
+ parseUrl,
29
+ } from './utils'
30
+
21
31
  export {
22
32
  analyzeFilePath,
23
33
  buildSearchString,
24
34
  buildUrl,
25
35
  extractParamNames,
26
36
  filePathToRoutePath,
27
- findMatchingRoute,
28
37
  getParentPath,
29
38
  getParentPaths,
30
- isDynamicRoute,
31
39
  isPathActive,
32
40
  joinPaths,
33
41
  matchRoute,
34
- normalizePathname,
35
42
  parseSearchParams,
36
- parseUrl,
37
43
  routePathsEqual,
38
44
  routePathToRegex,
39
45
  sortRoutesBySpecificity,
@@ -47,10 +47,9 @@ export function RouterProvider({
47
47
  }),
48
48
  [config],
49
49
  )
50
- const [currentRoute, setCurrentRoute] = useState<RouteMatch | null>(null)
51
50
 
52
- const updateCurrentRoute = useCallback(
53
- (url: string) => {
51
+ const resolveRoute = useCallback(
52
+ (url: string): RouteMatch | null => {
54
53
  const { pathname, search, hash, searchParams } = parseUrl(url)
55
54
  const normalizedPathname = normalizePathname(pathname)
56
55
 
@@ -64,17 +63,56 @@ export function RouterProvider({
64
63
  hash,
65
64
  }
66
65
 
67
- enhancedMatch.childMatch = findDeepestChildMatch(enhancedMatch, normalizedPathname)
68
-
69
- setCurrentRoute(enhancedMatch)
70
- }
71
- else {
72
- setCurrentRoute(null)
66
+ enhancedMatch.childMatch = findDeepestChildMatch(
67
+ enhancedMatch,
68
+ normalizedPathname,
69
+ )
70
+ return enhancedMatch
73
71
  }
72
+
73
+ return null
74
74
  },
75
75
  [routes],
76
76
  )
77
77
 
78
+ const [routerState, setRouterState] = useState<{
79
+ currentRoute: RouteMatch | null
80
+ isReady: boolean
81
+ }>(() => {
82
+ if (typeof window === 'undefined') {
83
+ return { currentRoute: null, isReady: false }
84
+ }
85
+
86
+ const url = mergedConfig.useHash
87
+ ? window.location.hash.slice(1) || '/'
88
+ : window.location.pathname
89
+ + window.location.search
90
+ + window.location.hash
91
+
92
+ let initialRoute
93
+ try {
94
+ initialRoute = resolveRoute(url)
95
+ }
96
+ catch (error) {
97
+ console.error('Error resolving initial route:', error)
98
+ initialRoute = null
99
+ }
100
+
101
+ const isReady = true
102
+ return { currentRoute: initialRoute, isReady }
103
+ })
104
+
105
+ const currentRoute = routerState.currentRoute
106
+ const isReady = routerState.isReady
107
+
108
+ const updateCurrentRoute = useCallback(
109
+ (url: string) => {
110
+ const route = resolveRoute(url)
111
+ setRouterState({ currentRoute: route, isReady: true })
112
+ },
113
+ [resolveRoute],
114
+ )
115
+
78
116
  useEffect(() => {
79
117
  const handleLocationChange = () => {
80
118
  const url = mergedConfig.useHash
@@ -86,8 +124,6 @@ export function RouterProvider({
86
124
  updateCurrentRoute(url)
87
125
  }
88
126
 
89
- handleLocationChange()
90
-
91
127
  const handlePopState = () => {
92
128
  handleLocationChange()
93
129
  }
@@ -175,8 +211,8 @@ export function RouterProvider({
175
211
  [currentRoute],
176
212
  )
177
213
 
178
- const contextValue: IRouterContext = useMemo(
179
- () => ({
214
+ const contextValue: IRouterContext = useMemo(() => {
215
+ return {
180
216
  currentRoute,
181
217
  routes,
182
218
  navigate,
@@ -185,18 +221,19 @@ export function RouterProvider({
185
221
  replace,
186
222
  isActive,
187
223
  config: mergedConfig,
188
- }),
189
- [
190
- currentRoute,
191
- routes,
192
- navigate,
193
- back,
194
- forward,
195
- replace,
196
- isActive,
197
- mergedConfig,
198
- ],
199
- )
224
+ isReady,
225
+ }
226
+ }, [
227
+ currentRoute,
228
+ routes,
229
+ navigate,
230
+ back,
231
+ forward,
232
+ replace,
233
+ isActive,
234
+ mergedConfig,
235
+ isReady,
236
+ ])
200
237
 
201
238
  return <RouterContext value={contextValue}>{children}</RouterContext>
202
239
  }
@@ -244,8 +281,7 @@ export function useParams() {
244
281
  }
245
282
 
246
283
  export function useSearchParams() {
247
- const { currentRoute } = useRouter()
248
- const { navigate } = useRouter()
284
+ const { currentRoute, navigate } = useRouter()
249
285
 
250
286
  const searchParams = currentRoute?.searchParams || {}
251
287
 
@@ -254,7 +290,7 @@ export function useSearchParams() {
254
290
  params:
255
291
  | Record<string, string | string[]>
256
292
  | ((
257
- prev: Record<string, string | string[]>
293
+ prev: Record<string, string | string[]>,
258
294
  ) => Record<string, string | string[]>),
259
295
  options: NavigationOptions = DEFAULT_CONFIG,
260
296
  ) => {
@@ -357,16 +393,25 @@ export function Outlet() {
357
393
  return null
358
394
  }
359
395
 
360
- return <ChildComponent {...childRoute.params} searchParams={childRoute.searchParams} />
396
+ return (
397
+ <ChildComponent
398
+ {...childRoute.params}
399
+ searchParams={childRoute.searchParams}
400
+ />
401
+ )
361
402
  }
362
403
 
363
- function findChildRouteForCurrentLevel(currentRoute: RouteMatch): RouteMatch | null {
404
+ function findChildRouteForCurrentLevel(
405
+ currentRoute: RouteMatch,
406
+ ): RouteMatch | null {
364
407
  if (currentRoute.childMatch) {
365
408
  return currentRoute.childMatch
366
409
  }
367
410
 
368
411
  if (currentRoute.route.children) {
369
- const indexRoute = currentRoute.route.children.find(child => child.isIndex)
412
+ const indexRoute = currentRoute.route.children.find(
413
+ child => child.isIndex,
414
+ )
370
415
  if (indexRoute) {
371
416
  return {
372
417
  route: indexRoute,
@@ -385,14 +430,26 @@ function findChildRouteForCurrentLevel(currentRoute: RouteMatch): RouteMatch | n
385
430
  export function RouteRenderer({ routeMatch }: { routeMatch: RouteMatch }) {
386
431
  if (!routeMatch.layouts || routeMatch.layouts.length === 0) {
387
432
  const Component = routeMatch.route.component
388
- return Component ? <Component {...routeMatch.params} searchParams={routeMatch.searchParams} /> : null
433
+ return Component
434
+ ? (
435
+ <Component
436
+ {...routeMatch.params}
437
+ searchParams={routeMatch.searchParams}
438
+ />
439
+ )
440
+ : null
389
441
  }
390
442
 
391
443
  let rendered: ReactNode = null
392
444
  const Component = routeMatch.route.component
393
445
 
394
446
  if (Component) {
395
- rendered = <Component {...routeMatch.params} searchParams={routeMatch.searchParams} />
447
+ rendered = (
448
+ <Component
449
+ {...routeMatch.params}
450
+ searchParams={routeMatch.searchParams}
451
+ />
452
+ )
396
453
  }
397
454
 
398
455
  for (let i = routeMatch.layouts.length - 1; i >= 0; i--) {
@@ -400,7 +457,9 @@ export function RouteRenderer({ routeMatch }: { routeMatch: RouteMatch }) {
400
457
  const LayoutComponent = layout.component
401
458
 
402
459
  if (LayoutComponent) {
403
- rendered = <LayoutComponent route={routeMatch}>{rendered}</LayoutComponent>
460
+ rendered = (
461
+ <LayoutComponent route={routeMatch}>{rendered}</LayoutComponent>
462
+ )
404
463
  }
405
464
  }
406
465
 
@@ -428,7 +487,10 @@ export function Navigate({
428
487
  export default RouterProvider
429
488
  export { RouterContext }
430
489
 
431
- function findDeepestChildMatch(routeMatch: RouteMatch, pathname: string): RouteMatch | null {
490
+ function findDeepestChildMatch(
491
+ routeMatch: RouteMatch,
492
+ pathname: string,
493
+ ): RouteMatch | null {
432
494
  if (!routeMatch.route.children || routeMatch.route.children.length === 0) {
433
495
  return null
434
496
  }
@@ -486,18 +548,12 @@ export function Link({
486
548
  )
487
549
 
488
550
  const isLinkActive = isActive(to, exact)
489
- const finalClassName = [
490
- className,
491
- isLinkActive && activeClassName,
492
- ].filter(Boolean).join(' ')
551
+ const finalClassName = [className, isLinkActive && activeClassName]
552
+ .filter(Boolean)
553
+ .join(' ')
493
554
 
494
555
  return (
495
- <a
496
- href={to}
497
- className={finalClassName}
498
- onClick={handleClick}
499
- {...props}
500
- >
556
+ <a href={to} className={finalClassName} onClick={handleClick} {...props}>
501
557
  {children}
502
558
  </a>
503
559
  )
@@ -75,6 +75,7 @@ export interface RouterContext {
75
75
  replace: (path: string, options?: Omit<NavigationOptions, 'replace'>) => void
76
76
  isActive: (path: string, exact?: boolean) => boolean
77
77
  config: RouterConfig
78
+ isReady: boolean
78
79
  }
79
80
 
80
81
  export interface NavigationState {
@@ -122,7 +123,7 @@ export type RouteGenerator = (
122
123
  options: RouteGenerationOptions,
123
124
  ) => Promise<Route[]>
124
125
 
125
- export interface UseRouterReturn extends RouterContext { }
126
+ export interface UseRouterReturn extends RouterContext {}
126
127
 
127
128
  export interface UseNavigationReturn extends NavigationState {
128
129
  navigate: RouterContext['navigate']
package/src/server.ts CHANGED
@@ -1,6 +1,4 @@
1
- export {
2
- Link,
3
- } from './router'
1
+ export { Link } from './router'
4
2
 
5
3
  export {
6
4
  buildSearchString,
@@ -61,19 +59,12 @@ export {
61
59
  watchFileRoutes,
62
60
  } from './router/file-routes'
63
61
 
64
- export {
65
- getRoutePriority,
66
- } from './router/utils'
62
+ export { getRoutePriority } from './router/utils'
67
63
 
68
64
  export { rariRouter } from './router/vite-plugin'
69
65
 
70
- export {
71
- createHttpRuntimeClient,
72
- HttpRuntimeClient,
73
- } from './runtime-client'
66
+ export { createHttpRuntimeClient, HttpRuntimeClient } from './runtime-client'
74
67
 
75
- export type {
76
- RuntimeClient,
77
- } from './runtime-client'
68
+ export type { RuntimeClient } from './runtime-client'
78
69
 
79
70
  export { defineRariConfig, rari } from './vite'
package/src/vite/index.ts CHANGED
@@ -151,7 +151,10 @@ export function rari(options: RariOptions = {}): Plugin[] {
151
151
  }
152
152
  }
153
153
 
154
- function hasTopLevelDirective(code: string, directive: 'use client' | 'use server'): boolean {
154
+ function hasTopLevelDirective(
155
+ code: string,
156
+ directive: 'use client' | 'use server',
157
+ ): boolean {
155
158
  try {
156
159
  const ast = acorn.parse(code, {
157
160
  ecmaVersion: 2024,
@@ -370,44 +373,61 @@ if (import.meta.hot) {
370
373
  config(config: UserConfig, { command }) {
371
374
  config.resolve = config.resolve || {}
372
375
  const existingDedupe = Array.isArray((config.resolve as any).dedupe)
373
- ? (config.resolve as any).dedupe as string[]
376
+ ? ((config.resolve as any).dedupe as string[])
374
377
  : []
375
- const toAdd = ['react', 'react-dom']
376
- ; (config.resolve as any).dedupe = Array.from(
378
+ const toAdd = ['react', 'react-dom'];
379
+ (config.resolve as any).dedupe = Array.from(
377
380
  new Set([...(existingDedupe || []), ...toAdd]),
378
381
  )
379
382
 
380
- const existingAlias: Array<{ find: string | RegExp, replacement: string }>
381
- = Array.isArray((config.resolve as any).alias)
382
- ? (config.resolve as any).alias
383
- : []
383
+ const existingAlias: Array<{
384
+ find: string | RegExp
385
+ replacement: string
386
+ }> = Array.isArray((config.resolve as any).alias)
387
+ ? (config.resolve as any).alias
388
+ : []
384
389
  const aliasFinds = new Set(existingAlias.map(a => String(a.find)))
385
390
  try {
386
391
  const reactPath = require.resolve('react')
387
392
  const reactDomClientPath = require.resolve('react-dom/client')
388
393
  const reactJsxRuntimePath = require.resolve('react/jsx-runtime')
389
- const aliasesToAppend: Array<{ find: string, replacement: string }> = []
394
+ const aliasesToAppend: Array<{ find: string, replacement: string }>
395
+ = []
390
396
  if (!aliasFinds.has('react/jsx-runtime')) {
391
- aliasesToAppend.push({ find: 'react/jsx-runtime', replacement: reactJsxRuntimePath })
397
+ aliasesToAppend.push({
398
+ find: 'react/jsx-runtime',
399
+ replacement: reactJsxRuntimePath,
400
+ })
392
401
  }
393
402
  try {
394
- const reactJsxDevRuntimePath = require.resolve('react/jsx-dev-runtime')
403
+ const reactJsxDevRuntimePath = require.resolve(
404
+ 'react/jsx-dev-runtime',
405
+ )
395
406
  if (!aliasFinds.has('react/jsx-dev-runtime')) {
396
- aliasesToAppend.push({ find: 'react/jsx-dev-runtime', replacement: reactJsxDevRuntimePath })
407
+ aliasesToAppend.push({
408
+ find: 'react/jsx-dev-runtime',
409
+ replacement: reactJsxDevRuntimePath,
410
+ })
397
411
  }
398
412
  }
399
- catch { }
413
+ catch {}
400
414
  if (!aliasFinds.has('react')) {
401
415
  aliasesToAppend.push({ find: 'react', replacement: reactPath })
402
416
  }
403
417
  if (!aliasFinds.has('react-dom/client')) {
404
- aliasesToAppend.push({ find: 'react-dom/client', replacement: reactDomClientPath })
418
+ aliasesToAppend.push({
419
+ find: 'react-dom/client',
420
+ replacement: reactDomClientPath,
421
+ })
405
422
  }
406
423
  if (aliasesToAppend.length > 0) {
407
- (config.resolve as any).alias = [...existingAlias, ...aliasesToAppend]
424
+ (config.resolve as any).alias = [
425
+ ...existingAlias,
426
+ ...aliasesToAppend,
427
+ ]
408
428
  }
409
429
  }
410
- catch { }
430
+ catch {}
411
431
 
412
432
  config.environments = config.environments || {}
413
433
 
@@ -1110,7 +1130,7 @@ const ${componentName} = registerClientReference(
1110
1130
  return { id, external: true }
1111
1131
  }
1112
1132
  }
1113
- catch { }
1133
+ catch {}
1114
1134
  }
1115
1135
 
1116
1136
  return null