pmndrs / valtio

🧙 Valtio makes proxy-state simple for React and Vanilla
https://valtio.dev
MIT License
8.84k stars 248 forks source link

`use-sync-external-store` should be marked as a `peerDep` #698

Closed maraisr closed 1 year ago

maraisr commented 1 year ago

Hi 👋🏻

We are using valtio in a context where react isnt used. So exclusively the /vanilla package.

But NPM is throwing an install warning for us:

npm ERR! code ELSPROBLEMS
npm ERR! missing: react@^16.8.0 || ^17.0.0 || ^18.0.0, required by use-sync-external-store@1.2.0

Believe its because valtio requires use-sync-external-store which has a peer dep on react, which we do not want.

https://github.com/pmndrs/valtio/blob/7fe26c2a8ff2df8a5b8df019f8878dbf48e40876/package.json#LL140C18-L140C18


Perhaps there is an alternative to valtio that doesnt depend on react?

dai-shi commented 1 year ago

I see it's because use-sync-external-store has peer dep, and it's not optional.

We could mark it as peer dep, but that would require react users to install it. (some new package managers can do it automatically.)

Curious, how "bad" is it to install react for you?

maraisr commented 1 year ago

thank you for your time. appreciate the response. But no thank you, installing react is an insurmountable sin I do not wish to commit.

dai-shi commented 1 year ago

Does --legacy-peer-deps option help? Otherwise, patch-package might be a last resort.

maraisr commented 1 year ago

use-sync-external-store is only used in your react submodule — can that not be an optional peer dependency as it rightly is?

dai-shi commented 1 year ago

It could. (Theoretically, same applies to proxy-compare which is only meaningfully used in react. vanilla part is meaningless without it.)

It's just a matter of usability. If we remove use-sync-external-store from the dependency, 99.9% of users would have to re-install it. note valtio depends on it. Say, 1% of users is using valtio/vanilla, and probably only one tenth would actually have a trouble with the react peer dependency.

I feel like a dummy react library would help in your case. or dummy use-sync-external-store.

btw, we will be removing it in the future version.

maraisr commented 1 year ago

Oh this is fantastic news, looking forward to it!

dai-shi commented 1 year ago

By the future version, I meant v2 with React >= 18 requirement. It won't happen very soon.