Use custom lazy for loading components

Signed-off-by: Bryan Frimin <bryan@getprobo.com>
Signed-off-by: Sacha Al Himdani <sacha@getprobo.com>
This commit is contained in:
Jonathan
2025-06-11 18:39:11 +02:00
committed by Sacha Al Himdani
parent 1ba61f691e
commit e1b63b59a6
13 changed files with 47 additions and 43 deletions

View File

@@ -1,14 +1,18 @@
{
"name": "@probo/react-lazy",
"version": "0.1.0",
"description": "Enhanced React lazy loading with retries and error handling",
"type": "module",
"main": "src/index.ts",
"exports": {
".": "./src/index.ts"
},
"license": "MIT",
"peerDependencies": {
"react": ">=16.8.0"
}
"name": "@probo/react-lazy",
"version": "1.0.0",
"description": "Enhanced React lazy loading with retries and error handling",
"private": true,
"type": "module",
"main": "src/index.ts",
"scripts": {},
"prettier": "@probo/prettier",
"peerDependencies": {
"react": ">18.0.0"
},
"eslintConfig": {
"extends": [
"plugin:storybook/recommended"
]
}
}

View File

@@ -5,9 +5,9 @@ import {
type FC,
} from "react";
export const DEFAULT_STORAGE_KEY = "reactLazyReloadedFunctions";
const DEFAULT_STORAGE_KEY = "reactLazyReloadedFunctions";
export class ReloadStorage {
class ReloadStorage {
constructor(public readonly storageKey = DEFAULT_STORAGE_KEY) {}
getMap(): Map<string, number> {
@@ -51,24 +51,24 @@ export class ReloadStorage {
}
}
export interface ForceReloadConfig {
type ForceReloadConfig = {
maxRetries: number;
storageKey?: string;
}
};
export interface LazyConfigInit {
type LazyConfigInit = {
forceReload?: false | Partial<ForceReloadConfig>;
importRetries?: number;
retryDelay?: number;
onImportError?: (error: unknown) => void;
}
};
export interface LazyConfig {
type LazyConfig = {
forceReload: ForceReloadConfig;
importRetries: number;
retryDelay: number;
onImportError?: (error: unknown) => void;
}
};
const createConfig = (init: LazyConfigInit = {}): LazyConfig => ({
forceReload: {
@@ -77,8 +77,8 @@ const createConfig = (init: LazyConfigInit = {}): LazyConfig => ({
...(typeof init.forceReload === "object"
? init.forceReload
: init.forceReload === false
? { maxRetries: 0 }
: {}),
? { maxRetries: 0 }
: {}),
},
importRetries:
typeof init.importRetries === "number"