Skip to content

Re-copy the prefab headers when a header changes - #59127

Closed
YevheniiKotyrlo wants to merge 2 commits into
react:mainfrom
YevheniiKotyrlo:fix/prefab-headers-track-inputs
Closed

YevheniiKotyrlo wants to merge 2 commits into
react:mainfrom
YevheniiKotyrlo:fix/prefab-headers-track-inputs

Conversation

@YevheniiKotyrlo

Copy link
Copy Markdown
Contributor

Summary:

PreparePrefabHeadersTask copies ReactAndroid's public headers into build/prefab-headers, the prefab package an app's appmodules and every library's C++ compile against, while libreactnative.so compiles against ReactCommon directly. The task's only input is the list of directory paths:

  @get:Input abstract val input: ListProperty<PrefabPreprocessingEntry>

so after a header under those directories changes, Gradle finds the task up to date and the prefab package keeps the old header. Everything built against the prefab package then disagrees with libreactnative.so about that header: a struct that gained a field is allocated at its old size by a library and used at its new size by React Native.

A header changes in place whenever React Native is built from source and patched with patch-package, or while ReactCommon is edited during development. In an app built from source, a patch that added two fields to Yoga's CachedMeasurement left prefab-headers/reactnative/yoga/node/CachedMeasurement.h, LayoutResults.h, Node.h and style/Style.h at their old content across two builds, and the app crashed at launch with SIGSEGV under YogaLayoutableShadowNode::replaceChild ← cloneChildInPlace ← configureYogaTree.

The task now declares the headers it copies as @InputFiles, read through the same filtered file trees the copy uses, so the declared inputs and the copied headers cannot disagree. Each library's folder is deleted before it is copied into, so a header removed from ReactCommon leaves no copy behind once the task runs again.

Changelog:

[ANDROID] [FIXED] - Re-copy the prefab headers when a header under ReactCommon changes

Test Plan:

  • PreparePrefabHeadersTaskTest gains preparePrefabHeadersTask_declaresTheHeadersItCopiesAsInputs (the task's input files are exactly the copied header, not the .cpp beside it) and preparePrefabHeadersTask_withARemovedHeader_removesItsCopy. On main both fail: the input files are [], and removed.h is still in the output after the second run. With the change, all 10 cases pass.
  • ./gradlew build -PenableWarningsAsErrors=true in packages/gradle-plugin, in reactnativecommunity/react-native-android:latest: 238 tests, 0 failures. ktfmt 0.59.0 (--dry-run --set-exit-if-changed) is clean on both files.
  • In the app above, with the change applied to its @react-native/gradle-plugin: the next build ran preparePrefab instead of finding it up to date, every Yoga header in prefab-headers and in the debug prefab package matched ReactCommon, every library recompiled against them, and the app launched without the crash.

PreparePrefabHeadersTask declared only the directory paths it copies
from, so Gradle found it up to date after a header under them changed
and the prefab package every app and library compiles against kept the
old header. The headers it copies are now its input files, read through
the same file trees the copy uses, and each library's folder is rebuilt
from scratch so a removed header leaves no copy behind.
@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Oct 16, 2026
@YevheniiKotyrlo
YevheniiKotyrlo marked this pull request as ready for review October 16, 2026 07:41
@facebook-github-tools facebook-github-tools Bot added the Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team. label Oct 16, 2026
@meta-codesync

meta-codesync Bot commented Oct 16, 2026

Copy link
Copy Markdown

@cortinico has imported this pull request. If you are a Meta employee, you can view this in D125650684.

@meta-codesync meta-codesync Bot closed this in bf4fac3 Oct 16, 2026
@meta-codesync meta-codesync Bot added the Merged This PR has been merged. label Oct 16, 2026
@meta-codesync

meta-codesync Bot commented Oct 16, 2026

Copy link
Copy Markdown

@cortinico merged this pull request in bf4fac3.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Merged This PR has been merged. Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant