Skip to content

Commit 69ac1d7

Browse files
committed
[compiler] Add support for commonjs (facebook#34589)
We previously always generated import statements for any modules that had to be required, notably the `import {c} from 'react/compiler-runtime'` for the memo cache function. However, this obviously doesn't work when the source is using commonjs. Now we check the sourceType of the module and generate require() statements if the source type is 'script'. I initially explored using https://babeljs.io/docs/babel-helper-module-imports, but the API design was unfortunately not flexible enough for our use-case. Specifically, our pipeline is as follows: * Compile individual functions. Generate candidate imports, pre-allocating the local names for those imports. * If the file is compiled successfully, actually add the imports to the program. Ie we need to pre-allocate identifier names for the imports before we add them to the program — but that isn't supported by babel-helper-module-imports. So instead we generate our own require() calls if the sourceType is script. DiffTrain build for [8ad773b](facebook@8ad773b)
1 parent 88489cf commit 69ac1d7

26 files changed

+1553
-1555
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.2.0-native-fb-cad813ac-20250923
1+
19.2.0-native-fb-8ad773b1-20250924

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<<2ed4b9dfad2066fd453dbef258c5270b>>
10+
* @generated SignedSource<<9c16e0645fb189599108ec815a3cca64>>
1111
*/
1212

1313
"use strict";
@@ -404,5 +404,5 @@ __DEV__ &&
404404
exports.useFormStatus = function () {
405405
return resolveDispatcher().useHostTransitionStatus();
406406
};
407-
exports.version = "19.2.0-native-fb-cad813ac-20250923";
407+
exports.version = "19.2.0-native-fb-8ad773b1-20250924";
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<<0ca17d66e56209964dce082f7dab20bf>>
10+
* @generated SignedSource<<2ba7a24595485f5678f07169a726feb9>>
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.2.0-native-fb-cad813ac-20250923";
206+
exports.version = "19.2.0-native-fb-8ad773b1-20250924";

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<<0ca17d66e56209964dce082f7dab20bf>>
10+
* @generated SignedSource<<2ba7a24595485f5678f07169a726feb9>>
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.2.0-native-fb-cad813ac-20250923";
206+
exports.version = "19.2.0-native-fb-8ad773b1-20250924";

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

Lines changed: 186 additions & 189 deletions
Large diffs are not rendered by default.

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

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

1313
/*
@@ -4995,7 +4995,7 @@ function updateSyncExternalStore(subscribe, getSnapshot, getServerSnapshot) {
49954995
);
49964996
if (null === workInProgressRoot) throw Error(formatProdErrorMessage(349));
49974997
isHydrating$jscomp$0 ||
4998-
0 !== (renderLanes & 124) ||
4998+
0 !== (renderLanes & 127) ||
49994999
pushStoreConsistencyCheck(fiber, getSnapshot, getServerSnapshot);
50005000
}
50015001
return getServerSnapshot;
@@ -5848,7 +5848,7 @@ var ContextOnlyDispatcher = {
58485848
getServerSnapshot = getSnapshot();
58495849
if (null === workInProgressRoot)
58505850
throw Error(formatProdErrorMessage(349));
5851-
0 !== (workInProgressRootRenderLanes & 124) ||
5851+
0 !== (workInProgressRootRenderLanes & 127) ||
58525852
pushStoreConsistencyCheck(fiber, getSnapshot, getServerSnapshot);
58535853
}
58545854
hook.memoizedState = getServerSnapshot;
@@ -11539,7 +11539,7 @@ function performWorkOnRoot(root$jscomp$0, lanes, forceSync) {
1153911539
if (0 !== (executionContext & 6)) throw Error(formatProdErrorMessage(327));
1154011540
var shouldTimeSlice =
1154111541
(!forceSync &&
11542-
0 === (lanes & 124) &&
11542+
0 === (lanes & 127) &&
1154311543
0 === (lanes & root$jscomp$0.expiredLanes)) ||
1154411544
checkIfRootIsPrerendering(root$jscomp$0, lanes),
1154511545
exitStatus = shouldTimeSlice
@@ -17529,14 +17529,14 @@ ReactDOMHydrationRoot.prototype.unstable_scheduleHydration = function (target) {
1752917529
};
1753017530
var isomorphicReactPackageVersion$jscomp$inline_2052 = React.version;
1753117531
if (
17532-
"19.2.0-native-fb-cad813ac-20250923" !==
17532+
"19.2.0-native-fb-8ad773b1-20250924" !==
1753317533
isomorphicReactPackageVersion$jscomp$inline_2052
1753417534
)
1753517535
throw Error(
1753617536
formatProdErrorMessage(
1753717537
527,
1753817538
isomorphicReactPackageVersion$jscomp$inline_2052,
17539-
"19.2.0-native-fb-cad813ac-20250923"
17539+
"19.2.0-native-fb-8ad773b1-20250924"
1754017540
)
1754117541
);
1754217542
ReactDOMSharedInternals.findDOMNode = function (componentOrElement) {
@@ -17558,10 +17558,10 @@ ReactDOMSharedInternals.findDOMNode = function (componentOrElement) {
1755817558
};
1755917559
var internals$jscomp$inline_2625 = {
1756017560
bundleType: 0,
17561-
version: "19.2.0-native-fb-cad813ac-20250923",
17561+
version: "19.2.0-native-fb-8ad773b1-20250924",
1756217562
rendererPackageName: "react-dom",
1756317563
currentDispatcherRef: ReactSharedInternals,
17564-
reconcilerVersion: "19.2.0-native-fb-cad813ac-20250923"
17564+
reconcilerVersion: "19.2.0-native-fb-8ad773b1-20250924"
1756517565
};
1756617566
if ("undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__) {
1756717567
var hook$jscomp$inline_2626 = __REACT_DEVTOOLS_GLOBAL_HOOK__;
@@ -17668,4 +17668,4 @@ exports.hydrateRoot = function (container, initialChildren, options) {
1766817668
listenToAllSupportedEvents(container);
1766917669
return new ReactDOMHydrationRoot(initialChildren);
1767017670
};
17671-
exports.version = "19.2.0-native-fb-cad813ac-20250923";
17671+
exports.version = "19.2.0-native-fb-8ad773b1-20250924";

0 commit comments

Comments
 (0)