Skip to content

Commit 0da9b2d

Browse files
committed
[compiler] improve zod v3 backwards compat (#34877)
## Summary When upgrading to `babel-plugin-react-compiler@1.0.0` in a project that uses `zod@3` we are running into TypeScript errors like: ``` node_modules/babel-plugin-react-compiler/dist/index.d.ts:435:10 - error TS2694: Namespace '"/REDACTED/node_modules/zod/v3/external"' has no exported member 'core'. 435 }, z.core.$strip>>>; ~~~~ ``` This problem seems to be related to d6eb735, which introduced zod v3/v4 compatibility. Since `zod` is bundled into the compiler source this does not cause runtime issues and only manifests as TypeScript errors. My proposed solution is this PR is to use zod's [subpath versioning strategy](https://zod.dev/v4/versioning?id=versioning-in-zod-4) which allows you to support v3 and v4 APIs on both major versions. Changes in this PR include: - Updated `zod` import paths to `zod/v4` - Bumped min `zod` version to `^3.25.0` for zod which guarantees the `zod/v4` subpath is available. - Updated `zod-validation-error` import paths to `zod-validation-error/v4` - Bumped min `zod-validation-error ` version to `^3.5.0` - Updated `externals` tsup configuration where appropriate. Once the compiler drops zod v3 support we could optionally remove the `/v4` subpath from the imports. ## How did you test this change? Not totally sure the best way to test. I ran `NODE_ENV=production yarn workspace babel-plugin-react-compiler run build --dts` and diffed the `dist/` folder between my change and `v1.0.0` and it looks correct. We have a `patch-package` patch to workaround this for now and it works as expected. ```diff diff --git a/node_modules/babel-plugin-react-compiler/dist/index.d.ts b/node_modules/babel-plugin-react-compiler/dist/index.d.ts index 81c3f3d..daafc2c 100644 --- a/node_modules/babel-plugin-react-compiler/dist/index.d.ts +++ b/node_modules/babel-plugin-react-compiler/dist/index.d.ts @@ -1,7 +1,7 @@ import * as BabelCore from '@babel/core'; import { NodePath as NodePath$1 } from '@babel/core'; import * as t from '@babel/types'; -import { z } from 'zod'; +import { z } from 'zod/v4'; import { NodePath, Scope } from '@babel/traverse'; interface Result<T, E> { ``` Co-authored-by: Henry Q. Dineen <henryqdineen@gmail.com> DiffTrain build for [ed1351c](ed1351c)
1 parent 4bb65ae commit 0da9b2d

26 files changed

+399
-399
lines changed

compiled-rn/VERSION_NATIVE_FB

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
19.3.0-native-fb-d8aa94b0-20251016
1+
19.3.0-native-fb-ed1351c4-20251016

compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react/react-dom/cjs/ReactDOM-dev.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* @noflow
88
* @nolint
99
* @preventMunge
10-
* @generated SignedSource<<92b85e25721a5fd5afa9ab7f7ed14dd2>>
10+
* @generated SignedSource<<0c3973912050f59d94122963d1d2deda>>
1111
*/
1212

1313
"use strict";
@@ -404,5 +404,5 @@ __DEV__ &&
404404
exports.useFormStatus = function () {
405405
return resolveDispatcher().useHostTransitionStatus();
406406
};
407-
exports.version = "19.3.0-native-fb-d8aa94b0-20251016";
407+
exports.version = "19.3.0-native-fb-ed1351c4-20251016";
408408
})();

compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react/react-dom/cjs/ReactDOM-prod.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* @noflow
88
* @nolint
99
* @preventMunge
10-
* @generated SignedSource<<492d1c7f1715f79e03e614e23bf3cfe1>>
10+
* @generated SignedSource<<b6536d265de7b2c1f98d4b5c5631182a>>
1111
*/
1212

1313
"use strict";
@@ -203,4 +203,4 @@ exports.useFormState = function (action, initialState, permalink) {
203203
exports.useFormStatus = function () {
204204
return ReactSharedInternals.H.useHostTransitionStatus();
205205
};
206-
exports.version = "19.3.0-native-fb-d8aa94b0-20251016";
206+
exports.version = "19.3.0-native-fb-ed1351c4-20251016";

compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react/react-dom/cjs/ReactDOM-profiling.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* @noflow
88
* @nolint
99
* @preventMunge
10-
* @generated SignedSource<<492d1c7f1715f79e03e614e23bf3cfe1>>
10+
* @generated SignedSource<<b6536d265de7b2c1f98d4b5c5631182a>>
1111
*/
1212

1313
"use strict";
@@ -203,4 +203,4 @@ exports.useFormState = function (action, initialState, permalink) {
203203
exports.useFormStatus = function () {
204204
return ReactSharedInternals.H.useHostTransitionStatus();
205205
};
206-
exports.version = "19.3.0-native-fb-d8aa94b0-20251016";
206+
exports.version = "19.3.0-native-fb-ed1351c4-20251016";

compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react/react-dom/cjs/ReactDOMClient-dev.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* @noflow
88
* @nolint
99
* @preventMunge
10-
* @generated SignedSource<<6392ec10ad620717b885c00858c982d1>>
10+
* @generated SignedSource<<10050bb86cef9b7c923695c42bf0b742>>
1111
*/
1212

1313
/*
@@ -30117,11 +30117,11 @@ __DEV__ &&
3011730117
};
3011830118
(function () {
3011930119
var isomorphicReactPackageVersion = React.version;
30120-
if ("19.3.0-native-fb-d8aa94b0-20251016" !== isomorphicReactPackageVersion)
30120+
if ("19.3.0-native-fb-ed1351c4-20251016" !== isomorphicReactPackageVersion)
3012130121
throw Error(
3012230122
'Incompatible React versions: The "react" and "react-dom" packages must have the exact same version. Instead got:\n - react: ' +
3012330123
(isomorphicReactPackageVersion +
30124-
"\n - react-dom: 19.3.0-native-fb-d8aa94b0-20251016\nLearn more: https://react.dev/warnings/version-mismatch")
30124+
"\n - react-dom: 19.3.0-native-fb-ed1351c4-20251016\nLearn more: https://react.dev/warnings/version-mismatch")
3012530125
);
3012630126
})();
3012730127
("function" === typeof Map &&
@@ -30158,10 +30158,10 @@ __DEV__ &&
3015830158
!(function () {
3015930159
var internals = {
3016030160
bundleType: 1,
30161-
version: "19.3.0-native-fb-d8aa94b0-20251016",
30161+
version: "19.3.0-native-fb-ed1351c4-20251016",
3016230162
rendererPackageName: "react-dom",
3016330163
currentDispatcherRef: ReactSharedInternals,
30164-
reconcilerVersion: "19.3.0-native-fb-d8aa94b0-20251016"
30164+
reconcilerVersion: "19.3.0-native-fb-ed1351c4-20251016"
3016530165
};
3016630166
internals.overrideHookState = overrideHookState;
3016730167
internals.overrideHookStateDeletePath = overrideHookStateDeletePath;
@@ -30311,5 +30311,5 @@ __DEV__ &&
3031130311
listenToAllSupportedEvents(container);
3031230312
return new ReactDOMHydrationRoot(initialChildren);
3031330313
};
30314-
exports.version = "19.3.0-native-fb-d8aa94b0-20251016";
30314+
exports.version = "19.3.0-native-fb-ed1351c4-20251016";
3031530315
})();

compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react/react-dom/cjs/ReactDOMClient-prod.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* @noflow
88
* @nolint
99
* @preventMunge
10-
* @generated SignedSource<<c862f975f4d671459fc4218fc9a16617>>
10+
* @generated SignedSource<<363e7039da3eaf3fe0bea474ac2a0bf8>>
1111
*/
1212

1313
/*
@@ -17581,14 +17581,14 @@ ReactDOMHydrationRoot.prototype.unstable_scheduleHydration = function (target) {
1758117581
};
1758217582
var isomorphicReactPackageVersion$jscomp$inline_2060 = React.version;
1758317583
if (
17584-
"19.3.0-native-fb-d8aa94b0-20251016" !==
17584+
"19.3.0-native-fb-ed1351c4-20251016" !==
1758517585
isomorphicReactPackageVersion$jscomp$inline_2060
1758617586
)
1758717587
throw Error(
1758817588
formatProdErrorMessage(
1758917589
527,
1759017590
isomorphicReactPackageVersion$jscomp$inline_2060,
17591-
"19.3.0-native-fb-d8aa94b0-20251016"
17591+
"19.3.0-native-fb-ed1351c4-20251016"
1759217592
)
1759317593
);
1759417594
ReactDOMSharedInternals.findDOMNode = function (componentOrElement) {
@@ -17610,10 +17610,10 @@ ReactDOMSharedInternals.findDOMNode = function (componentOrElement) {
1761017610
};
1761117611
var internals$jscomp$inline_2637 = {
1761217612
bundleType: 0,
17613-
version: "19.3.0-native-fb-d8aa94b0-20251016",
17613+
version: "19.3.0-native-fb-ed1351c4-20251016",
1761417614
rendererPackageName: "react-dom",
1761517615
currentDispatcherRef: ReactSharedInternals,
17616-
reconcilerVersion: "19.3.0-native-fb-d8aa94b0-20251016"
17616+
reconcilerVersion: "19.3.0-native-fb-ed1351c4-20251016"
1761717617
};
1761817618
if ("undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__) {
1761917619
var hook$jscomp$inline_2638 = __REACT_DEVTOOLS_GLOBAL_HOOK__;
@@ -17720,4 +17720,4 @@ exports.hydrateRoot = function (container, initialChildren, options) {
1772017720
listenToAllSupportedEvents(container);
1772117721
return new ReactDOMHydrationRoot(initialChildren);
1772217722
};
17723-
exports.version = "19.3.0-native-fb-d8aa94b0-20251016";
17723+
exports.version = "19.3.0-native-fb-ed1351c4-20251016";

compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react/react-dom/cjs/ReactDOMClient-profiling.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* @noflow
88
* @nolint
99
* @preventMunge
10-
* @generated SignedSource<<661bcbf8694be245aad5fbb7e37c3375>>
10+
* @generated SignedSource<<839a1ddc7e6dd708b23f2243d86967ce>>
1111
*/
1212

1313
/*
@@ -19703,14 +19703,14 @@ ReactDOMHydrationRoot.prototype.unstable_scheduleHydration = function (target) {
1970319703
};
1970419704
var isomorphicReactPackageVersion$jscomp$inline_2375 = React.version;
1970519705
if (
19706-
"19.3.0-native-fb-d8aa94b0-20251016" !==
19706+
"19.3.0-native-fb-ed1351c4-20251016" !==
1970719707
isomorphicReactPackageVersion$jscomp$inline_2375
1970819708
)
1970919709
throw Error(
1971019710
formatProdErrorMessage(
1971119711
527,
1971219712
isomorphicReactPackageVersion$jscomp$inline_2375,
19713-
"19.3.0-native-fb-d8aa94b0-20251016"
19713+
"19.3.0-native-fb-ed1351c4-20251016"
1971419714
)
1971519715
);
1971619716
ReactDOMSharedInternals.findDOMNode = function (componentOrElement) {
@@ -19732,10 +19732,10 @@ ReactDOMSharedInternals.findDOMNode = function (componentOrElement) {
1973219732
};
1973319733
var internals$jscomp$inline_2382 = {
1973419734
bundleType: 0,
19735-
version: "19.3.0-native-fb-d8aa94b0-20251016",
19735+
version: "19.3.0-native-fb-ed1351c4-20251016",
1973619736
rendererPackageName: "react-dom",
1973719737
currentDispatcherRef: ReactSharedInternals,
19738-
reconcilerVersion: "19.3.0-native-fb-d8aa94b0-20251016",
19738+
reconcilerVersion: "19.3.0-native-fb-ed1351c4-20251016",
1973919739
getLaneLabelMap: function () {
1974019740
for (
1974119741
var map = new Map(), lane = 1, index$332 = 0;
@@ -19858,4 +19858,4 @@ exports.hydrateRoot = function (container, initialChildren, options) {
1985819858
listenToAllSupportedEvents(container);
1985919859
return new ReactDOMHydrationRoot(initialChildren);
1986019860
};
19861-
exports.version = "19.3.0-native-fb-d8aa94b0-20251016";
19861+
exports.version = "19.3.0-native-fb-ed1351c4-20251016";

compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react/react-dom/cjs/ReactDOMProfiling-dev.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* @noflow
88
* @nolint
99
* @preventMunge
10-
* @generated SignedSource<<4a7ebe67c9f8aa928a3ad371e6fd3966>>
10+
* @generated SignedSource<<0fe412611812eec10d6b28d328f42188>>
1111
*/
1212

1313
/*
@@ -30173,11 +30173,11 @@ __DEV__ &&
3017330173
};
3017430174
(function () {
3017530175
var isomorphicReactPackageVersion = React.version;
30176-
if ("19.3.0-native-fb-d8aa94b0-20251016" !== isomorphicReactPackageVersion)
30176+
if ("19.3.0-native-fb-ed1351c4-20251016" !== isomorphicReactPackageVersion)
3017730177
throw Error(
3017830178
'Incompatible React versions: The "react" and "react-dom" packages must have the exact same version. Instead got:\n - react: ' +
3017930179
(isomorphicReactPackageVersion +
30180-
"\n - react-dom: 19.3.0-native-fb-d8aa94b0-20251016\nLearn more: https://react.dev/warnings/version-mismatch")
30180+
"\n - react-dom: 19.3.0-native-fb-ed1351c4-20251016\nLearn more: https://react.dev/warnings/version-mismatch")
3018130181
);
3018230182
})();
3018330183
("function" === typeof Map &&
@@ -30214,10 +30214,10 @@ __DEV__ &&
3021430214
!(function () {
3021530215
var internals = {
3021630216
bundleType: 1,
30217-
version: "19.3.0-native-fb-d8aa94b0-20251016",
30217+
version: "19.3.0-native-fb-ed1351c4-20251016",
3021830218
rendererPackageName: "react-dom",
3021930219
currentDispatcherRef: ReactSharedInternals,
30220-
reconcilerVersion: "19.3.0-native-fb-d8aa94b0-20251016"
30220+
reconcilerVersion: "19.3.0-native-fb-ed1351c4-20251016"
3022130221
};
3022230222
internals.overrideHookState = overrideHookState;
3022330223
internals.overrideHookStateDeletePath = overrideHookStateDeletePath;
@@ -30683,7 +30683,7 @@ __DEV__ &&
3068330683
exports.useFormStatus = function () {
3068430684
return resolveDispatcher().useHostTransitionStatus();
3068530685
};
30686-
exports.version = "19.3.0-native-fb-d8aa94b0-20251016";
30686+
exports.version = "19.3.0-native-fb-ed1351c4-20251016";
3068730687
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
3068830688
"function" ===
3068930689
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&

compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react/react-dom/cjs/ReactDOMProfiling-prod.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* @noflow
88
* @nolint
99
* @preventMunge
10-
* @generated SignedSource<<9f3d58983b9f6e0cbefa334c6c2962c4>>
10+
* @generated SignedSource<<4ac36dbf5ef6b77c072bd3c9130ef85c>>
1111
*/
1212

1313
/*
@@ -17592,14 +17592,14 @@ ReactDOMHydrationRoot.prototype.unstable_scheduleHydration = function (target) {
1759217592
};
1759317593
var isomorphicReactPackageVersion$jscomp$inline_2061 = React.version;
1759417594
if (
17595-
"19.3.0-native-fb-d8aa94b0-20251016" !==
17595+
"19.3.0-native-fb-ed1351c4-20251016" !==
1759617596
isomorphicReactPackageVersion$jscomp$inline_2061
1759717597
)
1759817598
throw Error(
1759917599
formatProdErrorMessage(
1760017600
527,
1760117601
isomorphicReactPackageVersion$jscomp$inline_2061,
17602-
"19.3.0-native-fb-d8aa94b0-20251016"
17602+
"19.3.0-native-fb-ed1351c4-20251016"
1760317603
)
1760417604
);
1760517605
ReactDOMSharedInternals.findDOMNode = function (componentOrElement) {
@@ -17621,10 +17621,10 @@ ReactDOMSharedInternals.findDOMNode = function (componentOrElement) {
1762117621
};
1762217622
var internals$jscomp$inline_2640 = {
1762317623
bundleType: 0,
17624-
version: "19.3.0-native-fb-d8aa94b0-20251016",
17624+
version: "19.3.0-native-fb-ed1351c4-20251016",
1762517625
rendererPackageName: "react-dom",
1762617626
currentDispatcherRef: ReactSharedInternals,
17627-
reconcilerVersion: "19.3.0-native-fb-d8aa94b0-20251016"
17627+
reconcilerVersion: "19.3.0-native-fb-ed1351c4-20251016"
1762817628
};
1762917629
if ("undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__) {
1763017630
var hook$jscomp$inline_2641 = __REACT_DEVTOOLS_GLOBAL_HOOK__;
@@ -17884,4 +17884,4 @@ exports.useFormState = function (action, initialState, permalink) {
1788417884
exports.useFormStatus = function () {
1788517885
return ReactSharedInternals.H.useHostTransitionStatus();
1788617886
};
17887-
exports.version = "19.3.0-native-fb-d8aa94b0-20251016";
17887+
exports.version = "19.3.0-native-fb-ed1351c4-20251016";

compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react/react-dom/cjs/ReactDOMProfiling-profiling.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* @noflow
88
* @nolint
99
* @preventMunge
10-
* @generated SignedSource<<832bdef850d7cb6af0eb98e3fd4fb460>>
10+
* @generated SignedSource<<f5badcefde854907a6bfa274ee94bd3f>>
1111
*/
1212

1313
/*
@@ -19718,14 +19718,14 @@ ReactDOMHydrationRoot.prototype.unstable_scheduleHydration = function (target) {
1971819718
};
1971919719
var isomorphicReactPackageVersion$jscomp$inline_2376 = React.version;
1972019720
if (
19721-
"19.3.0-native-fb-d8aa94b0-20251016" !==
19721+
"19.3.0-native-fb-ed1351c4-20251016" !==
1972219722
isomorphicReactPackageVersion$jscomp$inline_2376
1972319723
)
1972419724
throw Error(
1972519725
formatProdErrorMessage(
1972619726
527,
1972719727
isomorphicReactPackageVersion$jscomp$inline_2376,
19728-
"19.3.0-native-fb-d8aa94b0-20251016"
19728+
"19.3.0-native-fb-ed1351c4-20251016"
1972919729
)
1973019730
);
1973119731
ReactDOMSharedInternals.findDOMNode = function (componentOrElement) {
@@ -19747,10 +19747,10 @@ ReactDOMSharedInternals.findDOMNode = function (componentOrElement) {
1974719747
};
1974819748
var internals$jscomp$inline_2383 = {
1974919749
bundleType: 0,
19750-
version: "19.3.0-native-fb-d8aa94b0-20251016",
19750+
version: "19.3.0-native-fb-ed1351c4-20251016",
1975119751
rendererPackageName: "react-dom",
1975219752
currentDispatcherRef: ReactSharedInternals,
19753-
reconcilerVersion: "19.3.0-native-fb-d8aa94b0-20251016",
19753+
reconcilerVersion: "19.3.0-native-fb-ed1351c4-20251016",
1975419754
getLaneLabelMap: function () {
1975519755
for (
1975619756
var map = new Map(), lane = 1, index$332 = 0;
@@ -20026,7 +20026,7 @@ exports.useFormState = function (action, initialState, permalink) {
2002620026
exports.useFormStatus = function () {
2002720027
return ReactSharedInternals.H.useHostTransitionStatus();
2002820028
};
20029-
exports.version = "19.3.0-native-fb-d8aa94b0-20251016";
20029+
exports.version = "19.3.0-native-fb-ed1351c4-20251016";
2003020030
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
2003120031
"function" ===
2003220032
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&

0 commit comments

Comments
 (0)