diff --git a/README.md b/README.md index d84d1f7..fadd671 100644 --- a/README.md +++ b/README.md @@ -284,3 +284,36 @@ This project is based on [fhevmjs](https://github.com/zama-ai/fhevmjs) by Zama a #### Need support? Open an issue or Pull Request on Github! Or reach out to us on [Discord](https://discord.com/invite/FuVgxrvJMY) or Telegram. + +## Using Fhenix.js in Client-Side Frameworks + +Fhenix.js relies on a WebAssembly file (`tfhe_bg.wasm`) which is **client-side only**. +When using frameworks like Next.js, React (Vite), or others, this can cause errors if the WASM file is loaded during SSR (server-side rendering). + +### Next.js Example +```javascript +import dynamic from 'next/dynamic'; + +const Token = dynamic(() => import('../components/token'), { ssr: false }); + +Vite + React Example +// vite.config.js +import { defineConfig } from 'vite'; +import react from '@vitejs/plugin-react'; +import wasm from 'vite-plugin-wasm'; +import topLevelAwait from 'vite-plugin-top-level-await'; + +export default defineConfig({ + plugins: [wasm(), topLevelAwait(), react()], + optimizeDeps: { exclude: ['fhenixjs'] }, +}); + +Alternative +Use the UMD build directly via a + +Notes +Always use Fhenix.js on the client side for user interactions. +Avoid importing it directly in SSR code. + +---