Skip to content
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

fix(vanilla): respect property enumetrability #800

Merged
merged 6 commits into from
Oct 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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))
})
Loading