Skip to content

Commit

Permalink
fix: avoid "double proxying"
Browse files Browse the repository at this point in the history
This can be reverted when the following PR is merged: pmndrs/valtio#1038
  • Loading branch information
aleclarson committed Jan 20, 2025
1 parent 08b275d commit 1ad5b60
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
export {
getVersion,
proxy,
ref,
snapshot,
type INTERNAL_Op,
Expand All @@ -22,3 +21,4 @@ export {
type ReactiveClass,
type ReactiveProxy,
} from './runtime/instance'
export { proxy } from './runtime/proxy'
10 changes: 10 additions & 0 deletions src/runtime/proxy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { proxy as createProxy, unstable_getInternalStates } from 'valtio'

const { proxyStateMap } = unstable_getInternalStates()

export function proxy<T extends object>(data: T): T {
if (proxyStateMap.has(data)) {
return data
}
return createProxy(data)
}

0 comments on commit 1ad5b60

Please sign in to comment.