facebook / facebook/hermes

TypeError: ownKeys target is non-extensible but key is missing from trap result error when using numeric string keys on Hermes

Open
#1,609 10 comments 2 reactions 0 assignees View on GitHub
bug
Dominant language
JavaScript
Stars
11.3k
Forks
859
Avg merge
1h 30m
Merged PRs (30d)
3

Description

## Bug Description

When using Valtio with Hermes in React Native, an error is thrown if the proxy object contains numeric string keys. For example, using a key like '12345' results in the following error:

```vbnet
TypeError: ownKeys target is non-extensible but key is missing from trap result, js engine: hermes
```

I've confirmed that using non-numeric string keys (e.g. text) avoids the error.

- [x] I have run `gradle clean` and confirmed this bug does not occur with JSC
- [ ] The issue is reproducible with the latest version of React Native.

Hermes git revision (if applicable):
React Native version: 0.76.5 (new arch is `false`)
OS: iOS, Android
Platform (most likely one of arm64-v8a, armeabi-v7a, x86, x86_64): arm64

## Steps To Reproduce

1. Create a Valtio proxy object with a numeric string as key:
```tsx
import { useSnapshot, proxy } from 'valtio';
const state = proxy({ '12345': 'hello' });
```

2.In a ReactNative component, take a snapshot and log it when a button is pressed:
```tsx
export const MyScreen: React.FC = () => {
const snap = useSnapshot(state);
return (
{
// Triggering iteration on the snapshot throws the error:
Object.entries(snap).forEach(([key, value]) => {
console.log(key, value);
});
}}
>
button for test

);
}
```
3. Run the application on a device/emulator with Hermes enabled.
4. Press the button. The error occurs:
```vbnet
TypeError: ownKeys target is non-extensible but key is missing from trap result, js engine: hermes
```

## The Expected Behavior

Using a numeric string as a key in a Valtio proxy should not lead to an error when accessing the snapshot (e.g., via Object.entries or direct logging). The behavior should be consistent with proxy objects that use non-numeric keys.

Additional context:

- Replacing the key with a non-numeric string (for example, proxy({ text: 'hello' })) avoids the error.
- A patch from [this Valtio PR](https://github.com/pmndrs/valtio/pull/752/files#diff-b68a2cbc8606fe37f9c2c72867a87ff50a11c2b38a6d9de45a94281f02bf0a4eL149) appears to work around the issue, suggesting the problem may be related to how Hermes handles Proxy traps.
- A similar issue is discussed in the [Hermes issue #1063](https://github.com/facebook/hermes/issues/1063), though the root cause has not yet been identified.

Any guidance or fixes for this issue would be greatly appreciated. Thank you for your help!

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.