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

@@ -11,7 +11,7 @@
"typecheck": "npx tsc --noEmit" "typecheck": "npx tsc --noEmit"
}, },
"dependencies": { "dependencies": {
"@probo/react-lazy": "^0.1.0", "@probo/react-lazy": "1.0.0",
"@probo/vendors": "^0.0.1", "@probo/vendors": "^0.0.1",
"@radix-ui/colors": "^3.0.0", "@radix-ui/colors": "^3.0.0",
"@radix-ui/react-avatar": "^1.1.3", "@radix-ui/react-avatar": "^1.1.3",

View File

@@ -16,6 +16,7 @@
"@probo/helpers": "1.0.0", "@probo/helpers": "1.0.0",
"@probo/hooks": "1.0.0", "@probo/hooks": "1.0.0",
"@probo/i18n": "1.0.0", "@probo/i18n": "1.0.0",
"@probo/react-lazy": "1.0.0",
"@probo/ui": "1.0.0", "@probo/ui": "1.0.0",
"@probo/vendors": "0.0.1", "@probo/vendors": "0.0.1",
"@radix-ui/react-dialog": "^1.1.14", "@radix-ui/react-dialog": "^1.1.14",

View File

@@ -8,13 +8,7 @@ import {
} from "react-router"; } from "react-router";
import { MainLayout } from "./layouts/MainLayout"; import { MainLayout } from "./layouts/MainLayout";
import { AuthLayout, CenteredLayout, CenteredLayoutSkeleton } from "@probo/ui"; import { AuthLayout, CenteredLayout, CenteredLayoutSkeleton } from "@probo/ui";
import { import { Fragment, Suspense, type FC, type LazyExoticComponent } from "react";
Fragment,
lazy,
Suspense,
type FC,
type LazyExoticComponent,
} from "react";
import { import {
relayEnvironment, relayEnvironment,
UnAuthenticatedError, UnAuthenticatedError,
@@ -31,8 +25,9 @@ import { peopleRoutes } from "./routes/peopleRoutes.ts";
import { frameworkRoutes } from "./routes/frameworkRoutes.ts"; import { frameworkRoutes } from "./routes/frameworkRoutes.ts";
import { PageError } from "./components/PageError.tsx"; import { PageError } from "./components/PageError.tsx";
import { taskRoutes } from "./routes/taskRoutes.ts"; import { taskRoutes } from "./routes/taskRoutes.ts";
import { lazy } from "@probo/react-lazy";
function ErrorBoundary(props) { function ErrorBoundary() {
const error = useRouteError(); const error = useRouteError();
if (error instanceof UnAuthenticatedError) { if (error instanceof UnAuthenticatedError) {

View File

@@ -1,4 +1,4 @@
import { Fragment, lazy } from "react"; import { Fragment } from "react";
import { loadQuery } from "react-relay"; import { loadQuery } from "react-relay";
import type { AppRoute } from "/routes.tsx"; import type { AppRoute } from "/routes.tsx";
import { relayEnvironment } from "/providers/RelayProviders"; import { relayEnvironment } from "/providers/RelayProviders";
@@ -6,6 +6,7 @@ import { documentsQuery } from "/hooks/graph/DocumentGraph";
import { documentNodeQuery } from "/hooks/graph/DocumentGraph"; import { documentNodeQuery } from "/hooks/graph/DocumentGraph";
import { PageSkeleton } from "/components/skeletons/PageSkeleton"; import { PageSkeleton } from "/components/skeletons/PageSkeleton";
import { redirect } from "react-router"; import { redirect } from "react-router";
import { lazy } from "@probo/react-lazy";
export const documentsRoutes = [ export const documentsRoutes = [
{ {

View File

@@ -6,7 +6,8 @@ import {
frameworkNodeQuery, frameworkNodeQuery,
} from "/hooks/graph/FrameworkGraph"; } from "/hooks/graph/FrameworkGraph";
import type { AppRoute } from "/routes"; import type { AppRoute } from "/routes";
import { Fragment, lazy } from "react"; import { Fragment } from "react";
import { lazy } from "@probo/react-lazy";
export const frameworkRoutes = [ export const frameworkRoutes = [
{ {

View File

@@ -1,10 +1,11 @@
import { Fragment, lazy } from "react"; import { Fragment } from "react";
import { loadQuery } from "react-relay"; import { loadQuery } from "react-relay";
import type { AppRoute } from "/routes.tsx"; import type { AppRoute } from "/routes.tsx";
import { relayEnvironment } from "/providers/RelayProviders"; import { relayEnvironment } from "/providers/RelayProviders";
import { measureNodeQuery, measuresQuery } from "/hooks/graph/MeasureGraph"; import { measureNodeQuery, measuresQuery } from "/hooks/graph/MeasureGraph";
import { PageSkeleton } from "/components/skeletons/PageSkeleton"; import { PageSkeleton } from "/components/skeletons/PageSkeleton";
import { redirect } from "react-router"; import { redirect } from "react-router";
import { lazy } from "@probo/react-lazy";
export const measureRoutes = [ export const measureRoutes = [
{ {

View File

@@ -1,4 +1,4 @@
import { lazy } from "react"; import { lazy } from "@probo/react-lazy";
import { loadQuery } from "react-relay"; import { loadQuery } from "react-relay";
import type { AppRoute } from "/routes.tsx"; import type { AppRoute } from "/routes.tsx";
import { relayEnvironment } from "/providers/RelayProviders"; import { relayEnvironment } from "/providers/RelayProviders";

View File

@@ -1,11 +1,12 @@
import { Fragment, lazy } from "react"; import { Fragment } from "react";
import { loadQuery } from "react-relay"; import { loadQuery } from "react-relay";
import { RisksPageSkeleton } from "/components/skeletons/RisksPageSkeleton.tsx"; import { RisksPageSkeleton } from "/components/skeletons/RisksPageSkeleton.tsx";
import type { AppRoute } from "/routes.tsx"; import type { AppRoute } from "/routes.tsx";
import { relayEnvironment } from "/providers/RelayProviders"; import { relayEnvironment } from "/providers/RelayProviders";
import { riskNodeQuery, risksQuery } from "/hooks/graph/RiskGraph"; import { riskNodeQuery, risksQuery } from "/hooks/graph/RiskGraph";
import { PageSkeleton } from "/components/skeletons/PageSkeleton.tsx"; import { PageSkeleton } from "/components/skeletons/PageSkeleton";
import { redirect } from "react-router"; import { redirect } from "react-router";
import { lazy } from "@probo/react-lazy";
export const riskRoutes = [ export const riskRoutes = [
{ {

View File

@@ -1,4 +1,4 @@
import { lazy } from "react"; import { lazy } from "@probo/react-lazy";
import { PageSkeleton } from "/components/skeletons/PageSkeleton"; import { PageSkeleton } from "/components/skeletons/PageSkeleton";
import { loadQuery } from "react-relay"; import { loadQuery } from "react-relay";
import { relayEnvironment } from "/providers/RelayProviders"; import { relayEnvironment } from "/providers/RelayProviders";

View File

@@ -1,4 +1,4 @@
import { lazy } from "react"; import { lazy } from "@probo/react-lazy";
import { loadQuery } from "react-relay"; import { loadQuery } from "react-relay";
import type { AppRoute } from "/routes.tsx"; import type { AppRoute } from "/routes.tsx";
import { relayEnvironment } from "/providers/RelayProviders"; import { relayEnvironment } from "/providers/RelayProviders";

8
package-lock.json generated
View File

@@ -21,7 +21,7 @@
"name": "@probo/console", "name": "@probo/console",
"version": "0.0.1", "version": "0.0.1",
"dependencies": { "dependencies": {
"@probo/react-lazy": "^0.1.0", "@probo/react-lazy": "1.0.0",
"@probo/vendors": "^0.0.1", "@probo/vendors": "^0.0.1",
"@radix-ui/colors": "^3.0.0", "@radix-ui/colors": "^3.0.0",
"@radix-ui/react-avatar": "^1.1.3", "@radix-ui/react-avatar": "^1.1.3",
@@ -229,6 +229,7 @@
"@probo/helpers": "1.0.0", "@probo/helpers": "1.0.0",
"@probo/hooks": "1.0.0", "@probo/hooks": "1.0.0",
"@probo/i18n": "1.0.0", "@probo/i18n": "1.0.0",
"@probo/react-lazy": "1.0.0",
"@probo/ui": "1.0.0", "@probo/ui": "1.0.0",
"@probo/vendors": "0.0.1", "@probo/vendors": "0.0.1",
"@radix-ui/react-dialog": "^1.1.14", "@radix-ui/react-dialog": "^1.1.14",
@@ -14693,10 +14694,9 @@
}, },
"packages/react-lazy": { "packages/react-lazy": {
"name": "@probo/react-lazy", "name": "@probo/react-lazy",
"version": "0.1.0", "version": "1.0.0",
"license": "MIT",
"peerDependencies": { "peerDependencies": {
"react": ">=16.8.0" "react": ">18.0.0"
} }
}, },
"packages/tsconfig": { "packages/tsconfig": {

View File

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

View File

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