diff --git a/README.md b/README.md index a46a6cb..56ff41f 100644 --- a/README.md +++ b/README.md @@ -133,6 +133,7 @@ Run [demo application](./demo/app) in development mode to test [react-bndl libra #### Scripts - `start`: Starts development server and builds demo application in development mode +- `start`: Starts development server only - `build:lib`: Create production distribution that exports a CommonJS and ESM version of the react-bndl library - `build:app`: Create a production bundle of the demo application - `fix:lint`: Attempt to fix any lint errors diff --git a/demo/app/main/src/examples/ExampleHook.tsx b/demo/app/main/src/examples/ExampleHook.tsx index 8bca343..9c0adf0 100644 --- a/demo/app/main/src/examples/ExampleHook.tsx +++ b/demo/app/main/src/examples/ExampleHook.tsx @@ -12,7 +12,7 @@ export const ExampleHook = () => { <> {(isLoading && !data) ?
Loading
: - (!isLoading && error) ? + (error || (!isLoading && !data)) ?
{error.message}
: Dynamic Component diff --git a/lib/src/component/BundleComponent.tsx b/lib/src/component/BundleComponent.tsx index 692109d..9767ded 100644 --- a/lib/src/component/BundleComponent.tsx +++ b/lib/src/component/BundleComponent.tsx @@ -44,7 +44,7 @@ export function BundleComponent({ path, name, component, children, LoaderCompone if (isLoading && !data) return renderLoader(); - if (error || !data && !isLoading) + if (error || (!data && !isLoading)) return renderError(error); else return ( diff --git a/lib/src/hook/hook.ts b/lib/src/hook/hook.ts index e15887e..584eb53 100644 --- a/lib/src/hook/hook.ts +++ b/lib/src/hook/hook.ts @@ -25,7 +25,8 @@ interface IStatus { export const bundles = new Map(); export function useBundle({ path, name, component }:IProps) { - const [status, setStatus] = React.useState({ isLoading: false, error: null, data: null }); + const bundleExists = bundles.get(name); + const [status, setStatus] = React.useState({ isLoading: !bundleExists, error: null, data: null }); const scope = getScope(); diff --git a/package.json b/package.json index a3d8e8b..71974e8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "react-bndl", - "version": "1.0.1", + "version": "1.0.2", "description": "A library that allows users to split their React application into multiple bundles and load them each dynamically.", "keywords": [ "React", @@ -32,6 +32,7 @@ }, "scripts": { "start": "pnpm --filter @bndl/demo run start", + "start:server": "pnpm --filter @bndl/demo run start:server", "build:lib": "pnpm --filter @bndl/lib run build", "build:app": "pnpm --filter @bndl/demo run build:prod", "fix:lint": "pnpm --filter @bndl/* run fix:lint",