-
Notifications
You must be signed in to change notification settings - Fork 36
No atoms found when lazy loading #212
Copy link
Copy link
Open
Description
I have this pattern I use for DevTools extensions - I load based on environment variables (which i validate with zod). I've noticed that when I do this, the extension loads file, but I get no atoms. As soon as I move it out of the lazy, I can see it does work and find all atoms
import React, { Suspense } from "react";
import { env } from "#env.ts";
import { jotaiStore } from "#store/atoms/jotaiStore.ts";
const LazyDevTools =
import.meta.env.PROD || !env.enableJotaiDevtools
? () => null
: React.lazy(() =>
Promise.all([
import("jotai-devtools"),
import("jotai-devtools/styles.css?inline"),
]).then(([{ DevTools }, jotaiCss]) => ({
default: () => {
return (
<>
<style>{jotaiCss.default}</style>
<DevTools
store={jotaiStore}
position="bottom-right"
theme="dark"
options={{
// It defaults to infinity which will cause the extension to crash when storing a lot of data
snapshotHistoryLimit: 30,
}}
/>
</>
);
},
})),
);
export const JotaiDevTools = () => (
<Suspense fallback={null}>
<LazyDevTools store={jotaiStore} />
</Suspense>
);Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels