pmndrs / valtio

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

Consuming a valtio proxy from another package results in "TypeError: proxyState is not iterable" #705

Closed iam4x closed 1 year ago

iam4x commented 1 year ago

Summary

import {createExchange} from 'foo';

const exchange = createExchange();
// exchange.store is a Proxy object from valtio/vanilla

const Component = () => {
  const snap = useSnapshot(exchange.store);
  return (<div>{snap.foo}</div>);
}

This doesn't work and throws:

TypeError: proxyState is not iterable

I've logged: console.log(Object.getOwnPropertyDescriptors(exchange.store)) which outputs:

image

Do you have an idea?

iam4x commented 1 year ago

Still debugging, it looks like its importing .mjs and .js packages:

image

So proxyStateMap is correctly set in one context but not the other