@lookiero/checkout 0.6.0-beta.30 → 0.6.0-beta.32
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/infrastructure/ui/Root.js +1 -3
- package/dist/infrastructure/ui/routing/Routing.d.ts +3 -3
- package/dist/infrastructure/ui/routing/Routing.js +14 -92
- package/dist/shared/logging/SentryDependencies.d.ts +5 -4
- package/dist/shared/logging/SentryDependencies.js +7 -5
- package/dist/shared/logging/SentryDependencies.native.d.ts +5 -4
- package/dist/shared/logging/SentryDependencies.native.js +8 -7
- package/dist/shared/logging/SentryLogger.d.ts +0 -1
- package/dist/shared/logging/SentryLogger.js +5 -11
- package/dist/shared/logging/matchRoutes.d.ts +3 -6
- package/dist/shared/logging/matchRoutes.js +4 -4
- package/dist/shared/logging/reactRouterV6Instrumentation.native.d.ts +8 -8
- package/dist/shared/logging/reactRouterV6Instrumentation.native.js +78 -2
- package/dist/shared/logging/types.d.ts +14 -0
- package/dist/shared/logging/types.js +1 -0
- package/package.json +1 -1
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import React, { useCallback } from "react";
|
|
2
2
|
import { Platform } from "react-native";
|
|
3
|
-
import {
|
|
4
|
-
//Routes as ReactRouterRoutes
|
|
5
|
-
useRoutes as reactRouterUseRoutes, } from "react-router-native";
|
|
3
|
+
import { useRoutes as reactRouterUseRoutes } from "react-router-native";
|
|
6
4
|
import { sentryLogger } from "../../shared/logging/SentryLogger";
|
|
7
5
|
import { Routing } from "./routing/Routing";
|
|
8
6
|
const root = ({ Messaging, I18n, getAuthToken, development, sentry }) => {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { I18n } from "@lookiero/i18n-react";
|
|
2
|
-
import
|
|
2
|
+
import React from "react";
|
|
3
3
|
import { useRoutes as reactRouterUseRoutes } from "react-router-native";
|
|
4
4
|
import { Customer } from "../../../projection/shared/customer";
|
|
5
5
|
import { Menu, TabBar } from "../views/navigation/Navigation";
|
|
@@ -16,11 +16,11 @@ interface RoutingProps {
|
|
|
16
16
|
readonly useRedirect: () => Record<string, string>;
|
|
17
17
|
readonly useRoutes: typeof reactRouterUseRoutes;
|
|
18
18
|
}
|
|
19
|
-
declare const Routing: FC<RoutingProps>;
|
|
20
19
|
/**
|
|
21
20
|
* Provided useRoutes is not stable (when integrated with Sentry) as it's rendering a different component tree.
|
|
22
21
|
*
|
|
23
22
|
* https://github.com/getsentry/sentry-javascript/blob/master/packages/react/src/reactrouterv6.tsx#L221
|
|
24
23
|
* (SentryRoutes is a new component after each re-render)
|
|
25
24
|
*/
|
|
26
|
-
|
|
25
|
+
declare const MemoizedRouting: React.NamedExoticComponent<RoutingProps>;
|
|
26
|
+
export { MemoizedRouting as Routing };
|
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
import React, { lazy, Suspense } from "react";
|
|
2
|
-
import {
|
|
3
|
-
// Routes as ReactRouterRoutes,
|
|
4
|
-
// Route,
|
|
5
|
-
Navigate, Outlet, useRoutes as reactRouterUseRoutes, } from "react-router-native";
|
|
1
|
+
import React, { lazy, memo, Suspense } from "react";
|
|
2
|
+
import { Navigate, Outlet, useRoutes as reactRouterUseRoutes } from "react-router-native";
|
|
6
3
|
import { Spinner } from "../../../shared/ui/components/atoms/spinner/Spinner";
|
|
7
4
|
import { App } from "../views/App";
|
|
8
5
|
import { CheckoutPaymentModal } from "../views/checkout/components/checkoutPaymentModal/CheckoutPaymentModal";
|
|
@@ -15,92 +12,10 @@ const Item = lazy(() => import("../views/item/Item").then((module) => ({ default
|
|
|
15
12
|
const Summary = lazy(() => import("../views/summary/Summary").then((module) => ({ default: module.Summary })));
|
|
16
13
|
const Checkout = lazy(() => import("../views/checkout/Checkout").then((module) => ({ default: module.Checkout })));
|
|
17
14
|
const Feedback = lazy(() => import("../views/feedback/Feedback").then((module) => ({ default: module.Feedback })));
|
|
18
|
-
const Routing = ({ basePath = "", customer, locale, I18n, menu, tabBar, getAuthToken, onI18nError, onNotAccessible, useRedirect, useRoutes = reactRouterUseRoutes,
|
|
19
|
-
// rootRoutes: RootRoutes,
|
|
20
|
-
}) => {
|
|
21
|
-
// return (
|
|
22
|
-
// <RootRoutes>
|
|
23
|
-
// <Route
|
|
24
|
-
// path=""
|
|
25
|
-
// element={
|
|
26
|
-
// <BasePathProvider basePath={basePath}>
|
|
27
|
-
// <CheckoutAccessibilityMiddleware customerId={customer?.customerId} onNotAccessible={onNotAccessible}>
|
|
28
|
-
// <I18n loader={<Spinner />} locale={locale} onError={onI18nError}>
|
|
29
|
-
// <CheckoutMiddleware customerId={customer?.customerId as string}>
|
|
30
|
-
// <App customerId={customer?.customerId as string} menu={menu} tabBar={tabBar}>
|
|
31
|
-
// <Outlet />
|
|
32
|
-
// </App>
|
|
33
|
-
// </CheckoutMiddleware>
|
|
34
|
-
// </I18n>
|
|
35
|
-
// </CheckoutAccessibilityMiddleware>
|
|
36
|
-
// </BasePathProvider>
|
|
37
|
-
// }
|
|
38
|
-
// >
|
|
39
|
-
// <Route
|
|
40
|
-
// path={Routes.INTRO}
|
|
41
|
-
// element={
|
|
42
|
-
// <Suspense fallback={<Spinner />}>
|
|
43
|
-
// <Intro customerId={customer?.customerId as string} />
|
|
44
|
-
// </Suspense>
|
|
45
|
-
// }
|
|
46
|
-
// />
|
|
47
|
-
// <Route
|
|
48
|
-
// path={Routes.ITEM}
|
|
49
|
-
// element={
|
|
50
|
-
// <Suspense fallback={<Spinner />}>
|
|
51
|
-
// <Item country={customer?.country as Country} customerId={customer?.customerId as string} />
|
|
52
|
-
// </Suspense>
|
|
53
|
-
// }
|
|
54
|
-
// />
|
|
55
|
-
// <Route
|
|
56
|
-
// path={Routes.ITEM_DETAIL}
|
|
57
|
-
// element={
|
|
58
|
-
// <Suspense fallback={<Spinner />}>
|
|
59
|
-
// <Item country={customer?.country as Country} customerId={customer?.customerId as string} />
|
|
60
|
-
// </Suspense>
|
|
61
|
-
// }
|
|
62
|
-
// />
|
|
63
|
-
// <Route
|
|
64
|
-
// path={Routes.SUMMARY}
|
|
65
|
-
// element={
|
|
66
|
-
// <Suspense fallback={<Spinner />}>
|
|
67
|
-
// <Summary country={customer?.country as Country} customerId={customer?.customerId as string} />
|
|
68
|
-
// </Suspense>
|
|
69
|
-
// }
|
|
70
|
-
// />
|
|
71
|
-
// <Route
|
|
72
|
-
// path={Routes.CHECKOUT}
|
|
73
|
-
// element={
|
|
74
|
-
// <Suspense fallback={<Spinner />}>
|
|
75
|
-
// <Checkout
|
|
76
|
-
// country={customer?.country as Country}
|
|
77
|
-
// customerId={customer?.customerId as string}
|
|
78
|
-
// useRedirect={useRedirect}
|
|
79
|
-
// >
|
|
80
|
-
// <Outlet />
|
|
81
|
-
// </Checkout>
|
|
82
|
-
// </Suspense>
|
|
83
|
-
// }
|
|
84
|
-
// >
|
|
85
|
-
// <Route
|
|
86
|
-
// element={<CheckoutPaymentModal customerId={customer?.customerId as string} getAuthToken={getAuthToken} />}
|
|
87
|
-
// path={Routes.CHECKOUT_PAYMENT}
|
|
88
|
-
// />
|
|
89
|
-
// </Route>
|
|
90
|
-
// <Route
|
|
91
|
-
// path={Routes.FEEDBACK}
|
|
92
|
-
// element={
|
|
93
|
-
// <Suspense fallback={<Spinner />}>
|
|
94
|
-
// <Feedback customerId={customer?.customerId as string} />
|
|
95
|
-
// </Suspense>
|
|
96
|
-
// }
|
|
97
|
-
// />
|
|
98
|
-
// <Route element={<Navigate to={`${Routes.HOME}`} replace />} path="*" />
|
|
99
|
-
// </Route>
|
|
100
|
-
// </RootRoutes>
|
|
101
|
-
// );
|
|
15
|
+
const Routing = ({ basePath = "", customer, locale, I18n, menu, tabBar, getAuthToken, onI18nError, onNotAccessible, useRedirect, useRoutes = reactRouterUseRoutes, }) => {
|
|
102
16
|
return useRoutes([
|
|
103
17
|
{
|
|
18
|
+
id: "root",
|
|
104
19
|
path: "",
|
|
105
20
|
element: (React.createElement(BasePathProvider, { basePath: basePath },
|
|
106
21
|
React.createElement(CheckoutAccessibilityMiddleware, { customerId: customer?.customerId, onNotAccessible: onNotAccessible },
|
|
@@ -110,43 +25,51 @@ const Routing = ({ basePath = "", customer, locale, I18n, menu, tabBar, getAuthT
|
|
|
110
25
|
React.createElement(Outlet, null))))))),
|
|
111
26
|
children: [
|
|
112
27
|
{
|
|
28
|
+
id: Routes.INTRO,
|
|
113
29
|
path: Routes.INTRO,
|
|
114
30
|
element: (React.createElement(Suspense, { fallback: React.createElement(Spinner, null) },
|
|
115
31
|
React.createElement(Intro, { customerId: customer?.customerId }))),
|
|
116
32
|
},
|
|
117
33
|
{
|
|
34
|
+
id: Routes.ITEM,
|
|
118
35
|
path: Routes.ITEM,
|
|
119
36
|
element: (React.createElement(Suspense, { fallback: React.createElement(Spinner, null) },
|
|
120
37
|
React.createElement(Item, { country: customer?.country, customerId: customer?.customerId }))),
|
|
121
38
|
},
|
|
122
39
|
{
|
|
40
|
+
id: Routes.ITEM_DETAIL,
|
|
123
41
|
path: Routes.ITEM_DETAIL,
|
|
124
42
|
element: (React.createElement(Suspense, { fallback: React.createElement(Spinner, null) },
|
|
125
43
|
React.createElement(Item, { country: customer?.country, customerId: customer?.customerId }))),
|
|
126
44
|
},
|
|
127
45
|
{
|
|
46
|
+
id: Routes.SUMMARY,
|
|
128
47
|
path: Routes.SUMMARY,
|
|
129
48
|
element: (React.createElement(Suspense, { fallback: React.createElement(Spinner, null) },
|
|
130
49
|
React.createElement(Summary, { country: customer?.country, customerId: customer?.customerId }))),
|
|
131
50
|
},
|
|
132
51
|
{
|
|
52
|
+
id: Routes.CHECKOUT,
|
|
133
53
|
path: Routes.CHECKOUT,
|
|
134
54
|
element: (React.createElement(Suspense, { fallback: React.createElement(Spinner, null) },
|
|
135
55
|
React.createElement(Checkout, { country: customer?.country, customerId: customer?.customerId, useRedirect: useRedirect },
|
|
136
56
|
React.createElement(Outlet, null)))),
|
|
137
57
|
children: [
|
|
138
58
|
{
|
|
59
|
+
id: Routes.CHECKOUT_PAYMENT,
|
|
139
60
|
path: Routes.CHECKOUT_PAYMENT,
|
|
140
61
|
element: React.createElement(CheckoutPaymentModal, { customerId: customer?.customerId, getAuthToken: getAuthToken }),
|
|
141
62
|
},
|
|
142
63
|
],
|
|
143
64
|
},
|
|
144
65
|
{
|
|
66
|
+
id: Routes.FEEDBACK,
|
|
145
67
|
path: Routes.FEEDBACK,
|
|
146
68
|
element: (React.createElement(Suspense, { fallback: React.createElement(Spinner, null) },
|
|
147
69
|
React.createElement(Feedback, { customerId: customer?.customerId }))),
|
|
148
70
|
},
|
|
149
71
|
{
|
|
72
|
+
id: "not-found-home-redirect",
|
|
150
73
|
path: "*",
|
|
151
74
|
element: React.createElement(Navigate, { to: `${Routes.HOME}`, replace: true }),
|
|
152
75
|
},
|
|
@@ -160,6 +83,5 @@ const Routing = ({ basePath = "", customer, locale, I18n, menu, tabBar, getAuthT
|
|
|
160
83
|
* https://github.com/getsentry/sentry-javascript/blob/master/packages/react/src/reactrouterv6.tsx#L221
|
|
161
84
|
* (SentryRoutes is a new component after each re-render)
|
|
162
85
|
*/
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
export { Routing };
|
|
86
|
+
const MemoizedRouting = memo(Routing);
|
|
87
|
+
export { MemoizedRouting as Routing };
|
|
@@ -2,8 +2,9 @@ import { BrowserClient, Hub } from "@sentry/browser";
|
|
|
2
2
|
import { ErrorBoundary } from "@sentry/react";
|
|
3
3
|
import { ReactNativeTransportOptions } from "@sentry/react-native/dist/js/options";
|
|
4
4
|
import { Transport, Integration } from "@sentry/types";
|
|
5
|
-
import {
|
|
5
|
+
import { WrapComponent, WrapUseRoutes } from "./types";
|
|
6
6
|
declare const transport: (options: ReactNativeTransportOptions) => Transport;
|
|
7
|
-
declare const integrations:
|
|
8
|
-
declare const
|
|
9
|
-
|
|
7
|
+
declare const integrations: Integration[];
|
|
8
|
+
declare const wrapComponent: WrapComponent;
|
|
9
|
+
declare const wrapUseRoutes: WrapUseRoutes;
|
|
10
|
+
export { BrowserClient as Client, Hub, ErrorBoundary, transport, integrations, wrapComponent, wrapUseRoutes };
|
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
import { BrowserClient, Hub, makeFetchTransport, defaultIntegrations } from "@sentry/browser";
|
|
2
2
|
import { ErrorBoundary } from "@sentry/react";
|
|
3
3
|
import { reactRouterV6Instrumentation } from "@sentry/react";
|
|
4
|
+
import { wrapUseRoutes as reactRouterV6WrapUseRoutes } from "@sentry/react";
|
|
4
5
|
import { BrowserTracing } from "@sentry/tracing";
|
|
5
6
|
import { useEffect } from "react";
|
|
6
7
|
import { createRoutesFromChildren, useLocation, useNavigationType } from "react-router-native";
|
|
7
|
-
import {
|
|
8
|
+
import { matchRoutes } from "./matchRoutes";
|
|
8
9
|
const transport = (options, nativeFetch) => makeFetchTransport(options, nativeFetch);
|
|
9
|
-
const integrations =
|
|
10
|
+
const integrations = [
|
|
10
11
|
...defaultIntegrations,
|
|
11
12
|
new BrowserTracing({
|
|
12
|
-
routingInstrumentation: reactRouterV6Instrumentation(useEffect, useLocation, useNavigationType, createRoutesFromChildren,
|
|
13
|
+
routingInstrumentation: reactRouterV6Instrumentation(useEffect, useLocation, useNavigationType, createRoutesFromChildren, matchRoutes),
|
|
13
14
|
}),
|
|
14
15
|
];
|
|
15
|
-
const
|
|
16
|
-
|
|
16
|
+
const wrapComponent = (Component) => Component;
|
|
17
|
+
const wrapUseRoutes = reactRouterV6WrapUseRoutes;
|
|
18
|
+
export { BrowserClient as Client, Hub, ErrorBoundary, transport, integrations, wrapComponent, wrapUseRoutes };
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { ReactNativeClient, Hub, ErrorBoundary } from "@sentry/react-native";
|
|
2
2
|
import { ReactNativeTransportOptions } from "@sentry/react-native/dist/js/options";
|
|
3
3
|
import { Transport, Integration } from "@sentry/types";
|
|
4
|
-
import {
|
|
4
|
+
import { WrapComponent, WrapUseRoutes } from "./types";
|
|
5
5
|
declare const transport: (options: ReactNativeTransportOptions) => Transport;
|
|
6
|
-
declare const integrations:
|
|
7
|
-
declare const
|
|
8
|
-
|
|
6
|
+
declare const integrations: Integration[];
|
|
7
|
+
declare const wrapComponent: WrapComponent;
|
|
8
|
+
declare const wrapUseRoutes: WrapUseRoutes;
|
|
9
|
+
export { ReactNativeClient as Client, Hub, ErrorBoundary, transport, integrations, wrapComponent, wrapUseRoutes };
|
|
@@ -2,12 +2,13 @@ import { makeFetchTransport } from "@sentry/browser";
|
|
|
2
2
|
import { ReactNativeClient, Hub, ErrorBoundary, wrap as sentryWrap, ReactNativeTracing } from "@sentry/react-native";
|
|
3
3
|
import { makeReactNativeTransport } from "@sentry/react-native/dist/js/transports/native";
|
|
4
4
|
import { NATIVE } from "@sentry/react-native/dist/js/wrapper";
|
|
5
|
+
import { useEffect } from "react";
|
|
6
|
+
import { useLocation, useNavigationType } from "react-router-native";
|
|
7
|
+
import { matchRoutes } from "./matchRoutes";
|
|
5
8
|
import { ReactRouterV6Instrumentation } from "./reactRouterV6Instrumentation.native";
|
|
6
9
|
const transport = (options, nativeFetch) => NATIVE.isNativeTransportAvailable() ? makeReactNativeTransport(options) : makeFetchTransport(options, nativeFetch);
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
const wrap = (Component) => sentryWrap(Component);
|
|
13
|
-
export { ReactNativeClient as Client, Hub, ErrorBoundary, transport, integrations, wrap };
|
|
10
|
+
const routingInstrumentation = new ReactRouterV6Instrumentation(useEffect, useLocation, useNavigationType, matchRoutes);
|
|
11
|
+
const integrations = [new ReactNativeTracing({ routingInstrumentation })];
|
|
12
|
+
const wrapComponent = (Component) => sentryWrap(Component);
|
|
13
|
+
const wrapUseRoutes = routingInstrumentation.wrapUseRoutes.bind(routingInstrumentation);
|
|
14
|
+
export { ReactNativeClient as Client, Hub, ErrorBoundary, transport, integrations, wrapComponent, wrapUseRoutes };
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { ComponentType } from "react";
|
|
2
2
|
import { Platform } from "react-native";
|
|
3
3
|
interface SentryLoggerFunctionArgs {
|
|
4
|
-
readonly routerBasename: string;
|
|
5
4
|
readonly publicKey: string;
|
|
6
5
|
readonly environment: `${typeof Platform.OS}-${"DEV" | "PROD"}`;
|
|
7
6
|
readonly release: string;
|
|
@@ -1,21 +1,16 @@
|
|
|
1
1
|
import { defaultStackParser } from "@sentry/browser";
|
|
2
2
|
import { makeMain } from "@sentry/core";
|
|
3
|
-
import {
|
|
4
|
-
// withSentryReactRouterV6Routing,
|
|
5
|
-
wrapUseRoutes, } from "@sentry/react";
|
|
6
3
|
import React, { useEffect } from "react";
|
|
7
4
|
import { Platform } from "react-native";
|
|
8
|
-
import {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
import { Client, Hub, ErrorBoundary, transport, integrations, wrap } from "./SentryDependencies";
|
|
12
|
-
const sentryLogger = ({ routerBasename, publicKey, environment, release, project }) => {
|
|
5
|
+
import { useRoutes as reactRouterUseRoutes } from "react-router-native";
|
|
6
|
+
import { Client, Hub, ErrorBoundary, transport, integrations, wrapComponent, wrapUseRoutes, } from "./SentryDependencies";
|
|
7
|
+
const sentryLogger = ({ publicKey, environment, release, project }) => {
|
|
13
8
|
let mainHub;
|
|
14
9
|
const client = new Client({
|
|
15
10
|
environment,
|
|
16
11
|
release,
|
|
17
12
|
dsn: `https://${publicKey}@o179049.ingest.sentry.io/${project}`,
|
|
18
|
-
integrations
|
|
13
|
+
integrations,
|
|
19
14
|
tracesSampleRate: 1.0,
|
|
20
15
|
debug: true,
|
|
21
16
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
@@ -90,9 +85,8 @@ const sentryLogger = ({ routerBasename, publicKey, environment, release, project
|
|
|
90
85
|
makeMain(mainHub);
|
|
91
86
|
};
|
|
92
87
|
const useRoutes = wrapUseRoutes(reactRouterUseRoutes);
|
|
93
|
-
// const Routes = withSentryReactRouterV6Routing(ReactRouterRoutes);
|
|
94
88
|
return (Component) => {
|
|
95
|
-
const WrappedComponent =
|
|
89
|
+
const WrappedComponent = wrapComponent(Component);
|
|
96
90
|
const SentryLogger = (props) => {
|
|
97
91
|
const { customer } = props;
|
|
98
92
|
useEffect(() => {
|
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
import { matchRoutes } from "@remix-run/router";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
}
|
|
5
|
-
declare const matchRoutesForBasename: MatchRoutesForBasenameFunction;
|
|
6
|
-
export { matchRoutesForBasename };
|
|
1
|
+
import { matchRoutes as reactRouterMatchRoutes } from "@remix-run/router";
|
|
2
|
+
declare const matchRoutes: typeof reactRouterMatchRoutes;
|
|
3
|
+
export { matchRoutes };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { matchRoutes } from "@remix-run/router";
|
|
2
|
-
const
|
|
1
|
+
import { matchRoutes as reactRouterMatchRoutes } from "@remix-run/router";
|
|
2
|
+
const matchRoutes = (routes, locationArg) => {
|
|
3
3
|
// Remove the location's first path ("/checkout"). Otherwise it won't match the proper route.
|
|
4
4
|
const location = (typeof locationArg === "string" ? locationArg : locationArg?.pathname || "").replace(/^\/\w+/, "");
|
|
5
|
-
return
|
|
5
|
+
return reactRouterMatchRoutes(routes, location);
|
|
6
6
|
};
|
|
7
|
-
export {
|
|
7
|
+
export { matchRoutes };
|
|
@@ -1,20 +1,18 @@
|
|
|
1
1
|
import { RoutingInstrumentation } from "@sentry/react-native";
|
|
2
2
|
import { OnConfirmRoute, TransactionCreator } from "@sentry/react-native/dist/js/tracing/routingInstrumentation";
|
|
3
3
|
import { BeforeNavigate } from "@sentry/react-native/dist/js/tracing/types";
|
|
4
|
-
|
|
5
|
-
readonly name: string;
|
|
6
|
-
readonly key: string;
|
|
7
|
-
readonly params: Record<string, unknown>;
|
|
8
|
-
}
|
|
9
|
-
export interface ReactNavigationCurrentRoute extends ReactNavigationRoute {
|
|
10
|
-
readonly hasBeenSeen: boolean;
|
|
11
|
-
}
|
|
4
|
+
import { MatchRoutes, UseEffect, UseLocation, UseNavigationType, WrapUseRoutes } from "./types";
|
|
12
5
|
declare class ReactRouterV6Instrumentation extends RoutingInstrumentation {
|
|
13
6
|
static instrumentationName: string;
|
|
7
|
+
private useEffect;
|
|
8
|
+
private useLocation;
|
|
9
|
+
private useNavigationType;
|
|
10
|
+
private matchRoutes;
|
|
14
11
|
private prevRoute?;
|
|
15
12
|
private recentRouteKeys;
|
|
16
13
|
private latestTransaction?;
|
|
17
14
|
private shouldUpdateLatestTransaction;
|
|
15
|
+
constructor(useEffect: UseEffect, useLocation: UseLocation, useNavigationType: UseNavigationType, matchRoutes: MatchRoutes);
|
|
18
16
|
/**
|
|
19
17
|
* Extends by calling _handleInitialState at the end.
|
|
20
18
|
*/
|
|
@@ -23,5 +21,7 @@ declare class ReactRouterV6Instrumentation extends RoutingInstrumentation {
|
|
|
23
21
|
* Starts an idle transaction for the initial state which won't get called by the router listener.
|
|
24
22
|
*/
|
|
25
23
|
private handleInitialState;
|
|
24
|
+
private getTransactionContext;
|
|
25
|
+
wrapUseRoutes: WrapUseRoutes;
|
|
26
26
|
}
|
|
27
27
|
export { ReactRouterV6Instrumentation };
|
|
@@ -1,16 +1,27 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
2
1
|
/* eslint-disable @typescript-eslint/ban-ts-comment */
|
|
3
2
|
import { RoutingInstrumentation } from "@sentry/react-native";
|
|
3
|
+
import { logger } from "@sentry/utils";
|
|
4
|
+
import React from "react";
|
|
4
5
|
class ReactRouterV6Instrumentation extends RoutingInstrumentation {
|
|
5
6
|
static instrumentationName = "react-router-v6";
|
|
7
|
+
useEffect;
|
|
8
|
+
useLocation;
|
|
9
|
+
useNavigationType;
|
|
10
|
+
matchRoutes;
|
|
6
11
|
// @ts-ignore
|
|
7
12
|
prevRoute;
|
|
8
|
-
// @ts-ignore
|
|
9
13
|
recentRouteKeys = [];
|
|
10
14
|
// @ts-ignore
|
|
11
15
|
latestTransaction;
|
|
12
16
|
// @ts-ignore
|
|
13
17
|
shouldUpdateLatestTransaction = false;
|
|
18
|
+
constructor(useEffect, useLocation, useNavigationType, matchRoutes) {
|
|
19
|
+
super();
|
|
20
|
+
this.useEffect = useEffect;
|
|
21
|
+
this.useLocation = useLocation;
|
|
22
|
+
this.useNavigationType = useNavigationType;
|
|
23
|
+
this.matchRoutes = matchRoutes;
|
|
24
|
+
}
|
|
14
25
|
/**
|
|
15
26
|
* Extends by calling _handleInitialState at the end.
|
|
16
27
|
*/
|
|
@@ -27,6 +38,71 @@ class ReactRouterV6Instrumentation extends RoutingInstrumentation {
|
|
|
27
38
|
// We set this to true so when registerAppContainer is called, the transaction gets updated with the actual route data
|
|
28
39
|
this.shouldUpdateLatestTransaction = true;
|
|
29
40
|
}
|
|
41
|
+
// @ts-ignore
|
|
42
|
+
getTransactionContext(route, previousRoute) {
|
|
43
|
+
return {
|
|
44
|
+
name: route.name,
|
|
45
|
+
op: "navigation",
|
|
46
|
+
tags: {
|
|
47
|
+
["routing.instrumentation"]: ReactRouterV6Instrumentation.instrumentationName,
|
|
48
|
+
["routing.route.name"]: route.name,
|
|
49
|
+
},
|
|
50
|
+
data: {
|
|
51
|
+
route: {
|
|
52
|
+
name: route.name,
|
|
53
|
+
key: route.key,
|
|
54
|
+
params: route.params ?? {},
|
|
55
|
+
hasBeenSeen: this.recentRouteKeys.includes(route.key),
|
|
56
|
+
},
|
|
57
|
+
previousRoute: previousRoute
|
|
58
|
+
? {
|
|
59
|
+
name: previousRoute.name,
|
|
60
|
+
key: previousRoute.key,
|
|
61
|
+
params: previousRoute.params ?? {},
|
|
62
|
+
}
|
|
63
|
+
: null,
|
|
64
|
+
},
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
wrapUseRoutes = (origUseRoutes) => {
|
|
68
|
+
if (!this.useEffect ||
|
|
69
|
+
!this.useLocation ||
|
|
70
|
+
!this.useNavigationType ||
|
|
71
|
+
!this.matchRoutes
|
|
72
|
+
// !this._customStartTransaction
|
|
73
|
+
) {
|
|
74
|
+
__DEBUG_BUILD__ &&
|
|
75
|
+
logger.warn("reactRouterV6Instrumentation was unable to wrap `useRoutes` because of one or more missing parameters.");
|
|
76
|
+
return origUseRoutes;
|
|
77
|
+
}
|
|
78
|
+
let isMountRenderPass = true;
|
|
79
|
+
// eslint-disable-next-line react/display-name
|
|
80
|
+
return (routes, locationArg) => {
|
|
81
|
+
const SentryRoutes = () => {
|
|
82
|
+
const Routes = origUseRoutes(routes, locationArg);
|
|
83
|
+
const location = this.useLocation();
|
|
84
|
+
const navigationType = this.useNavigationType();
|
|
85
|
+
// A value with stable identity to either pick `locationArg` if available or `location` if not
|
|
86
|
+
const stableLocationParam = typeof locationArg === "string" || (locationArg && locationArg.pathname)
|
|
87
|
+
? locationArg
|
|
88
|
+
: location;
|
|
89
|
+
this.useEffect(() => {
|
|
90
|
+
const normalizedLocation = typeof stableLocationParam === "string" ? { pathname: stableLocationParam } : stableLocationParam;
|
|
91
|
+
if (isMountRenderPass) {
|
|
92
|
+
console.log("updatePageloadTransaction", normalizedLocation, routes);
|
|
93
|
+
// updatePageloadTransaction(normalizedLocation, routes);
|
|
94
|
+
isMountRenderPass = false;
|
|
95
|
+
}
|
|
96
|
+
else {
|
|
97
|
+
console.log("normalizedLocation", normalizedLocation, routes, navigationType);
|
|
98
|
+
// handleNavigation(normalizedLocation, routes, navigationType);
|
|
99
|
+
}
|
|
100
|
+
}, [navigationType, stableLocationParam]);
|
|
101
|
+
return Routes;
|
|
102
|
+
};
|
|
103
|
+
return React.createElement(SentryRoutes, null);
|
|
104
|
+
};
|
|
105
|
+
};
|
|
30
106
|
}
|
|
31
107
|
const INITIAL_TRANSACTION_CONTEXT = {
|
|
32
108
|
name: "App Launch",
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { ComponentType, useEffect } from "react";
|
|
2
|
+
import { matchRoutes, RouteObject, useLocation } from "react-router-native";
|
|
3
|
+
type UseEffect = typeof useEffect;
|
|
4
|
+
type UseLocation = typeof useLocation;
|
|
5
|
+
type UseNavigationType = () => "PUSH" | "REPLACE" | "POP";
|
|
6
|
+
type MatchRoutes = typeof matchRoutes;
|
|
7
|
+
type UseRoutes = (routes: RouteObject[], locationArg?: Partial<Location> | string) => React.ReactElement | null;
|
|
8
|
+
interface WrapUseRoutes {
|
|
9
|
+
(useRoutes: UseRoutes): UseRoutes;
|
|
10
|
+
}
|
|
11
|
+
interface WrapComponent {
|
|
12
|
+
<P>(Component: ComponentType<P>): ComponentType<P>;
|
|
13
|
+
}
|
|
14
|
+
export type { UseEffect, UseLocation, UseNavigationType, MatchRoutes, WrapUseRoutes, WrapComponent };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|