Skip to content

fix: Move jest/mock into package build (fix TS under RN 0.87) - #745

Merged
janicduplessis merged 1 commit into
appandflow:mainfrom
huntie:precompile-jest-mock
Aug 3, 2026
Merged

fix: Move jest/mock into package build (fix TS under RN 0.87)#745
janicduplessis merged 1 commit into
appandflow:mainfrom
huntie:precompile-jest-mock

Conversation

@huntie

@huntie huntie commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

Summary

Minimal fix for react-native-safe-area-context compatibility in React Native 0.87 projects. See react-native-community/template#245.

Context

The incoming React Native 0.87 release will ship the Strict TypeScript API by default (moving to a user opt-out).

Typically, this change is scoped to the user's project (@react-native/typescript-config includes skipLibCheck: true) and not library source code.

However, react-native-safe-area-context ships a Jest integration, which is an exception that crosses this boundary:

setupFiles: ['react-native-safe-area-context/jest/mock']

Problem: react-native-safe-area-context/jest/mock pulls ../src/* (of this library) into the scope of the user's TypeScript analysis — instead of the compiled lib/ code, producing a type error against deep imports such as react-native/Libraries/Types/CodegenTypes which no longer resolve (see also #744).

This diff

Fix this types breakage for app consumers, independent of #744.

  • Move jest/mock.tsx to src/jest/mock.tsx so builder-bob compiles it like the rest of the library. The react-native-safe-area-context/jest/mock subpath is preserved via shims.
  • ✅ Consuming projects now only see this library's .d.ts files, which are exempt from typechecking due toskipLibCheck: false.

Test Plan

  • yarn validate:typescript, ESlint, and the Jest suite all pass.
  • Simulated an RN 0.88 (main) consumer app with TypeScript 6: published 5.8.0 reproduces the 6 errors from the issue; the packed build from this change typechecks clean.
  • Runtime smoke test: The shim loads the compiled mock under Jest, and SafeAreaProvider/useSafeAreaInsets/useSafeAreaFrame render the mock metrics through context.

Comment thread jest/mock.js
@@ -0,0 +1 @@
module.exports = require('../lib/commonjs/jest/mock');

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: After #740, we could introduce an "exports" entry to replace these shims (non-breaking).

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do u know what is minimum version of rn / metro that supports exports?

@janicduplessis janicduplessis left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @huntie !

@janicduplessis
janicduplessis merged commit b9e2857 into appandflow:main Aug 3, 2026
1 check passed
@huntie
huntie deleted the precompile-jest-mock branch August 3, 2026 22:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants