Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
fa35b70
chore: add repack
OlimpiaZurek Jul 21, 2026
07b2f00
fix: sign in not working under repack
OlimpiaZurek Jul 21, 2026
c90d413
fix: CI checks
OlimpiaZurek Jul 21, 2026
2aaa1f6
chore: add OXC parser for mobile
OlimpiaZurek Jul 22, 2026
c1b3c1a
Merge branch 'main' into ft/repack-poc
OlimpiaZurek Jul 22, 2026
4bc297b
Merge branch 'main' into ft/repack-poc
OlimpiaZurek Jul 22, 2026
6073a74
fix config
OlimpiaZurek Jul 22, 2026
7f2076e
fix profiling aliases
OlimpiaZurek Jul 22, 2026
ec46b09
fix: Hermes loop var capture
OlimpiaZurek Jul 22, 2026
553baae
Merge branch 'main' into ft/repack-poc
OlimpiaZurek Jul 28, 2026
10edc2e
Merge branch 'main' into ft/repack-poc
OlimpiaZurek Jul 28, 2026
e4de033
fix lint
OlimpiaZurek Jul 28, 2026
9010cb7
Merge branch 'main' into ft/repack-poc
OlimpiaZurek Jul 28, 2026
f73a534
Merge branch 'main' into ft/repack-poc
OlimpiaZurek Jul 28, 2026
7cafdb3
Merge branch 'main' into ft/repack-poc
OlimpiaZurek Jul 29, 2026
de7d01d
move rspack config
OlimpiaZurek Jul 29, 2026
b494849
fix(repack): enable production JS bundle minification
OlimpiaZurek Jul 29, 2026
b5ce702
Merge branch 'main' into ft/repack-poc
OlimpiaZurek Jul 31, 2026
0534679
fix persistent cache and worklets crashes
OlimpiaZurek Jul 31, 2026
6b73156
spell check fix
OlimpiaZurek Jul 31, 2026
abbbb11
fix ts
OlimpiaZurek Jul 31, 2026
caea815
fix: defer imports via inline-requires instead of SWC lazy mode
OlimpiaZurek Aug 3, 2026
7fa2e2a
fix spellcheck
OlimpiaZurek Aug 3, 2026
81bc961
Exclude dotlottie-react prebuilt bundle from babel-swc loader
elirangoshen Aug 13, 2026
50ec572
Route non-babel node_modules through the OXC pipeline
elirangoshen Aug 21, 2026
842920a
Shorten config comments
elirangoshen Aug 21, 2026
8b41085
Merge remote-tracking branch 'upstream/main' into eliran/2733-dotlott…
elirangoshen Aug 21, 2026
9f1f584
Remove comments that restate the code
elirangoshen Aug 25, 2026
d7aafb9
Merge remote-tracking branch 'upstream/main' into eliran/2733-dotlott…
elirangoshen Aug 25, 2026
dbfc762
Fix tsconfig formatting
elirangoshen Aug 25, 2026
2b86082
Match Metro's @flow pragma gate in the Re.Pack babel lane
elirangoshen Aug 27, 2026
6b89eff
Merge remote-tracking branch 'upstream/main' into eliran/2733-dotlott…
elirangoshen Sep 3, 2026
4b193c6
Declare hermes-parser as a direct devDependency
elirangoshen Sep 3, 2026
b7bd9f5
Rewrite Re.Pack config comments as plain sentences
elirangoshen Sep 3, 2026
ecc1f5b
Select the native bundler with a BUNDLER env var
elirangoshen Sep 3, 2026
26e7f45
Stamp Sentry Debug IDs into native release bundles
elirangoshen Sep 4, 2026
75a92b1
Ignore the Sentry debug-id marker in cspell
elirangoshen Sep 4, 2026
62c60ba
Route @fullstory/react-native through the babel lane
elirangoshen Sep 4, 2026
e4d06c4
Merge remote-tracking branch 'upstream/main' into eliran/2733-dotlott…
elirangoshen Sep 7, 2026
db3a016
Merge remote-tracking branch 'upstream/main' into eliran/2733-dotlott…
kacper-mikolajczak Sep 8, 2026
bd74fa7
fix: re-hydrate package-lock against main and restore patched action …
kacper-mikolajczak Sep 8, 2026
3ffa1eb
fix: address Re.Pack dev-server review feedback
kacper-mikolajczak Sep 9, 2026
1b89f9d
fix: clamp Re.Pack dev server progress so it never runs backwards
kacper-mikolajczak Sep 9, 2026
5b03a65
fix double platform loaders
kacper-mikolajczak Sep 10, 2026
10a63af
drop comment-only churn from the review-feedback commits
kacper-mikolajczak Sep 10, 2026
1a8378d
docs: add details.md for the Re.Pack progress patch
kacper-mikolajczak Sep 10, 2026
7b582b7
Merge remote-tracking branch 'upstream/main' into eliran/2733-dotlott…
kacper-mikolajczak Sep 10, 2026
d94e95e
Share one React Compiler config and compile native platforms on demand
kacper-mikolajczak Sep 15, 2026
d2c7b46
Merge remote-tracking branch 'upstream/main' into eliran/2733-dotlott…
elirangoshen Sep 17, 2026
e029c2c
Merge remote-tracking branch 'upstream/main' into eliran/2733-dotlott…
elirangoshen Sep 18, 2026
45e1fb5
Restore --verbose on rock run:ios and run:android
elirangoshen Sep 18, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,10 @@ react {
//
// A list of extra flags to pass to the 'bundle' commands.
// See https://github.com/react-native-community/cli/blob/main/docs/commands.md#bundle
// extraPackagerArgs = []
// Force `--minify true` for Repack. The RN gradle task hardcodes minifyEnabled=false when Hermes
// is on, an assumption from the Metro era. Under Repack the SWC minifier does real dead-code
// elimination and tree-shaking, and commander applies the last value passed.
extraPackagerArgs = ["--minify", "true"]

/* Hermes Commands */
// The hermes compiler command to run. By default it is 'hermesc'
Expand Down
16 changes: 14 additions & 2 deletions babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,15 @@ if (process.env.CAPTURE_METRICS === 'true') {
]);
}

const repack = {
...metro,
plugins: metro.plugins
.filter((plugin) => !(Array.isArray(plugin) && plugin[0] === 'module-resolver' && plugin[2] !== 'extra-alias'))
.map((plugin) => (Array.isArray(plugin) && plugin[0] === 'react-native-worklets/plugin' ? 'react-native-worklets/plugin' : plugin)),
};

module.exports = (api) => {
if (!process.env.KNIP) {
if (process.env.DEBUG_BABEL_CONFIG === 'true') {
console.debug('babel.config.js');
console.debug(' - api.version:', api.version);
console.debug(' - api.env:', api.env());
Expand All @@ -170,12 +177,17 @@ module.exports = (api) => {
}

// For `react-native` (iOS/Android) caller will be "metro"
// For `@callstack/repack` (Re.Pack native bundler) caller will be "@callstack/repack"
// For jest, it will be babel-jest
// The web build and Storybook (Rsbuild) don't call into this file at all
const runningIn = api.caller((args = {}) => args.name);
if (!process.env.KNIP) {
if (process.env.DEBUG_BABEL_CONFIG === 'true') {
console.debug(' - running in: ', runningIn);
}

if (runningIn === '@callstack/repack') {
return repack;
}

return ['metro', 'babel-jest'].includes(runningIn) ? metro : {};
};
10 changes: 3 additions & 7 deletions config/babel/oxcJestTransformer.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const {transformSync} = require('oxc-transform-react');

const babelJest = require('babel-jest');
const OXC_TRANSFORM_REACT_VERSION = require('oxc-transform-react/package.json').version;
const BaseReactCompilerConfig = require('./reactCompilerConfig');
const oxcReactCompilerConfig = require('./oxcReactCompilerConfig');

const babelTransformer = babelJest.createTransformer();

Expand All @@ -16,13 +16,9 @@ const JEST_SETUP_RE = /[/\\]jest[/\\]/;
const MOCKS_RE = /[/\\]__mocks__[/\\]/;

const TRANSFORMER_SOURCE = fs.readFileSync(__filename);
const REACT_COMPILER_CONFIG_KEY = JSON.stringify(BaseReactCompilerConfig);
const REACT_COMPILER_CONFIG_KEY = JSON.stringify(oxcReactCompilerConfig());

const REACT_COMPILER_OPTIONS = {
...BaseReactCompilerConfig,
panicThreshold: 'none',
eslintSuppressionRules: [],
};
const REACT_COMPILER_OPTIONS = oxcReactCompilerConfig();

function getLang(filename) {
const ext = path.extname(filename).slice(1);
Expand Down
4 changes: 4 additions & 0 deletions config/babel/oxcReactCompilerConfig.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/** CJS implementation in `oxcReactCompilerConfig.js`, typed so the Rsbuild TS configs can import it. */
declare function oxcReactCompilerConfig(overrides?: Record<string, unknown>): Record<string, unknown>;

export = oxcReactCompilerConfig;
29 changes: 29 additions & 0 deletions config/babel/oxcReactCompilerConfig.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/**
* The React Compiler options OXC compiles with, in one place: Re.Pack native, Rsbuild web, the Jest
* transform and the react-compiler checker. Each used to spell out its own. The native build ended up
* without two of them, so components carrying `react-hooks` suppressions shipped with no memoization
* while the web build and the checker memoized the same files.
*/
const BaseReactCompilerConfig = require('./reactCompilerConfig');

/**
* `eslintSuppressionRules: []` matches the Babel/Metro lane. Without it OXC treats a `react-hooks`
* suppression as an opt-out of compilation. `isDev` is absent because OXC has no such option, so
* passing it changes nothing.
*
* Overrides are limited to `sources` (web compiles node_modules too) and `panicThreshold` (the checker
* needs diagnostics). Two lanes differing any other way is a bug.
*
* @param {Record<string, unknown>} [overrides] applied last
* @returns {Record<string, unknown>}
*/
function oxcReactCompilerConfig(overrides = {}) {
return {
...BaseReactCompilerConfig,
eslintSuppressionRules: [],
panicThreshold: 'none',
...overrides,
};
}

module.exports = oxcReactCompilerConfig;
2 changes: 1 addition & 1 deletion config/eslint/eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,7 @@ const config = defineConfig([

// Rspack loaders receive their `this` from the bundler, and it's standard practice to use it
{
files: ['config/rsbuild/loaders/*-loader.mjs'],
files: ['config/rsbuild/loaders/*-loader.mjs', 'config/repack/*-loader.mjs'],
rules: {
'no-invalid-this': 'off',
},
Expand Down
14 changes: 7 additions & 7 deletions config/reactCompiler/checkWithOxc.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
* React Compiler analysis via oxc-transform-react (sync).
*
* Shared 3-state API for the ESLint processor and the CI compliance check.
* Mirrors web build options from config/rsbuild/rsbuild.common.ts.
* Options come from config/babel/oxcReactCompilerConfig.js, the same object the build lanes compile
* with. Only `panicThreshold` differs here, for the reason below.
*
* `panicThreshold: 'critical_errors'` is what splits the two kinds of diagnostic apart:
* a Rules-of-React violation aborts the whole transform, while a
Expand All @@ -24,6 +25,8 @@
import path from 'node:path';
import {transformSync} from 'oxc-transform-react';

import oxcReactCompilerConfig from '../babel/oxcReactCompilerConfig.js';

// Any file compiled by React Compiler will have a _c marker in it
const REACT_COMPILER_MARKER_PATTERN = /_c\(|react\/compiler-runtime/;

Expand Down Expand Up @@ -75,13 +78,10 @@ function checkReactCompilerWithOxc(source, filename) {
const lang = getLang(ext);
const transformOptions = {
lang,
reactCompiler: {
target: '19',
reactCompiler: oxcReactCompilerConfig({
// 'critical_errors' splits the two kinds of diagnostic apart; the builds use 'none'.
panicThreshold: 'critical_errors',
// Kept in sync with the web build: see the `eslintSuppressionRules` comment in
// config/rsbuild/rsbuild.common.ts.
eslintSuppressionRules: [],
},
}),
};

try {
Expand Down
132 changes: 132 additions & 0 deletions config/repack/cjs-inline-requires-loader.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
/**
* Lowers ES modules to CommonJS and defers each `require()` to its first use site. This gives the
* same import-cycle tolerance Metro gets from `inlineRequires` (see metro.config.js), which this
* app relies on to boot.
*
* Uses Metro's own `inlineRequiresPlugin` rather than SWC's `module.lazy`. Both defer ~100% of
* imports, but SWC's lazy mode emits a memoizing wrapper function per imported module. That is
* about 103k extra functions here, worth about 7MB of Hermes bytecode. Inlining the require at
* the use site defers identically and emits no wrapper.
*
* Needed as a separate stage because OXC transpiles only and has no CJS lowering.
*/
import babel from '@babel/core';
import remapping from '@jridgewell/remapping';
import {rspack} from '@rspack/core';
// CommonJS with lazy getters, so named ESM imports are not statically detectable.
import metroTransformPlugins from 'metro-transform-plugins';

const {inlineRequiresPlugin} = metroTransformPlugins;

/** SWC's interop wrappers for `import x from` and `import * as x from`. */
const INTEROP_HELPERS = new Set(['_interop_require_default', '_interop_require_wildcard']);

/**
* Extends inline-requires to SWC's interop-wrapped imports, which Metro's plugin alone cannot
* defer: it requires `arguments[0]` to be a string literal (SWC passes a `require()` call) and
* skips any call whose function is bound locally (SWC declares the helper in-file). Without this,
* default and namespace imports stay hoisted and eager. That is about half of all imports here,
* and exactly the cycle tolerance the loader exists to provide.
*
* Metro sidesteps the problem with a global `_$$_IMPORT_DEFAULT('x')` helper that resolves the
* module id at runtime. That is not portable to webpack, which must see a literal `require('x')`
* to add the module to the graph at all. So instead of hoisting the helper, we inline the whole
* initializer (the interop call and the literal require together) down to each use site.
*
* Repeating the interop call per use site is cheap: `_interop_require_wildcard` early-returns for
* `__esModule` objects and memoizes the rest in a WeakMap, and `_interop_require_default` is a
* single object literal on the non-ESM path.
*/
function inlineInteropRequiresPlugin({types: t}) {
const isInteropRequire = (node) =>
t.isCallExpression(node) &&
t.isIdentifier(node.callee) &&
INTEROP_HELPERS.has(node.callee.name) &&
node.arguments.length >= 1 &&
t.isCallExpression(node.arguments[0]) &&
t.isIdentifier(node.arguments[0].callee, {name: 'require'}) &&
node.arguments[0].arguments.length === 1 &&
t.isStringLiteral(node.arguments[0].arguments[0]);

return {
visitor: {
Program(programPath) {
for (const binding of Object.values(programPath.scope.bindings)) {
if (!binding.path.isVariableDeclarator() || !isInteropRequire(binding.path.node.init)) {
continue;
}
// Reassignment would make the inlined copies diverge from the original binding.
if (!binding.constant) {
continue;
}
// With no references there is nothing to inline into, and dropping the
// declaration would stop the module loading at all, since side-effect imports
// rely on it. Metro's plugin does remove these, but we stay conservative here.
if (binding.referencePaths.length === 0) {
continue;
}
for (const reference of binding.referencePaths) {
reference.replaceWith(t.cloneNode(binding.path.node.init, true));
}
binding.path.remove();
}
},
},
};
}

export default async function cjsInlineRequiresLoader(source, inputSourceMap) {
const callback = this.async();
try {
const options = this.getOptions() || {};
// On prebuilt bundles SWC can emit a multi-source map, which remapping() below rejects.
// The node_modules rule passes `sourcemap: false` to skip maps entirely.
const sourceMaps = options.sourcemap !== undefined ? options.sourcemap : !!this.sourceMap;

// App source only needs block-scoping (Hermes shares one binding across loop iterations).
// node_modules also ship async generators, which Hermes cannot parse, so the node_modules
// rule opts into lowering those too. Everything else modern Hermes handles natively.
const envInclude = options.hermesLowering ? ['transform-block-scoping', 'transform-async-to-generator', 'transform-async-generator-functions'] : ['transform-block-scoping'];

Comment thread
elirangoshen marked this conversation as resolved.
Resolved
const swcResult = await rspack.experiments.swc.transform(source, {
filename: this.resourcePath,
isModule: true,
env: {
targets: {node: 24},
include: envInclude,
},
jsc: options.hermesLowering
? {
// Loose-mode class lowering, same as the babel config's {loose: true} plugins.
assumptions: {setPublicClassFields: true, privateFieldsAsProperties: true},
}
: undefined,
module: {type: 'commonjs', lazy: false},
sourceMaps,
inputSourceMap: inputSourceMap ? JSON.stringify(inputSourceMap) : undefined,
});

const babelResult = await babel.transformAsync(swcResult.code, {
babelrc: false,
configFile: false,
filename: this.resourcePath,
// Interop-wrapped imports first, then Metro's plugin for the bare `require` form.
plugins: [inlineInteropRequiresPlugin, inlineRequiresPlugin],
sourceMaps,
// The minifier handles formatting; keeping newlines makes build output readable.
compact: false,
});

if (!sourceMaps || !babelResult.map) {
callback(null, babelResult.code);
return;
}

// swcResult.map already folds in inputSourceMap (passed above), so composing the Babel map
// onto it is enough to keep stack traces pointing at original sources.
const map = swcResult.map ? remapping([babelResult.map, swcResult.map], () => null) : babelResult.map;
callback(null, babelResult.code, map);
} catch (error) {
callback(error);
}
}
17 changes: 17 additions & 0 deletions config/repack/expoVirtualEnv.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/**
* Replacement for `expo/virtual/env` when bundling natively with Re.Pack (see rspack.config.mjs).
*
* Expo's own module is `export const env = process.env` and relies on Expo's Metro integration to
* populate EXPO_PUBLIC_* values at runtime. That integration does not exist under Re.Pack, leaving
* them undefined. Most importantly, `expo/src/winter/runtime.native` checks EXPO_PUBLIC_USE_RN_FETCH
* and, when falsy, replaces global fetch with expo/fetch. That needs ReadableStream, absent in
* Hermes, and breaks every API request. Keep React Native's built-in fetch, same as Metro builds
* (see metro.config.js / babel.config.js).
*/
const env: Record<string, string> = {
EXPO_PUBLIC_USE_RN_FETCH: '1',
};

// Must be a named export: expo's compiled code imports it as `import {env} from 'expo/virtual/env'`.
// eslint-disable-next-line import/prefer-default-export
export {env};
26 changes: 26 additions & 0 deletions config/repack/hermesParserShim.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/**
* Parser for Re.Pack's babel lane, mirroring what `babel-plugin-syntax-hermes-parser` does for
* Metro: hermes-parser only for files that opt into Flow with an `@flow` pragma, @babel/parser for
* everything else. Re.Pack calls hermes-parser unconditionally, which is 4x slower across this
* lane and pathological (95s) on prebuilt minified single-line bundles.
*
* Wired in via the babel-swc-loader's `hermesParserPath` option, which Re.Pack imports with
* `importDefaultESM` and then calls as `parser.parse(source, options)`.
*/

import {parse as babelParse} from '@babel/parser';
import * as hermesParser from 'hermes-parser';

// Matches @react-native/babel-preset's `parseLangTypes: 'flow'` gate.
const FLOW_PRAGMA = /@flow/;

const BABEL_PARSER_PLUGINS = ['flow', 'jsx'];

export default {
parse(code, options) {
if (FLOW_PRAGMA.test(code)) {
return hermesParser.parse(code, options);
}
return babelParse(code, {sourceType: options?.sourceType ?? 'unambiguous', plugins: BABEL_PARSER_PLUGINS});
},
};
Loading
Loading