Skip to content

Commit 6d8c7cc

Browse files
justin808claude
andcommitted
Reuse OSS defaultReportRecoverableError in Pro recoverable-error chain
Accepted /simplify finding: the Pro-local reportRecoverableError was byte-identical to the OSS helper introduced for the dev-mode logger. Export the OSS helper and import it in Pro so the "report exactly once" contract has a single implementation. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
1 parent 8678960 commit 6d8c7cc

2 files changed

Lines changed: 3 additions & 10 deletions

File tree

packages/react-on-rails-pro/src/handleRecoverableError.client.ts

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
*/
1515

1616
import type { ReactHydrateOptions } from 'react-on-rails/reactApis';
17+
import { defaultReportRecoverableError } from 'react-on-rails/@internal/rootErrorHandlers';
1718
import { isRSCRouteSSRFalseBailoutError } from './RSCRouteSSRFalseBailoutError.ts';
1819

1920
const getRecoverableErrorCause = (error: unknown): unknown =>
@@ -22,14 +23,6 @@ const getRecoverableErrorCause = (error: unknown): unknown =>
2223
const isRSCRouteSSRFalseBailout = (error: unknown): boolean =>
2324
isRSCRouteSSRFalseBailoutError(error) || isRSCRouteSSRFalseBailoutError(getRecoverableErrorCause(error));
2425

25-
const reportRecoverableError = (error: unknown) => {
26-
if (typeof globalThis.reportError === 'function') {
27-
globalThis.reportError(error);
28-
} else {
29-
console.error(error);
30-
}
31-
};
32-
3326
/**
3427
* Builds an `onRecoverableError` root option that chains Pro's internal recoverable-error
3528
* reporting with a user-registered `rootErrorHandlers.onRecoverableError` callback (already
@@ -49,7 +42,7 @@ export const chainRecoverableErrorHandlers =
4942
if (isRSCRouteSSRFalseBailout(error)) {
5043
return;
5144
}
52-
reportRecoverableError(error);
45+
defaultReportRecoverableError(error);
5346
next?.(error, errorInfo);
5447
};
5548

packages/react-on-rails/src/rootErrorHandlers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ function inDevelopmentEnv(): boolean {
132132
* dev-mode logger must re-emit it itself — otherwise window-'error'-based tooling (dev overlays,
133133
* error trackers) goes silent in development.
134134
*/
135-
function defaultReportRecoverableError(error: unknown): void {
135+
export function defaultReportRecoverableError(error: unknown): void {
136136
if (typeof globalThis.reportError === 'function') {
137137
globalThis.reportError(error);
138138
} else {

0 commit comments

Comments
 (0)