By using this site, you agree to the Privacy Policy and Terms of Use.
Accept
World of SoftwareWorld of SoftwareWorld of Software
  • News
  • Software
  • Mobile
  • Computing
  • Gaming
  • Videos
  • More
    • Gadget
    • Web Stories
    • Trending
    • Press Release
Search
  • Privacy
  • Terms
  • Advertise
  • Contact
Copyright © All Rights Reserved. World of Software.
Reading: How Multiple Valtio Instances Broke My React Native App | HackerNoon
Share
Sign In
Notification Show More
Font ResizerAa
World of SoftwareWorld of Software
Font ResizerAa
  • Software
  • Mobile
  • Computing
  • Gadget
  • Gaming
  • Videos
Search
  • News
  • Software
  • Mobile
  • Computing
  • Gaming
  • Videos
  • More
    • Gadget
    • Web Stories
    • Trending
    • Press Release
Have an existing account? Sign In
Follow US
  • Privacy
  • Terms
  • Advertise
  • Contact
Copyright © All Rights Reserved. World of Software.
World of Software > Computing > How Multiple Valtio Instances Broke My React Native App | HackerNoon
Computing

How Multiple Valtio Instances Broke My React Native App | HackerNoon

News Room
Last updated: 2025/11/10 at 3:51 PM
News Room Published 10 November 2025
Share
How Multiple Valtio Instances Broke My React Native App | HackerNoon
SHARE

It all started with a crash in @reown/appkit-react-native. While debugging that crash, I noticed something weird happening with valtio. The subscribe() function seemed to work fine, but proxy() wasn’t behaving as expected. I decided to dig into the library code itself and added some debugging directly in node_modules/valtio/vanilla.js.

I printed proxyStateMap.get(proxyObject) in both functions, and that’s when things got interesting:

  • In proxy(): Got the correct value ✓
  • In subscribe(): Got undefined ✗

Wait, what? They were completely different WeakMap instances from different valtio module instances! The proxy object was being stored in one proxyStateMap, but when subscribe() tried to find it, it was looking in a completely different proxyStateMap from a different valtio instance. That’s like putting your keys in one drawer and looking for them in another.

A Quick Note on Debugging Library Code

Before I continue, here’s something I had to remember: when you’re adding console.log statements to library code in node_modules, your logs might not show up because modules get cached. I spent way too long wondering why my logs weren’t appearing before I remembered to run:

pnpm start --reset-cache

Adding logs directly to library code is actually super helpful when you’re dealing with weird behavior – you can see exactly what’s happening inside the library, trace the execution flow, and peek at internal state that’s not exposed through the public API. Just don’t forget to clear that cache!

Going Back in Time

At this point, I was stuck. The code was working before, so what changed? I did what I should have done from the start: I checked the git history.

I went through past commits one by one until I found a commit where everything worked. Then I compared the difference between the working state and the broken state. Bingo – there it was, a single line change in .npmrc:

+ node-linker=hoisted

That one line was the culprit.

What Actually Happened

After adding node-linker=hoisted, pnpm switched to a flat structure similar to npm, and that broke the sharing mechanism by creating separate valtio instances:

node_modules/valtio (version 1.13.2)
node_modules/@reown/appkit-core-react-native/node_modules/valtio (version 2.1.8)
node_modules/@reown/appkit-react-native/node_modules/valtio (version 2.1.8)

Why did this happen? A few reasons:

  1. Version mismatch: The root had 1.13.2 (some transitive dependency), while the nested packages needed 2.1.8
  2. No virtual store: With node-linker=hoisted, pnpm doesn’t use the .pnpm virtual store structure that ensures proper symlinking
  3. pnpm kept them separate to avoid conflicts

Since they were using different valtio instances, and each instance had its own proxyStateMap WeakMap, the proxy object stored in one proxyStateMap wasn’t found when subscribe() looked in a different proxyStateMap.

The Fix

The solution was to force all valtio dependencies to use the same version. I added this to my root package.json:

{
  "pnpm": {
    "overrides": {
      "valtio": "2.1.8"
    }
  }
}

Then ran pnpm install, and that was it. This:

  • Unified all valtio to 2.1.8
  • Allowed pnpm to hoist it to the root
  • Removed the nested instances
  • Made all packages share the same proxyStateMap

Alternatively, I could have just removed node-linker=hoisted to go back to pnpm’s default virtual store, which handles this automatically. But I needed the hoisted structure for other reasons, so the override approach worked better for me.

Key Takeaways

  1. Check git history first – When something breaks, see what changed. The diff often reveals the root cause immediately.
  2. Adding console.log to library code is a good debugging habit – When you encounter weird library behavior, adding logs directly in node_modules can reveal exactly what’s happening inside the library. Just remember to use --reset-cache when debugging library code in node_modules to see your changes.
  3. Multiple package instances can break singleton-like behavior – Libraries that rely on WeakMaps, module-level state, or singletons can fail when multiple instances exist. This isn’t just a valtio thing – it can happen with any library that maintains internal state.
  4. Version mismatches prevent hoisting – Even with node-linker=hoisted, pnpm will keep separate instances if versions differ. Use pnpm.overrides to force consistent versions across your workspace.

Happy debugging!

Sign Up For Daily Newsletter

Be keep up! Get the latest breaking news delivered straight to your inbox.
By signing up, you agree to our Terms of Use and acknowledge the data practices in our Privacy Policy. You may unsubscribe at any time.
Share This Article
Facebook Twitter Email Print
Share
What do you think?
Love0
Sad0
Happy0
Sleepy0
Angry0
Dead0
Wink0
Previous Article Czechia’s policy on China: Swinging between engagement and de-risking Czechia’s policy on China: Swinging between engagement and de-risking
Next Article Google says its confusing Gemini Home rollout is going just great Google says its confusing Gemini Home rollout is going just great
Leave a comment

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Stay Connected

248.1k Like
69.1k Follow
134k Pin
54.3k Follow

Latest News

Gemini for TV is coming to Google TV Streamer starting today
Gemini for TV is coming to Google TV Streamer starting today
News
SSD Storage Prices to Climb as AI Demand Meets Tight NAND Supply
SSD Storage Prices to Climb as AI Demand Meets Tight NAND Supply
News
This AI Mapping System Lets Robots See the World | HackerNoon
This AI Mapping System Lets Robots See the World | HackerNoon
Computing
Mon, 11/10/2025 – 18:00 – Editors Summary
News

You Might also Like

This AI Mapping System Lets Robots See the World | HackerNoon
Computing

This AI Mapping System Lets Robots See the World | HackerNoon

10 Min Read
The Llama 2-IVLMap Combination Delivering Smarter Robot Control | HackerNoon
Computing

The Llama 2-IVLMap Combination Delivering Smarter Robot Control | HackerNoon

5 Min Read
IVLMap Solves Robot Navigation By Mapping Individual Objects | HackerNoon
Computing

IVLMap Solves Robot Navigation By Mapping Individual Objects | HackerNoon

20 Min Read
IVLMap Bridges the Sim-to-Real Gap in Robot Navigation | HackerNoon
Computing

IVLMap Bridges the Sim-to-Real Gap in Robot Navigation | HackerNoon

4 Min Read
//

World of Software is your one-stop website for the latest tech news and updates, follow us now to get the news that matters to you.

Quick Link

  • Privacy Policy
  • Terms of use
  • Advertise
  • Contact

Topics

  • Computing
  • Software
  • Press Release
  • Trending

Sign Up for Our Newsletter

Subscribe to our newsletter to get our newest articles instantly!

World of SoftwareWorld of Software
Follow US
Copyright © All Rights Reserved. World of Software.
Welcome Back!

Sign in to your account

Lost your password?