clear-react-router 1.8.6 → 1.8.8

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.
package/README.md CHANGED
@@ -88,7 +88,7 @@ Normalizes route configuration. Extracts dynamic params, builds nested paths.
88
88
 
89
89
  ### `Link`
90
90
 
91
- Component for client-side navigation with prefetch support, active state detection, and pending state styling.
91
+ Component for client-side navigation with prefetch support, active state detection, and pending state styling. Prefetch includes lazy route component preload.
92
92
 
93
93
  | Prop | Type | Default | Description |
94
94
  |------|------|---------|-------------|
package/dist/index.js CHANGED
@@ -165,22 +165,29 @@ var import_jsx_runtime = (/* @__PURE__ */ __commonJSMin(((exports, module) => {
165
165
  module.exports = require_react_jsx_runtime_production();
166
166
  })))();
167
167
  var createLazyComponent = (importFn, fallback) => {
168
- const LazyComp = lazy(() => importFn().then((module) => ({ default: module.default || module })));
169
- return () => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Suspense, {
168
+ const load = () => importFn().then((module) => ({ default: module.default || module }));
169
+ const LazyComp = lazy(load);
170
+ const Component = () => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Suspense, {
170
171
  fallback: typeof fallback === "function" ? fallback() : fallback || null,
171
172
  children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(LazyComp, {})
172
173
  });
174
+ return {
175
+ Component,
176
+ preloadElement: load
177
+ };
173
178
  };
174
179
  //#endregion
175
180
  //#region utils/utils.ts
176
181
  var isLazy = (el) => typeof el.element === "function" && el.element.toString().includes("import(");
177
182
  var parseClientRouteItem = (el, parentPattern = "") => {
178
183
  const pattern = `${parentPattern}/${el.path}`.replace(/\/+/g, "/");
179
- const resolvedElement = isLazy(el) ? createLazyComponent(el.element, el.fallback) : el.element;
184
+ const preloadElement = isLazy(el) ? createLazyComponent(el.element, el.fallback).preloadElement : void 0;
185
+ const resolvedElement = isLazy(el) ? createLazyComponent(el.element, el.fallback).Component : el.element;
180
186
  return [{
181
187
  ...el,
182
188
  pattern,
183
- element: resolvedElement
189
+ element: resolvedElement,
190
+ preloadElement
184
191
  }, ...el.children?.flatMap((child) => parseClientRouteItem(child, pattern)) ?? []];
185
192
  };
186
193
  var createRouter = (clientList) => clientList.flatMap((el) => parseClientRouteItem(el));
@@ -360,10 +367,13 @@ var createInvalidate = ({ routeItemDataState, loaderStateRef, timestampMap, curr
360
367
  //#region runtime/prefetch.ts
361
368
  var createPrefetch = (revalidateCache) => async (pathname) => {
362
369
  const item = findRoute(pathname);
363
- if (item) await revalidateCache({
364
- routeItem: item,
365
- pathname
366
- });
370
+ if (item) {
371
+ await item.preloadElement?.();
372
+ await revalidateCache({
373
+ routeItem: item,
374
+ pathname
375
+ });
376
+ }
367
377
  };
368
378
  //#endregion
369
379
  //#region utils/revalidateCache.ts
@@ -396,7 +406,10 @@ var createRevalidateCache = (routerState) => {
396
406
  if (isCacheItemFresh({
397
407
  routeItem,
398
408
  pathname
399
- })) loaderStateRef.set(loaderMapRef[pathname]);
409
+ })) {
410
+ loaderStateRef.set(loaderMapRef[pathname]);
411
+ return;
412
+ }
400
413
  const promise = (async () => {
401
414
  if (!routeItem?.loader) return;
402
415
  try {
package/dist/types.d.ts CHANGED
@@ -42,6 +42,9 @@ export type RouteItem = ClientRouteItem & {
42
42
  element: RenderElement;
43
43
  pattern: string;
44
44
  cacheTimestamp?: number;
45
+ preloadElement?(): Promise<{
46
+ default: ComponentType<unknown>;
47
+ }>;
45
48
  };
46
49
  export type Location = {
47
50
  pathname: string;
@@ -1,4 +1,9 @@
1
1
  import { type ComponentType, type ReactElement } from 'react';
2
2
  export declare const createLazyComponent: (importFn: () => Promise<{
3
3
  default: ComponentType<unknown>;
4
- }>, fallback?: ReactElement | (() => ReactElement)) => (() => ReactElement);
4
+ }>, fallback?: ReactElement | (() => ReactElement)) => {
5
+ Component: () => import("react/jsx-runtime").JSX.Element;
6
+ preloadElement: () => Promise<{
7
+ default: ComponentType<unknown>;
8
+ }>;
9
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "clear-react-router",
3
- "version": "1.8.6",
3
+ "version": "1.8.8",
4
4
  "description": "A lightweight, type-safe routing library for React applications",
5
5
  "author": "Andrew Bubnov",
6
6
  "scripts": {