Skip to content

Checking for a version match between JS and native #15271

Description

@ide

Many of the issues people run into - with quite a wide variety of symptoms - are caused by a mismatch between the JS and native code. There isn't a single reason for this mismatch, ex: it could be caused by stale Xcode/Android build data, forgetting to rebuild the native app after upgrading RN in node_modules, Watchman/Metro caching bugs, bundle caching on the client, and so on. Some kind of simple version check might help people discover these bugs more quickly with a more accurate error message.

Proposal

We add three new files: ReactNativeVersion.java, RCTVersion.h, and ReactNativeVersion.js. These files are marked as @generated and are written only by the release scripts, which already modify package.json, the Podspec, and a Gradle file.

// ReactNativeVersion.java// @generated by scripts/bump-oss-version.jspublicclassReactNativeVersion {
publicstaticfinalStringVERSION = "0.47.0-rc.1";
publicstaticfinalintMAJOR = 0;
publicstaticfinalintMINOR = 47;
publicstaticfinalintPATCH = 0;
publicstaticfinalintPRERELEASE = "rc.1";
}
// RCTVersion.h// @generated by scripts/bump-oss-version.js
#defineREACT_NATIVE_VERSION@"0.47.0-rc.1"
#defineREACT_NATIVE_VERSION_MAJOR0
#defineREACT_NATIVE_VERSION_MINOR47
#defineREACT_NATIVE_VERSION_PATCH0
#defineREACT_NATIVE_VERSION_PRERELEASE@"rc.1"
// ReactNativeVersion.js// @generated by scripts/bump-oss-version.jsexports.version='0.47.0-rc.1';exports.major=0;exports.minor=47;exports.patch=0;exports.prerelease='rc.1'

These files are checked into the repo for simplicity. In addition to these autogenerated files, there would be small native modules that export these versions from native to JS (using constantsToExport, it should be fast since there's not much real work being done). JS would then compare ReactNativeVersion.version to NativeModules.Version.version and call console.error if they don't match (for some definition of match -- maybe it's OK if 0.46.1 JS runs on 0.46.0 native code, don't want this warning to be annoying).

Metadata

Metadata

Assignees

No one assigned

    Labels

    Help Wanted :octocat:Issues ideal for external contributors.Resolution: LockedThis issue was locked by the bot.Type: DiscussionLong running discussion.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions