Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: handle early JS errors like in Metro #829

Merged
merged 9 commits into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
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: 5 additions & 0 deletions .changeset/late-crabs-deliver.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@callstack/repack": patch
---

Fix early JS errors not being displayed in LogBox
1 change: 1 addition & 0 deletions apps/tester-app/android/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ reactNativeArchitectures=armeabi-v7a,arm64-v8a,x86,x86_64
# Note that this is incompatible with web debugging.
newArchEnabled=true
bridgelessEnabled=true
hermesEnabled=true

# Uncomment the line below to build React Native from source.
#react.buildFromSource=true
Expand Down
4 changes: 2 additions & 2 deletions apps/tester-app/ios/Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
PODS:
- boost (1.84.0)
- callstack-repack (5.0.0-rc.2):
- callstack-repack (5.0.0-rc.3):
- DoubleConversion
- glog
- hermes-engine
Expand Down Expand Up @@ -1942,7 +1942,7 @@ EXTERNAL SOURCES:

SPEC CHECKSUMS:
boost: 1dca942403ed9342f98334bf4c3621f011aa7946
callstack-repack: 3106db24c24f7a76a380230ff7794d225cecb760
callstack-repack: 5219eedfb8cb06b905edecffaecf71af4a4ecdd6
DoubleConversion: f16ae600a246532c4020132d54af21d0ddb2a385
FBLazyVector: be7314029d6ec6b90f0f75ce1195b8130ed9ac4f
fmt: 10c6e61f4be25dc963c36bd73fc7b1705fe975be
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ jest.mock('../NativeScriptManager', () => ({
}));

globalThis.__webpack_require__ = {
i: [],
u: (id: string) => `${id}.chunk.bundle`,
p: () => '',
repack: {
Expand Down
19 changes: 19 additions & 0 deletions packages/repack/src/modules/ScriptManager/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,23 @@
type ModuleExports = Record<string | number | symbol, any>;

type ModuleObject = {
id: number;
loaded: boolean;
error?: any;
exports: ModuleExports;
};

export interface WebpackContext {
i: ((options: {
id: number;
factory: (
moduleObject: ModuleObject,
moduleExports: ModuleExports,
webpackRequire: WebpackContext
) => void;
module: ModuleObject;
require: WebpackContext;
}) => void)[];
p: () => string;
u: (id: string) => string;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ export class RepackTargetPlugin implements RspackPluginInstance {
compiler.options.output.chunkFormat = 'array-push';
compiler.options.output.globalObject = globalObject;

// Disable built-in strict module error handling
// this is handled through an interceptor in the
// init module added to __webpack_require__.i array
compiler.options.output.strictModuleErrorHandling = false;

// Normalize global object.
new compiler.webpack.BannerPlugin({
raw: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,18 @@ module.exports = function () {

__webpack_require__.repack = $globalObject$.__repack__ = repackRuntime;

// intercept module factory calls to forward errors to global.ErrorUtils
__webpack_require__.i.push(function (options) {
var originalFactory = options.factory;
options.factory = function (moduleObject, moduleExports, webpackRequire) {
try {
originalFactory.call(this, moduleObject, moduleExports, webpackRequire);
} catch (e) {
$globalObject$.ErrorUtils.reportFatalError(e);
jbroma marked this conversation as resolved.
Show resolved Hide resolved
}
};
});

function loadScript(
name: string,
caller: string | undefined,
Expand Down
Loading