Repository navigation
Conversation
The prebuild declares every ReactNativeHeaders header that reaches no C++ as a member of its namespace module. That includes the react/cxxstableapi guards and the headers that include them (react/debug/flags.h, react/runtime/JSRuntimeFactory*.h, ...). Clang compiles module members on their own, with the importer's -D macros and without RN_BUILDING or RN_UMBRELLA_CONTEXT, so when an app defines RN_STRICT_API the guards fire while building ReactNativeHeaders_react and `import React` fails. Declare the guards, and every member that reaches one through unguarded includes, as `textual header`. They still belong to the module, so React.framework may include them, but they are expanded at each include site, where the guard sees its real includer. headers-verify now also type-checks the Swift `import React` fixture with RN_STRICT_API defined. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
coado
marked this pull request as draft
October 14, 2026 12:20
|
@coado has imported this pull request. If you are a Meta employee, you can view this in D125444181. |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary:
Apps that use React Native through Swift Package Manager and define
RN_STRICT_API(the C++ stable API opt-in, see #59043) cannot buildimport React.The prebuilt
ReactNativeHeaders.xcframeworkships a module map with one module per namespace. The prebuild makes every header that reaches no C++ a member of that module, and thereact/cxxstableapiguards qualify because they are pure preprocessor code. SoReactNativeHeaders_reactlistsFrameworksGuard.h,PrivateGuard.handUmbrellaGuard.hthemselves, plusreact/debug/flags.hand theJSRuntimeFactoryheaders that include them.Clang compiles module members on their own, using the importing target's
-Dmacros, with neitherRN_BUILDINGnorRN_UMBRELLA_CONTEXTset. WithRN_STRICT_APIdefined,PrivateGuard.handUmbrellaGuard.hhit their#errorwhile building the module.import Reactneeds that module (RCTHermesInstanceFactory.himports<react/runtime/JSRuntimeFactoryCAPI.h>), so every Swift file importing React, and every Objective-C++ file importing<React/...>with modules on, fails.This change declares the guards, and every module member that reaches one through unguarded includes, as
textual header(new rule R13 inheaders-spec.js). They still belong to the module, soReact.frameworkmay keep including them without a non-modular include error, but they are expanded at each include site, where the guard sees its real includer. Onmainthis covers 8 headers acrossReactNativeHeaders_react,ReactCommonandreactperflogger.Other changes:
headers-verify.jsruns the Swiftimport Reactgate a second time withRN_STRICT_APIdefined. Its module import fixture now picks a non-textual member of each module.react/gets no module. It does, namedReactNativeHeaders_react.Changelog:
[IOS] [FIXED] - Fix
import Reactfailing to build in Swift Package Manager apps that defineRN_STRICT_APITest Plan:
Unit tests, lint and types:
Prebuild end to end (Debug, iOS simulator slice), from
packages/react-native:textual headerentries, andheaders-verify.jsreportsALL GATES PASSED, including the new strict gate.headers-spec.jsreverted, every gate still passes except the new strict gate, which fails onPrivateGuard.h.RNTester through SwiftPM, with #59043 applied and the artifact above packaged as CI does (
ReactCoreDebug.xcframework.tar.gz):RN_STRICT_APIonReactNativeHeaders_reactwon't precompile, Swift target failsRN_STRICT_APIon, private include in app codeRN_STRICT_APIon, direct public includeRN_STRICT_APIon, "for frameworks" includeRN_STRICT_APIon, umbrella includeRN_STRICT_APIoff (spm updatewithout it)The "Before" row was built against the published nightly. Swift with C++ interop also builds with
RN_STRICT_APIoncemain'sRCTCallInvoker.h(which now includes<React/CallInvoker.h>) is in the artifact.Not run: Release flavor, device and Mac Catalyst slices. React Native's dependencies and Hermes came from the nightly rather than being built locally.
🤖 Generated with Claude Code