Skip to content

Commit

Permalink
fix(vanilla): respect property enumetrability (#800)
Browse files Browse the repository at this point in the history
* respect property enumetrability (#726)

* correct `enumerable` default (#726)

* prettier

* not relying on defaults (#726)

---------

Co-authored-by: Daishi Kato <[email protected]>
  • Loading branch information
alexander-entin and dai-shi authored Oct 22, 2023
1 parent 0d5d69d commit 347ccf5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/vanilla.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,13 @@ const buildProxyFunction = (
return
}
const value = Reflect.get(target, key)
const { enumerable } = Reflect.getOwnPropertyDescriptor(
target,
key
) as PropertyDescriptor
const desc: PropertyDescriptor = {
value,
enumerable: true,
enumerable: enumerable as boolean,
// This is intentional to avoid copying with proxy-compare.
// It's still non-writable, so it avoids assigning a value.
configurable: true,
Expand Down
7 changes: 6 additions & 1 deletion tests/basic.test.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { StrictMode, useEffect, useRef, useState } from 'react'
import { fireEvent, render, waitFor } from '@testing-library/react'
import { expect, it, vi } from 'vitest'
import { proxy, useSnapshot } from 'valtio'
import { proxy, snapshot, useSnapshot } from 'valtio'

it('simple counter', async () => {
const obj = proxy({ count: 0 })
Expand Down Expand Up @@ -493,3 +493,8 @@ it('sync snapshot between nested components (#460)', async () => {
getByText('Child: value2')
})
})

it('respects property enumerability (#726)', async () => {
const x = proxy(Object.defineProperty({ a: 1 }, 'b', { value: 2 }))
expect(Object.keys(snapshot(x))).toEqual(Object.keys(x))
})

1 comment on commit 347ccf5

@vercel
Copy link

@vercel vercel bot commented on 347ccf5 Oct 22, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

valtio – ./

valtio-git-main-pmndrs.vercel.app
valtio-pmndrs.vercel.app
valtio.vercel.app
valtio.pmnd.rs

Please sign in to comment.