Track HiveGrid Cloud planning reference
This commit is contained in:
1 parent
b3d5ea6764
commit
e341c5938a
5784 files changed
+1104929
-3
No files matched your search
@@ -0,0 +1,43 @@
|
||||
import { render, waitFor } from "@testing-library/react";
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
|
||||
vi.mock("@sentry/react-router", () => {
|
||||
const sentryOnError = vi.fn();
|
||||
return {
|
||||
__esModule: true,
|
||||
sentryOnError,
|
||||
};
|
||||
});
|
||||
|
||||
import * as Sentry from "@sentry/react-router";
|
||||
|
||||
import { RouteTracingProvider, sentryHydrationErrorHandler } from "./routeTracing";
|
||||
|
||||
const mockedOnError = Sentry.sentryOnError as unknown as ReturnType<typeof vi.fn>;
|
||||
|
||||
describe("sentryHydrationErrorHandler", () => {
|
||||
it("delegates to Sentry.sentryOnError", async () => {
|
||||
const err = new Error("hydration-boom");
|
||||
const info = { errorInfo: { componentStack: "test-stack" } as React.ErrorInfo };
|
||||
sentryHydrationErrorHandler(err, info);
|
||||
await waitFor(() => expect(mockedOnError).toHaveBeenCalledWith(err, info));
|
||||
});
|
||||
|
||||
it("swallows exceptions thrown by the SDK", () => {
|
||||
mockedOnError.mockImplementationOnce(() => {
|
||||
throw new Error("sdk-down");
|
||||
});
|
||||
expect(() => sentryHydrationErrorHandler(new Error("boom"), {})).not.toThrow();
|
||||
});
|
||||
});
|
||||
|
||||
describe("RouteTracingProvider", () => {
|
||||
it("renders its children unchanged", () => {
|
||||
const { getByText } = render(
|
||||
<RouteTracingProvider>
|
||||
<span>route-tracing-content</span>
|
||||
</RouteTracingProvider>
|
||||
);
|
||||
expect(getByText("route-tracing-content")).toBeTruthy();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,51 @@
|
||||
/**
|
||||
* React Router v7 Sentry tracing glue.
|
||||
*
|
||||
* `@sentry/react-router` v10 supports the React Router v7 Framework Mode
|
||||
* natively. The auto-instrumentation is set up by `reactRouterTracingIntegration()`
|
||||
* which is registered in `apps/web/app/sentry.client.ts` — no manual
|
||||
* `wrapCreateBrowserRouter` is required.
|
||||
*
|
||||
* This module exposes two thin helpers:
|
||||
*
|
||||
* - {@link sentryHydrationErrorHandler} — to be passed to `<HydratedRouter onError={...}>`.
|
||||
* Delegates to `Sentry.sentryOnError` when the SDK is loaded; falls
|
||||
* back to a no-op so non-Sentry builds stay green.
|
||||
* - {@link RouteTracingProvider} — a tiny provider that exists so the
|
||||
* manual fallback path is wired uniformly. Today it is a passthrough
|
||||
* because the official integration handles navigation spans
|
||||
* internally; the wrapping component gives us a stable seam for
|
||||
* bug fixes that need to capture extra navigation context without
|
||||
* editing `root.tsx` again.
|
||||
*
|
||||
* @see docs/improvement-plan/02-observability/sentry-wiring-web.md (Step 7)
|
||||
*/
|
||||
import type { ReactNode } from "react";
|
||||
|
||||
export function sentryHydrationErrorHandler(error: unknown, info: { errorInfo?: React.ErrorInfo }): void {
|
||||
void import("@sentry/react-router")
|
||||
.then((Sentry) => {
|
||||
Sentry.sentryOnError(error, info);
|
||||
})
|
||||
.catch(() => {
|
||||
// If the SDK has not been initialized (DSN unset) or the export is
|
||||
// missing on older versions, fall back silently. The framework's
|
||||
// built-in default error handler still runs because React Router's
|
||||
// `onError` is purely additive — it does not replace the default
|
||||
// logging.
|
||||
});
|
||||
}
|
||||
|
||||
export interface RouteTracingProviderProps {
|
||||
children: ReactNode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Passthrough provider that documents the integration point. Wrapping
|
||||
* `<Outlet />` (or the entire app tree) in this component gives us a
|
||||
* stable seam to add navigation-context enrichment later without
|
||||
* needing to edit `root.tsx` again.
|
||||
*/
|
||||
export function RouteTracingProvider({ children }: RouteTracingProviderProps) {
|
||||
return <>{children}</>;
|
||||
}
|
||||
Reference in new issue
Block a user