clear-react-router 1.8.6 → 1.8.7
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 +1 -1
- package/dist/index.js +18 -8
- package/dist/types.d.ts +3 -0
- package/dist/utils/createLazyComponent.d.ts +6 -1
- package/package.json +1 -1
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
|
|
169
|
-
|
|
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
|
|
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)
|
|
364
|
-
|
|
365
|
-
|
|
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
|
package/dist/types.d.ts
CHANGED
|
@@ -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)) =>
|
|
4
|
+
}>, fallback?: ReactElement | (() => ReactElement)) => {
|
|
5
|
+
Component: () => import("react/jsx-runtime").JSX.Element;
|
|
6
|
+
preloadElement: () => Promise<{
|
|
7
|
+
default: ComponentType<unknown>;
|
|
8
|
+
}>;
|
|
9
|
+
};
|