diff --git a/.nx/version-plans/version-plan-1768220533507.md b/.nx/version-plans/version-plan-1768220533507.md new file mode 100644 index 0000000..4462d45 --- /dev/null +++ b/.nx/version-plans/version-plan-1768220533507.md @@ -0,0 +1,5 @@ +--- +__default__: prerelease +--- + +Adds Object.hasOwn polyfill to the runtime package for JSC (JavaScriptCore) compatibility. diff --git a/packages/runtime/src/index.ts b/packages/runtime/src/index.ts index dc03137..1dc1c6e 100644 --- a/packages/runtime/src/index.ts +++ b/packages/runtime/src/index.ts @@ -1,3 +1,4 @@ +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..df8ed18 --- /dev/null +++ b/packages/runtime/src/polyfills.ts @@ -0,0 +1,14 @@ +/** + * Polyfills for ES2022+ features not supported by JSC (JavaScriptCore). + * + * JSC, used in React Native when Hermes is disabled, doesn't support + * Object.hasOwn (ES2022). This causes runtime errors when @vitest/expect + * v4.x initializes. + * + * This polyfill must be loaded before any code that uses Object.hasOwn. + */ + +if (typeof Object.hasOwn !== 'function') { + Object.hasOwn = (obj: object, prop: PropertyKey): boolean => + Object.prototype.hasOwnProperty.call(obj, prop); +}