@fictjs/router 0.5.0 → 0.5.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.
- package/README.md +1 -1
- package/dist/index.cjs +19 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +6 -5
- package/dist/index.d.ts +6 -5
- package/dist/index.js +20 -8
- package/dist/index.js.map +1 -1
- package/package.json +5 -5
- package/src/lazy.tsx +29 -14
- package/src/link.tsx +4 -2
package/README.md
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -1863,14 +1863,16 @@ function Link(props) {
|
|
|
1863
1863
|
if (props.prefetch === "intent" || props.prefetch === void 0) {
|
|
1864
1864
|
triggerPreload();
|
|
1865
1865
|
}
|
|
1866
|
-
const
|
|
1866
|
+
const propsRecord = props;
|
|
1867
|
+
const onMouseEnter = propsRecord.onMouseEnter;
|
|
1867
1868
|
if (onMouseEnter) onMouseEnter(event);
|
|
1868
1869
|
};
|
|
1869
1870
|
const handleFocus = (event) => {
|
|
1870
1871
|
if (props.prefetch === "intent" || props.prefetch === void 0) {
|
|
1871
1872
|
triggerPreload();
|
|
1872
1873
|
}
|
|
1873
|
-
const
|
|
1874
|
+
const propsRecord = props;
|
|
1875
|
+
const onFocus = propsRecord.onFocus;
|
|
1874
1876
|
if (onFocus) onFocus(event);
|
|
1875
1877
|
};
|
|
1876
1878
|
const {
|
|
@@ -2413,6 +2415,10 @@ function lazy(loader) {
|
|
|
2413
2415
|
let cachedComponent = null;
|
|
2414
2416
|
let loadPromise = null;
|
|
2415
2417
|
const LazyComponent = (props) => {
|
|
2418
|
+
let isMounted = true;
|
|
2419
|
+
(0, import_runtime6.onCleanup)(() => {
|
|
2420
|
+
isMounted = false;
|
|
2421
|
+
});
|
|
2416
2422
|
const state = (0, import_advanced5.createSignal)({
|
|
2417
2423
|
component: cachedComponent,
|
|
2418
2424
|
error: null,
|
|
@@ -2430,9 +2436,13 @@ function lazy(loader) {
|
|
|
2430
2436
|
});
|
|
2431
2437
|
}
|
|
2432
2438
|
loadPromise.then((component) => {
|
|
2433
|
-
|
|
2439
|
+
if (isMounted) {
|
|
2440
|
+
state({ component, error: null, loading: false });
|
|
2441
|
+
}
|
|
2434
2442
|
}).catch((error) => {
|
|
2435
|
-
|
|
2443
|
+
if (isMounted) {
|
|
2444
|
+
state({ component: null, error, loading: false });
|
|
2445
|
+
}
|
|
2436
2446
|
});
|
|
2437
2447
|
const currentState = state();
|
|
2438
2448
|
if (currentState.error) {
|
|
@@ -2444,8 +2454,9 @@ function lazy(loader) {
|
|
|
2444
2454
|
const LoadedComponent = currentState.component;
|
|
2445
2455
|
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(LoadedComponent, { ...props });
|
|
2446
2456
|
};
|
|
2447
|
-
|
|
2448
|
-
|
|
2457
|
+
const lazyComp = LazyComponent;
|
|
2458
|
+
lazyComp.__lazy = true;
|
|
2459
|
+
lazyComp.__preload = () => {
|
|
2449
2460
|
if (!loadPromise) {
|
|
2450
2461
|
loadPromise = loader().then((module2) => {
|
|
2451
2462
|
const component = "default" in module2 ? module2.default : module2;
|
|
@@ -2465,7 +2476,8 @@ function preloadLazy(component) {
|
|
|
2465
2476
|
return Promise.resolve();
|
|
2466
2477
|
}
|
|
2467
2478
|
function isLazyComponent(component) {
|
|
2468
|
-
|
|
2479
|
+
const comp = component;
|
|
2480
|
+
return !!(comp && typeof comp === "function" && comp.__lazy);
|
|
2469
2481
|
}
|
|
2470
2482
|
function lazyRoute(config) {
|
|
2471
2483
|
const LazyComponent = lazy(config.component);
|