From 97b709272858fe2c7ceb438cc19925464b69768e Mon Sep 17 00:00:00 2001 From: bheemreddy-samsara Date: Thu, 8 Jan 2026 13:44:25 -0600 Subject: [PATCH] fix(runtime): add Object.hasOwn polyfill for Hermes compatibility Hermes (React Native's default JS engine) doesn't support Object.hasOwn (ES2022). This causes runtime errors when @vitest/expect v4.x initializes because it uses Object.hasOwn internally. Error without fix: ``` Object.hasOwn is not a function. (In 'Object.hasOwn(globalThis, MATCHERS_OBJECT)', 'Object.hasOwn' is undefined) ``` Add polyfill in runtime package that loads before @vitest/expect. Tracking: https://github.com/facebook/hermes/issues/1875 --- packages/runtime/src/index.ts | 2 ++ packages/runtime/src/polyfills.ts | 16 ++++++++++++++++ 2 files changed, 18 insertions(+) create mode 100644 packages/runtime/src/polyfills.ts diff --git a/packages/runtime/src/index.ts b/packages/runtime/src/index.ts index dc03137..6fd2a8c 100644 --- a/packages/runtime/src/index.ts +++ b/packages/runtime/src/index.ts @@ -1,3 +1,5 @@ +// Polyfills must be imported first to ensure compatibility with Hermes +import './polyfills.js'; import './globals.d.ts'; export { UI as ReactNativeHarness } from './ui/index.js'; diff --git a/packages/runtime/src/polyfills.ts b/packages/runtime/src/polyfills.ts new file mode 100644 index 0000000..4410462 --- /dev/null +++ b/packages/runtime/src/polyfills.ts @@ -0,0 +1,16 @@ +/** + * Polyfills for Hermes JavaScript engine compatibility. + * + * Hermes (React Native's default JS engine) doesn't support all ES2022+ features. + * This file provides polyfills for features used by harness dependencies. + */ + +/** + * Object.hasOwn (ES2022) + * Used by @vitest/expect v4.x for property checking. + * @see https://github.com/facebook/hermes/issues/1875 + */ +if (typeof Object.hasOwn !== 'function') { + Object.hasOwn = (obj: object, prop: PropertyKey): boolean => + Object.prototype.hasOwnProperty.call(obj, prop); +}