Skip to content

Commit

Permalink
fix: remove devtools in prod (#417)
Browse files Browse the repository at this point in the history
  • Loading branch information
spaenleh authored Nov 4, 2024
1 parent ddc3a56 commit 81d8bf4
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 12 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,5 @@ cypress/videos
!.yarn/releases
!.yarn/sdks
!.yarn/versions

*.tsbuildinfo
8 changes: 3 additions & 5 deletions src/routeTree.gen.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/* prettier-ignore-start */

/* eslint-disable */

// @ts-nocheck

// noinspection JSUnusedGlobalSymbols

// This file is auto-generated by TanStack Router
// This file was automatically generated by TanStack Router.
// You should NOT make any changes in this file as it will be overwritten.
// Additionally, you should also exclude this file from your linter and/or formatter to prevent it from being checked or modified.

// Import Routes

Expand Down Expand Up @@ -214,8 +214,6 @@ export const routeTree = rootRoute
._addFileChildren(rootRouteChildren)
._addFileTypes<FileRouteTypes>()

/* prettier-ignore-end */

/* ROUTE_MANIFEST_START
{
"routes": {
Expand Down
26 changes: 19 additions & 7 deletions src/routes/__root.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import React, { Suspense } from 'react';

import { Stack } from '@mui/material';

import { Outlet, createRootRouteWithContext } from '@tanstack/react-router';
import { TanStackRouterDevtools } from '@tanstack/router-devtools';

import { AuthContextType } from '@/AuthContext';
import { NotFoundComponent } from '@/components/NotFoundComponent';
Expand All @@ -12,16 +13,27 @@ export const Route = createRootRouteWithContext<{ auth: AuthContextType }>()({
notFoundComponent: NotFoundComponent,
});

// this allows to remove the tanstack router dev tools in production
const TanStackRouterDevtools =
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-expect-error
process.env.NODE_ENV === 'production'
? () => null // Render nothing in production
: React.lazy(() =>
// Lazy load in development
import('@tanstack/router-devtools').then((res) => ({
default: res.TanStackRouterDevtools,
})),
);

function RootComponent() {
return (
<Stack id="__root">
<Outlet />
{import.meta.env.MODE !== 'test' && (
<>
<ReactQueryDevtools />
<TanStackRouterDevtools />
</>
)}
{import.meta.env.MODE !== 'test' && <ReactQueryDevtools />}
<Suspense>
<TanStackRouterDevtools />
</Suspense>
</Stack>
);
}

0 comments on commit 81d8bf4

Please sign in to comment.