Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enable @swc-jotai/react-refresh in [email protected] will cause pages using 'use client' error #21

Open
seiry opened this issue Jan 16, 2024 · 4 comments

Comments

@seiry
Copy link

seiry commented Jan 16, 2024

reproduce step

  1. init a new next.js repo
  2. install jotai and @swc-jotai/react-refresh
  3. enable @swc-jotai/react-refresh in next.config.js
  4. add a jotai atom in a page with 'use client'
  5. get the error

reproduce repo

https://github.com/seiry/jotai-refresh-use-client/blob/e2f069f9761f35c75d23a9e71f6a13a279275e9a/next.config.js#L6

log

./app/page.tsx
ReactServerComponentsError:

The "use client" directive must be placed before other expressions. Move it to the top of the file to resolve this issue.

   ╭─[/Users/seiry/gitwork/jotai-refresh-use-client/app/page.tsx:1:1]
 1 │ 'use client'
   · ────────────
 2 │ import { atom, useAtom } from 'jotai'
 3 │ 
 4 │ const valueAtom = atom('hello')
   ╰────

Import path:
  ./app/page.tsx

It seems the plugin added some line at the file header.( sorry I'm not a rust master lol

@trevorpfiz
Copy link

I am getting this error as well. Next.js 14.1.0 and @swc-jotai/react-refresh.

Development experience with all the full reloads is not great 🤣

@McCulloughRT
Copy link

I'm getting this error in Next.js 14.1.0 and @swc-jotai/react-refresh as well. Agreed it seems the plugin is adding lines above the "use client" directive, causing Next.js problems. Also agreed that my knowledge of Rust is not enough to assist in fixing this, just wanted to raise another flag that something is amiss.

@BrandenXia
Copy link

I also got the same problem with Next.js 14.1.0 and @swc-jotai/react-refresh. Is there any temporary solution to this?

@Cielquan
Copy link

Cielquan commented Feb 8, 2024

I had my atoms in a seperate file and it worked. Just don't add "use client" to the atom file but just the componet file and import the atoms. Worked for me until I started using focusAtom which caused another issue: #24. So currently I forcibly stopped using the plugin.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants