@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/dist/index.d.cts CHANGED
@@ -1050,6 +1050,7 @@ declare function configureScrollRestoration(options: ScrollRestorationOptions):
1050
1050
  * Works with Fict's Suspense for loading states.
1051
1051
  */
1052
1052
 
1053
+ type AnyComponent = Component<any>;
1053
1054
  /**
1054
1055
  * Create a lazy-loaded component
1055
1056
  *
@@ -1067,18 +1068,18 @@ declare function configureScrollRestoration(options: ScrollRestorationOptions):
1067
1068
  * </Suspense>
1068
1069
  * ```
1069
1070
  */
1070
- declare function lazy<T extends Component<any>>(loader: () => Promise<{
1071
+ declare function lazy<T extends AnyComponent>(loader: () => Promise<{
1071
1072
  default: T;
1072
- } | T>): Component<any>;
1073
+ } | T>): AnyComponent;
1073
1074
  /**
1074
1075
  * Preload a lazy component
1075
1076
  * Useful for preloading on hover/focus
1076
1077
  */
1077
- declare function preloadLazy(component: Component<any>): Promise<void>;
1078
+ declare function preloadLazy(component: AnyComponent): Promise<void>;
1078
1079
  /**
1079
1080
  * Check if a component is a lazy component
1080
1081
  */
1081
- declare function isLazyComponent(component: unknown): boolean;
1082
+ declare function isLazyComponent(component: unknown): component is AnyComponent;
1082
1083
  /**
1083
1084
  * Create a lazy route definition
1084
1085
  *
@@ -1133,7 +1134,7 @@ declare function lazyRoute<P extends string = string>(config: {
1133
1134
  * ```
1134
1135
  */
1135
1136
  declare function createLazyRoutes(modules: Record<string, () => Promise<{
1136
- default: Component<any>;
1137
+ default: AnyComponent;
1137
1138
  }>>, options?: {
1138
1139
  pathTransform?: (filePath: string) => string;
1139
1140
  loadingElement?: FictNode;
package/dist/index.d.ts CHANGED
@@ -1050,6 +1050,7 @@ declare function configureScrollRestoration(options: ScrollRestorationOptions):
1050
1050
  * Works with Fict's Suspense for loading states.
1051
1051
  */
1052
1052
 
1053
+ type AnyComponent = Component<any>;
1053
1054
  /**
1054
1055
  * Create a lazy-loaded component
1055
1056
  *
@@ -1067,18 +1068,18 @@ declare function configureScrollRestoration(options: ScrollRestorationOptions):
1067
1068
  * </Suspense>
1068
1069
  * ```
1069
1070
  */
1070
- declare function lazy<T extends Component<any>>(loader: () => Promise<{
1071
+ declare function lazy<T extends AnyComponent>(loader: () => Promise<{
1071
1072
  default: T;
1072
- } | T>): Component<any>;
1073
+ } | T>): AnyComponent;
1073
1074
  /**
1074
1075
  * Preload a lazy component
1075
1076
  * Useful for preloading on hover/focus
1076
1077
  */
1077
- declare function preloadLazy(component: Component<any>): Promise<void>;
1078
+ declare function preloadLazy(component: AnyComponent): Promise<void>;
1078
1079
  /**
1079
1080
  * Check if a component is a lazy component
1080
1081
  */
1081
- declare function isLazyComponent(component: unknown): boolean;
1082
+ declare function isLazyComponent(component: unknown): component is AnyComponent;
1082
1083
  /**
1083
1084
  * Create a lazy route definition
1084
1085
  *
@@ -1133,7 +1134,7 @@ declare function lazyRoute<P extends string = string>(config: {
1133
1134
  * ```
1134
1135
  */
1135
1136
  declare function createLazyRoutes(modules: Record<string, () => Promise<{
1136
- default: Component<any>;
1137
+ default: AnyComponent;
1137
1138
  }>>, options?: {
1138
1139
  pathTransform?: (filePath: string) => string;
1139
1140
  loadingElement?: FictNode;
package/dist/index.js CHANGED
@@ -1767,14 +1767,16 @@ function Link(props) {
1767
1767
  if (props.prefetch === "intent" || props.prefetch === void 0) {
1768
1768
  triggerPreload();
1769
1769
  }
1770
- const onMouseEnter = props.onMouseEnter;
1770
+ const propsRecord = props;
1771
+ const onMouseEnter = propsRecord.onMouseEnter;
1771
1772
  if (onMouseEnter) onMouseEnter(event);
1772
1773
  };
1773
1774
  const handleFocus = (event) => {
1774
1775
  if (props.prefetch === "intent" || props.prefetch === void 0) {
1775
1776
  triggerPreload();
1776
1777
  }
1777
- const onFocus = props.onFocus;
1778
+ const propsRecord = props;
1779
+ const onFocus = propsRecord.onFocus;
1778
1780
  if (onFocus) onFocus(event);
1779
1781
  };
1780
1782
  const {
@@ -2310,13 +2312,17 @@ function cleanupDataUtilities() {
2310
2312
  }
2311
2313
 
2312
2314
  // src/lazy.tsx
2313
- import "@fictjs/runtime";
2315
+ import { onCleanup as onCleanup2 } from "@fictjs/runtime";
2314
2316
  import { createSignal as createSignal5 } from "@fictjs/runtime/advanced";
2315
2317
  import { jsx as jsx4 } from "fict/jsx-runtime";
2316
2318
  function lazy(loader) {
2317
2319
  let cachedComponent = null;
2318
2320
  let loadPromise = null;
2319
2321
  const LazyComponent = (props) => {
2322
+ let isMounted = true;
2323
+ onCleanup2(() => {
2324
+ isMounted = false;
2325
+ });
2320
2326
  const state = createSignal5({
2321
2327
  component: cachedComponent,
2322
2328
  error: null,
@@ -2334,9 +2340,13 @@ function lazy(loader) {
2334
2340
  });
2335
2341
  }
2336
2342
  loadPromise.then((component) => {
2337
- state({ component, error: null, loading: false });
2343
+ if (isMounted) {
2344
+ state({ component, error: null, loading: false });
2345
+ }
2338
2346
  }).catch((error) => {
2339
- state({ component: null, error, loading: false });
2347
+ if (isMounted) {
2348
+ state({ component: null, error, loading: false });
2349
+ }
2340
2350
  });
2341
2351
  const currentState = state();
2342
2352
  if (currentState.error) {
@@ -2348,8 +2358,9 @@ function lazy(loader) {
2348
2358
  const LoadedComponent = currentState.component;
2349
2359
  return /* @__PURE__ */ jsx4(LoadedComponent, { ...props });
2350
2360
  };
2351
- LazyComponent.__lazy = true;
2352
- LazyComponent.__preload = () => {
2361
+ const lazyComp = LazyComponent;
2362
+ lazyComp.__lazy = true;
2363
+ lazyComp.__preload = () => {
2353
2364
  if (!loadPromise) {
2354
2365
  loadPromise = loader().then((module) => {
2355
2366
  const component = "default" in module ? module.default : module;
@@ -2369,7 +2380,8 @@ function preloadLazy(component) {
2369
2380
  return Promise.resolve();
2370
2381
  }
2371
2382
  function isLazyComponent(component) {
2372
- return !!(component && typeof component === "function" && component.__lazy);
2383
+ const comp = component;
2384
+ return !!(comp && typeof comp === "function" && comp.__lazy);
2373
2385
  }
2374
2386
  function lazyRoute(config) {
2375
2387
  const LazyComponent = lazy(config.component);