Skip to content

Commit

Permalink
feat: add null fallback for integrations elements/loaders/actions
Browse files Browse the repository at this point in the history
  • Loading branch information
oedotme committed Dec 7, 2022
1 parent 878d33e commit b397776
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/react-location.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ const preservedRoutes = generatePreservedRoutes<Element>(PRESERVED)
const regularRoutes = generateRegularRoutes<Route, () => Promise<Module>>(ROUTES, (module) => ({
element: () => module().then((mod) => (mod?.default ? <mod.default /> : <></>)),
loader: async (...args) => module().then((mod) => mod?.Loader?.(...args)),
pendingElement: async () => module().then((mod) => (mod?.Pending ? <mod.Pending /> : null)),
errorElement: async () => module().then((mod) => (mod?.Failure ? <mod.Failure /> : null)),
pendingElement: () => module().then((mod) => (mod?.PendingElement ? <mod.PendingElement /> : null)),
errorElement: () => module().then((mod) => (mod?.ErrorElement ? <mod.ErrorElement /> : null)),
}))

const App = preservedRoutes?.['_app'] || Fragment
Expand Down
6 changes: 3 additions & 3 deletions src/react-router.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ const preservedRoutes = generatePreservedRoutes<Element>(PRESERVED)

const regularRoutes = generateRegularRoutes<RouteObject, () => Promise<Module>>(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 = /(?<!pages\/)index\.(jsx|tsx)$/.test(key) ? { index: true } : {}

return {
...index,
element: <Suspense fallback={null} children={<Element />} />,
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: <Suspense fallback={null} children={<ErrorElement />} />,
}
})
Expand Down
2 changes: 1 addition & 1 deletion src/solid-router.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const preservedRoutes = generatePreservedRoutes<Component>(PRESERVED)

const regularRoutes = generateRegularRoutes<Route, () => Promise<Module>>(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}</>
Expand Down

0 comments on commit b397776

Please sign in to comment.