From b397776e475566bf8a1e7bc801401c78174b5cd4 Mon Sep 17 00:00:00 2001 From: oedotme Date: Wed, 7 Dec 2022 23:45:36 +0200 Subject: [PATCH] feat: add null fallback for integrations elements/loaders/actions --- src/react-location.tsx | 4 ++-- src/react-router.tsx | 6 +++--- src/solid-router.tsx | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/react-location.tsx b/src/react-location.tsx index 8ad4a32..fcc0ed2 100644 --- a/src/react-location.tsx +++ b/src/react-location.tsx @@ -14,8 +14,8 @@ const preservedRoutes = generatePreservedRoutes(PRESERVED) const regularRoutes = generateRegularRoutes Promise>(ROUTES, (module) => ({ element: () => module().then((mod) => (mod?.default ? : <>)), loader: async (...args) => module().then((mod) => mod?.Loader?.(...args)), - pendingElement: async () => module().then((mod) => (mod?.Pending ? : null)), - errorElement: async () => module().then((mod) => (mod?.Failure ? : null)), + pendingElement: () => module().then((mod) => (mod?.PendingElement ? : null)), + errorElement: () => module().then((mod) => (mod?.ErrorElement ? : null)), })) const App = preservedRoutes?.['_app'] || Fragment diff --git a/src/react-router.tsx b/src/react-router.tsx index c105c2c..548df85 100644 --- a/src/react-router.tsx +++ b/src/react-router.tsx @@ -14,14 +14,14 @@ const preservedRoutes = generatePreservedRoutes(PRESERVED) const regularRoutes = generateRegularRoutes Promise>(ROUTES, (module, key) => { const Element = lazy(module) - const ErrorElement = lazy(() => module().then((module) => ({ default: module.ErrorElement }))) + const ErrorElement = lazy(() => module().then((module) => ({ default: module.ErrorElement || null }))) const index = /(?} />, - loader: async (...args) => module().then((mod) => mod?.Loader?.(...args)), - action: async (...args) => module().then((mod) => mod?.Action?.(...args)), + loader: (...args) => module().then((mod) => mod?.Loader?.(...args) || null), + action: (...args) => module().then((mod) => mod?.Action?.(...args) || null), errorElement: } />, } }) diff --git a/src/solid-router.tsx b/src/solid-router.tsx index f2fd36c..287c57d 100644 --- a/src/solid-router.tsx +++ b/src/solid-router.tsx @@ -14,7 +14,7 @@ const preservedRoutes = generatePreservedRoutes(PRESERVED) const regularRoutes = generateRegularRoutes Promise>(ROUTES, (module) => ({ component: lazy(module), - data: async (args: RouteDataFuncArgs) => module().then((mod) => mod?.Loader?.(args)), + data: (args: RouteDataFuncArgs) => module().then((mod) => mod?.Loader?.(args) || null), })) const Fragment = (props: ParentProps) => <>{props.children}