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
useSWR
in UI KIT library not using cache from consumer app
#2864
Comments
I can confirm that inside a monorepo when referencing a library from an app there is some kind of internal cache being utilized from the library export via There is only one provider for swr and it is in the tests, no other provider exists but some how two cache's are generated. If I move all of the library code into the app, all the tests pass. using: swr: ^2.2.5 |
I guess we should provide a reproduction sandbox, but currently I don't have time :( |
After some testing and a few suggestions from coworkers, the reason for this issue is that the node_modules/swr was in multiple locations, one in the app and one in the library. This caused two global caches respective to each instance of swr This is probably a non-issue with importing into apps NOT in the monorepo but when you have multiple instances of swr per library or app it breaks. tl;dr Should only use one node_modules/swr between all projects to access the same cache |
I don't get it. Why having 2 swr packages in Additional context: |
How to achive this? Installing swr as a peerDep instead of dep worked in your case? |
For my case I made sure all my swr instances were using the same version, that way one 1 copy of swr is loaded from monorepo root |
Bug report
useSWR
in UI KIT library not using cache from consumer appDescription / Observed Behavior
I have 3 applications:
And using
useSWR
inside of UI KIT components working but globalmutate
functions is not affecting consumer's app cache to revalidate.I found that
useSWR
calls inside of UI KIT components using their own cache layer.Expected Behavior
Global mutate function should work with app's cache
Additional Context
Projects using Vite typescript react and
"swr": "^2.2.4",
Reference: #2825
The text was updated successfully, but these errors were encountered: