react-native-mmkv icon indicating copy to clipboard operation
react-native-mmkv copied to clipboard

v3 beta requires RN-web to use in a web build

Open amutsch opened this issue 1 year ago • 6 comments

In V2 it did not require RN web to use the library with react native and a separate react web app pulling in a Shared JS only library with MMKV to zustand integration). When I moved to V3(RN 74 with Fabric enabled) it required me to add RN Web to use the module with my web setup.

Thanks for the v3 beta BTW, working great

amutsch avatar Aug 04 '24 15:08 amutsch

Guten Tag, Hans here.

[!NOTE] New features, bugfixes, updates and other improvements are all handled mostly by @mrousavy in his free time. To support @mrousavy, please consider 💖 sponsoring him on GitHub 💖. Sponsored issues will be prioritized.

maintenance-hans[bot] avatar Aug 04 '24 15:08 maintenance-hans[bot]

I'm planning to take a look at this issue and test it this weekend, I reviewed code tonight and the fix seems straight forward.

Quick summary of items. There are 2 types in NativeMmkv.ts that are pulled into MMKV that cause a whole chain of RN code to be pulled in. Move the 2 types into Types file and update imports as needed.

The AppState usage in MMKV.ts needs to be handled, likely push that out to another file so I can add the web overload. Need to determine if there is an equivalent listener for memoryWarning I can attach for web.

amutsch avatar Aug 06 '24 03:08 amutsch

Looks like separating the interfaces to disconnect pulling in react-native is not currently possible due to some issues in codegen. I'll hold my changes to a future date where codegen allows this.

amutsch avatar Aug 10 '24 19:08 amutsch

hi @amutsch @mrousavy does it mean that mmkv is dropping support for react-native-web when using v3?

gituser8796 avatar Aug 18 '24 10:08 gituser8796

@gituser8796 , no the lib still works great in web. With 2.x a web build did not require react-native-web to build with this lib. With 3.x react-native-web alias is required to use the lib in a web build.

amutsch avatar Aug 18 '24 11:08 amutsch

Thanks for letting me know @amutsch !

gituser8796 avatar Aug 18 '24 15:08 gituser8796

With 3.x react-native-web alias is required to use the lib in a web build.

How so? Can this be avoided? If yes I'd appreciate any help / PRs here, I am not using react-native-mmkv in web myself. 🙏

mrousavy avatar Aug 29 '24 15:08 mrousavy

@mrousavy I have changes but until some changes occur in react native codgen we are stuck. I will open a new issue with pr if codegen updates to support this.

amutsch avatar Aug 29 '24 16:08 amutsch

@amutsch do you happen to have a PR for web?

gituser8796 avatar Sep 01 '24 17:09 gituser8796

@gituser8796 if you add react-native-web there will be some warnings but the module will work fine. react-native-codegen currently does not support separating the turbomodule interface from the spec definition which is causing the RN code to need to be pulled in. I have changes in a branch can fix the RN-web requirement once codegen supports separating interface and module definition

amutsch avatar Sep 02 '24 17:09 amutsch

@mrousavy I looked into a vite issue for someone and it looks like some of the exploratory work I was doing for a PR for this will be needed to get react-native-mmkv to work with vite in web project. If you can re-open this I will try and get a PR. It is fixable just one thing I don't like with how I need to fix that I'm working out which I will either document on PR or get fixed

amutsch avatar Nov 17 '24 21:11 amutsch