Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
15 changes: 14 additions & 1 deletion apps/mobile/src/features/diffs/nativeReviewDiffSurface.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,23 @@ describe("resolveNativeReviewDiffView", () => {

it("returns null when the view manager cannot be required", async () => {
setExpoViewConfigAvailable();
const cause = new Error("boom");
expoMocks.requireNativeView.mockImplementation(() => {
throw new Error("boom");
throw cause;
});
const consoleError = vi.spyOn(console, "error").mockImplementation(() => undefined);
const { resolveNativeReviewDiffView } = await import("./nativeReviewDiffSurface");

expect(resolveNativeReviewDiffView()).toBeNull();
expect(resolveNativeReviewDiffView()).toBeNull();
expect(expoMocks.requireNativeView).toHaveBeenCalledTimes(1);
expect(consoleError).toHaveBeenCalledWith(
expect.objectContaining({
_tag: "NativeViewResolutionError",
nativeModuleName: "T3ReviewDiffSurface",
cause,
}),
);
expect(consoleError).toHaveBeenCalledTimes(1);
});
});
16 changes: 15 additions & 1 deletion apps/mobile/src/features/diffs/nativeReviewDiffSurface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import type { ComponentType } from "react";
import type { NativeSyntheticEvent, ViewProps } from "react-native";
import { requireNativeView } from "expo";

import { NativeViewResolutionError } from "../../native/nativeViewResolutionError";

const NATIVE_REVIEW_DIFF_MODULE_NAME = "T3ReviewDiffSurface";

interface ExpoGlobalWithViewConfig {
Expand Down Expand Up @@ -128,6 +130,7 @@ export interface NativeReviewDiffViewProps extends ViewProps {
}

let cachedNativeReviewDiffView: ComponentType<NativeReviewDiffViewProps> | undefined;
let nativeReviewDiffViewResolutionFailed = false;

function getExpoViewConfig(moduleName: string) {
return (globalThis as typeof globalThis & ExpoGlobalWithViewConfig).expo?.getViewConfig?.(
Expand All @@ -140,6 +143,10 @@ export function resolveNativeReviewDiffView(): ComponentType<NativeReviewDiffVie
return cachedNativeReviewDiffView;
}

if (nativeReviewDiffViewResolutionFailed) {
return null;
}

if (getExpoViewConfig(NATIVE_REVIEW_DIFF_MODULE_NAME) == null) {
return null;
}
Expand All @@ -148,7 +155,14 @@ export function resolveNativeReviewDiffView(): ComponentType<NativeReviewDiffVie
cachedNativeReviewDiffView = requireNativeView<NativeReviewDiffViewProps>(
NATIVE_REVIEW_DIFF_MODULE_NAME,
);
} catch {
} catch (cause) {
nativeReviewDiffViewResolutionFailed = true;
console.error(
new NativeViewResolutionError({
nativeModuleName: NATIVE_REVIEW_DIFF_MODULE_NAME,
cause,
}),
);
Comment thread
juliusmarminge marked this conversation as resolved.
return null;
}

Expand Down
15 changes: 14 additions & 1 deletion apps/mobile/src/features/terminal/nativeTerminalModule.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,23 @@ describe("resolveNativeTerminalSurfaceView", () => {

it("returns null when the view manager cannot be required", async () => {
setExpoViewConfigAvailable();
const cause = new Error("boom");
expoMocks.requireNativeView.mockImplementation(() => {
throw new Error("boom");
throw cause;
});
const consoleError = vi.spyOn(console, "error").mockImplementation(() => undefined);
const { resolveNativeTerminalSurfaceView } = await import("./nativeTerminalModule");

expect(resolveNativeTerminalSurfaceView()).toBeNull();
expect(resolveNativeTerminalSurfaceView()).toBeNull();
expect(expoMocks.requireNativeView).toHaveBeenCalledTimes(1);
expect(consoleError).toHaveBeenCalledWith(
expect.objectContaining({
_tag: "NativeViewResolutionError",
nativeModuleName: "T3TerminalSurface",
cause,
}),
);
expect(consoleError).toHaveBeenCalledTimes(1);
});
});
16 changes: 15 additions & 1 deletion apps/mobile/src/features/terminal/nativeTerminalModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import type { ComponentType } from "react";
import type { NativeSyntheticEvent, ViewProps } from "react-native";
import { requireNativeView } from "expo";

import { NativeViewResolutionError } from "../../native/nativeViewResolutionError";

const NATIVE_TERMINAL_MODULE_NAME = "T3TerminalSurface";

interface ExpoGlobalWithViewConfig {
Expand Down Expand Up @@ -33,6 +35,7 @@ export interface NativeTerminalSurfaceProps extends ViewProps {
}

let cachedNativeTerminalSurfaceView: ComponentType<NativeTerminalSurfaceProps> | undefined;
let nativeTerminalSurfaceViewResolutionFailed = false;

function getExpoViewConfig(moduleName: string) {
return (globalThis as typeof globalThis & ExpoGlobalWithViewConfig).expo?.getViewConfig?.(
Expand All @@ -45,6 +48,10 @@ export function resolveNativeTerminalSurfaceView(): ComponentType<NativeTerminal
return cachedNativeTerminalSurfaceView;
}

if (nativeTerminalSurfaceViewResolutionFailed) {
return null;
}

if (getExpoViewConfig(NATIVE_TERMINAL_MODULE_NAME) == null) {
return null;
}
Expand All @@ -53,7 +60,14 @@ export function resolveNativeTerminalSurfaceView(): ComponentType<NativeTerminal
cachedNativeTerminalSurfaceView = requireNativeView<NativeTerminalSurfaceProps>(
NATIVE_TERMINAL_MODULE_NAME,
);
} catch {
} catch (cause) {
nativeTerminalSurfaceViewResolutionFailed = true;
console.error(
new NativeViewResolutionError({
nativeModuleName: NATIVE_TERMINAL_MODULE_NAME,
cause,
}),
);
return null;
}

Expand Down
13 changes: 13 additions & 0 deletions apps/mobile/src/native/nativeViewResolutionError.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import * as Schema from "effect/Schema";

export class NativeViewResolutionError extends Schema.TaggedErrorClass<NativeViewResolutionError>()(
"NativeViewResolutionError",
{
nativeModuleName: Schema.String,
cause: Schema.Defect(),
},
) {
override get message(): string {
return `Failed to resolve native view ${this.nativeModuleName}.`;
}
}
Loading