pmndrs / swc-jotai

MIT License
90 stars 14 forks source link

@swc-jotai/react-refresh, jotai-optics and turbopack cannot work together #20

Closed yf-yang closed 2 months ago

yf-yang commented 8 months ago

reproduction: https://github.com/yf-yang/turbopack-swc-jotai-bug

This bug only happens when turbopack is enabled

pnpm dev --turbo # with turbopack enabled

When calling

const n = globalThis.jotaiAtomCache.get("index.modern.js/n", t());

Output:

Uncaught ReferenceError: t is not defined

I have no idea what that t() is, @Thisen do you have any ideas?

yf-yang commented 8 months ago

Emmm, may not be an issue with turbopack, maybe that's something after upgrading to next14. I am not sure what they do with the bundler when upgrading from 13.5 to 14. I guess something are replaced with swc implementations.

Thisen commented 2 months ago

Hi there!

Thanks for this.

Can you provide a reproduction with latest release of the packages?

Cielquan commented 2 months ago

After updating the dependencies in the Reproduction-Repo from my duplicate issue https://github.com/pmndrs/swc-jotai/issues/24 the error is gone. I did not cross-test what single update fixed the issue for my case.

Here is the update diff from pnpm:

dependencies:
- @swc-jotai/react-refresh 0.1.0
+ @swc-jotai/react-refresh 0.1.1
- jotai 2.6.4
+ jotai 2.8.3
- jotai-optics 0.3.1
+ jotai-optics 0.4.0
- next 14.1.0
+ next 14.2.4
- react 18.2.0
+ react 18.3.1
- react-dom 18.2.0
+ react-dom 18.3.1

devDependencies:
- @types/node 20.11.14
+ @types/node 20.14.5
- @types/react 18.2.49
+ @types/react 18.3.3
- @types/react-dom 18.2.18
+ @types/react-dom 18.3.0
- autoprefixer 10.4.17
+ autoprefixer 10.4.19
- postcss 8.4.33
+ postcss 8.4.38
- tailwindcss 3.4.1
+ tailwindcss 3.4.4

EDIT: I reenabled the plugin in my full application and the "t-Error" is gone there too. But it seems that the atoms are reset on refresh or something, but that would be another topic and I need to check if I am not the root cause.