Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -194,11 +194,14 @@ and is replaced it with native CSS.
2. Replace `@emotion/react` with `jotai-devtools/styles.css` in your code

Note that this css file may get included in your production builds please import
it conditionally if you want to avoid that.
it conditionally if you want to avoid that, e.g.:

```diff
import { DevTools } from 'jotai-devtools';
+ import 'jotai-devtools/styles.css';
+
+ if (process.env.NODE_ENV === 'development') {
+ require('jotai-devtools/styles.css')
Copy link
Copy Markdown
Member

@arjunvegda arjunvegda May 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR! I'm not sure if I'd recommend using require due to its limited support 🤔

What about lazy loading the component like this 👇? Would that for Next.Js?

const LazyDevtools = lazy(() =>
  import("./JotaiDevtools").then((module) => ({
    default: module.DevTools,
  }))
);

export const YourApp = () => {
  return (
    <Suspense fallback="">
      { process.env.NODE_ENV === "development" ?  <LazyDevtools/> : null }
    </Suspense>
  );
}

In ./JotaiDevTools.tsx

import "jotai-devtools/styles.css";
export { DevTools } from "jotai-devtools";

**Vite users could do something like this 👇 **

import { DevTools } from "jotai-devtools";
import css from "jotai-devtools/styles.css?inline";

export const JotaiDevTools = () =>
  process.env.NODE_ENV !== "production" ? (
    <>
      <style>{css}</style>
      <DevTools />
    </>
  ) : null;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

However, for some reason when I do this the build file turns out to be MUCH larger.

@npearson72 - Thanks for reporting. That seems strange! 🤔 Works fine on my end (see screenshot below). Could you create a small repro?

Group 1854

Copy link
Copy Markdown

@npearson72 npearson72 May 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@arjunvegda have you looked at jotai-devtools/dist/index.css?

It has all the mantine styles in it. I'm assuming you wanted those to live in jotai-devtools/dist/internal__devtools.css, but perhaps I've misunderstood.

In any case, it seems v0.8.0, which is using Mantine 6x which is not having this issue. But all later versions do.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah! you're missing process.env.NODE_ENV !== "production" check in DevTools.tsx#L4.

See the full code in the above comment.

Copy link
Copy Markdown

@npearson72 npearson72 May 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I see. I didn't realize that process.env was available in the Vite UI, but that make sense. Thank you.

+ }
```

### Migrate Jotai to V2
Expand Down