diff --git a/src/vanilla.ts b/src/vanilla.ts index 86faef85..2685c7d7 100644 --- a/src/vanilla.ts +++ b/src/vanilla.ts @@ -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, diff --git a/tests/basic.test.tsx b/tests/basic.test.tsx index ec2d27d3..eb1fa068 100644 --- a/tests/basic.test.tsx +++ b/tests/basic.test.tsx @@ -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 }) @@ -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)) +})