@grafana/faro-react 1.6.0 → 1.7.1
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/README.md +255 -108
- package/dist/bundle/types/router/v6/types.d.ts +16 -0
- package/dist/bundle/types/router/v6/withFaroRouterInstrumentation.d.ts +2 -2
- package/dist/cjs/router/v6/types.js.map +1 -1
- package/dist/cjs/router/v6/withFaroRouterInstrumentation.js.map +1 -1
- package/dist/esm/router/v6/types.js.map +1 -1
- package/dist/esm/router/v6/withFaroRouterInstrumentation.js.map +1 -1
- package/dist/types/router/v6/types.d.ts +16 -0
- package/dist/types/router/v6/withFaroRouterInstrumentation.d.ts +2 -2
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -4,36 +4,108 @@ Faro package that enables easier integration in projects built with React.
|
|
|
4
4
|
|
|
5
5
|
Out of the box, the package provides you the following features:
|
|
6
6
|
|
|
7
|
-
- Error Boundary - Provides additional stacktrace for errors and configuration options for
|
|
7
|
+
- Error Boundary - Provides additional stacktrace for errors and configuration options for
|
|
8
|
+
pushError behavior
|
|
8
9
|
- Component Profiler - Capture every re-render of a component, the un/mounting time etc.
|
|
9
10
|
- Router (v4-v6) integration - Send events for all route changes
|
|
10
11
|
- SSR support
|
|
11
12
|
|
|
12
|
-
|
|
13
|
+
The Faro Web SDK is a highly configurable open source real user monitoring (RUM) library built on
|
|
14
|
+
OpenTelemetry and integrating seamlessly with Grafana Cloud and Grafana Frontend Observability.
|
|
13
15
|
|
|
14
|
-
|
|
16
|
+
Faro-React is a distribution of the Faro Web SDK for project using React, which offers easier
|
|
17
|
+
integrations and the following features:
|
|
15
18
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
+
- **Support for React Router v6 or v4/v5.x**: send events for all route changes, including the data
|
|
20
|
+
router API
|
|
21
|
+
- **Error boundary**: enhancements to stack traces and configuration options for pushError behavior
|
|
22
|
+
- **Component profiler**: to capture component renders, un/mounting time, and more
|
|
23
|
+
- **Server side rendering (SSR) support**
|
|
24
|
+
|
|
25
|
+
## Install the Faro-React Web SDK
|
|
26
|
+
|
|
27
|
+
First add Faro-React to your project. Install the Faro-React package by running the following command
|
|
28
|
+
for NPM:
|
|
29
|
+
|
|
30
|
+
```sh
|
|
31
|
+
npm i @grafana/faro-react
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
Or with Yarn:
|
|
35
|
+
|
|
36
|
+
```sh
|
|
37
|
+
yarn add @grafana/faro-react
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
The Faro-React package offers all the functionality and behavior from the Faro Web SDK package plus
|
|
41
|
+
additional React specific functionality like router instrumentation, a custom ErrorBoundary, and more.
|
|
42
|
+
|
|
43
|
+
Add the following code snippet to your project to import Faro-React with the minimum setup needed to
|
|
44
|
+
get insights into the health and performance of your application or website:
|
|
45
|
+
|
|
46
|
+
```ts
|
|
47
|
+
import { initializeFaro } from '@grafana/faro-react';
|
|
48
|
+
|
|
49
|
+
initializeFaro({
|
|
50
|
+
// required: the URL of the Grafana collector
|
|
51
|
+
url: 'my/collector/url',
|
|
52
|
+
|
|
53
|
+
// required: the identification label of your application
|
|
54
|
+
app: {
|
|
55
|
+
name: 'my-react-app',
|
|
56
|
+
},
|
|
57
|
+
});
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
Faro-React captures data about your application’s health and performance and exports them to the
|
|
61
|
+
configured collector like Grafana Alloy.
|
|
62
|
+
|
|
63
|
+
## Instrument your application
|
|
64
|
+
|
|
65
|
+
The Faro-React package offers all the functionality and behavior from the Faro Web SDK package plus
|
|
66
|
+
additional React specific functionality like router instrumentation, a custom ErrorBoundary, and more.
|
|
67
|
+
|
|
68
|
+
### Router v6 with Data Router
|
|
69
|
+
|
|
70
|
+
Instrument the routes from a React data router (`BrowserRouter`, `HashRouter`, or `MemoryRouter`).
|
|
71
|
+
|
|
72
|
+
In the file you create your data router, often the App.\* file pass your data router to the Faro-React
|
|
73
|
+
function `withFaroRouterInstrumentation` to wrap all your routes and apply Faro auto instrumentation:
|
|
74
|
+
|
|
75
|
+
```ts
|
|
76
|
+
const reactBrowserRouter = createBrowserRouter([
|
|
77
|
+
// your routes...
|
|
78
|
+
]);
|
|
79
|
+
|
|
80
|
+
const browserRouter = withFaroRouterInstrumentation(reactBrowserRouter);
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
### Router v6 (no Data Router)
|
|
84
|
+
|
|
85
|
+
In the file you define your router, import `createRoutesFromChildren`, `matchRoutes`, `Routes`,
|
|
86
|
+
`useLocation`, `useNavigationType` from `react-router-dom` and pass them to the dependencies object.
|
|
19
87
|
|
|
20
88
|
```ts
|
|
21
89
|
import { createRoutesFromChildren, matchRoutes, Routes, useLocation, useNavigationType } from 'react-router-dom';
|
|
22
90
|
|
|
23
91
|
import { getWebInstrumentations, initializeFaro, ReactIntegration, ReactRouterVersion } from '@grafana/faro-react';
|
|
24
|
-
import { TracingInstrumentation } from '@grafana/faro-web-tracing';
|
|
25
92
|
|
|
26
93
|
initializeFaro({
|
|
94
|
+
// Mandatory, the URL of the Grafana collector
|
|
95
|
+
url: 'my/collector/url',
|
|
96
|
+
|
|
97
|
+
// Mandatory, the identification label of your application
|
|
98
|
+
app: {
|
|
99
|
+
name: 'my-react-app',
|
|
100
|
+
},
|
|
101
|
+
|
|
27
102
|
// ...
|
|
103
|
+
|
|
28
104
|
instrumentations: [
|
|
29
105
|
// Load the default Web instrumentations
|
|
30
106
|
...getWebInstrumentations(),
|
|
31
107
|
|
|
32
|
-
// Tracing Instrumentation is needed if you want to use the React Profiler
|
|
33
|
-
new TracingInstrumentation(),
|
|
34
|
-
|
|
35
108
|
new ReactIntegration({
|
|
36
|
-
// Only needed if you want to use the React Router instrumentation
|
|
37
109
|
router: {
|
|
38
110
|
version: ReactRouterVersion.V6,
|
|
39
111
|
dependencies: {
|
|
@@ -44,60 +116,115 @@ initializeFaro({
|
|
|
44
116
|
useNavigationType,
|
|
45
117
|
},
|
|
46
118
|
},
|
|
47
|
-
|
|
48
|
-
// Or if you use react-router v4/v5
|
|
49
|
-
router2: {
|
|
50
|
-
version: ReactRouterVersion.V5, // or ReactRouterVersion.V4,
|
|
51
|
-
dependencies: {
|
|
52
|
-
history, // the history object used by react-router
|
|
53
|
-
Route, // Route component imported from react-router package
|
|
54
|
-
},
|
|
55
|
-
},
|
|
56
119
|
}),
|
|
57
120
|
],
|
|
58
121
|
});
|
|
59
122
|
```
|
|
60
123
|
|
|
61
|
-
|
|
124
|
+
To instrument React Router v6 import the `<FaroRoutes/>` component and use it instead of the React
|
|
125
|
+
router `<Routes />` component, for example:
|
|
126
|
+
|
|
127
|
+
```tsx
|
|
128
|
+
import { FaroRoutes } from '@grafana/faro-react';
|
|
129
|
+
|
|
130
|
+
// during render
|
|
131
|
+
<FaroRoutes>
|
|
132
|
+
<Route path="/" element={<Home />} />
|
|
133
|
+
{/* ... */}
|
|
134
|
+
</FaroRoutes>;
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
### Router v4/v5
|
|
138
|
+
|
|
139
|
+
To instrument React Router v4 or v5, import the `Route` component from `react-router-dom` and the
|
|
140
|
+
`history` object from the `history package` and pass them to the dependencies object:
|
|
141
|
+
|
|
142
|
+
The final result should look similar like this example:
|
|
62
143
|
|
|
63
144
|
```ts
|
|
64
|
-
import {
|
|
145
|
+
import { createBrowserHistory } from 'history';
|
|
146
|
+
import { Route } from 'react-router-dom';
|
|
65
147
|
|
|
66
148
|
import { getWebInstrumentations, initializeFaro, ReactIntegration, ReactRouterVersion } from '@grafana/faro-react';
|
|
67
|
-
|
|
149
|
+
|
|
150
|
+
const history = createBrowserHistory();
|
|
68
151
|
|
|
69
152
|
initializeFaro({
|
|
153
|
+
// Mandatory, the URL of the Grafana collector
|
|
154
|
+
url: 'my/collector/url',
|
|
155
|
+
|
|
156
|
+
// Mandatory, the identification label of your application
|
|
157
|
+
app: {
|
|
158
|
+
name: 'my-react-app',
|
|
159
|
+
},
|
|
160
|
+
|
|
70
161
|
// ...
|
|
162
|
+
|
|
71
163
|
instrumentations: [
|
|
72
164
|
// Load the default Web instrumentations
|
|
73
165
|
...getWebInstrumentations(),
|
|
74
166
|
|
|
75
|
-
// Tracing Instrumentation is needed if you want to use the React Profiler
|
|
76
|
-
new TracingInstrumentation(),
|
|
77
|
-
|
|
78
167
|
new ReactIntegration({
|
|
79
|
-
// Only needed if you want to use the React Router instrumentation
|
|
80
168
|
router: {
|
|
81
|
-
version: ReactRouterVersion.
|
|
169
|
+
version: ReactRouterVersion.V5, // or ReactRouterVersion.V4,
|
|
82
170
|
dependencies: {
|
|
83
|
-
|
|
171
|
+
history, // the history object used by react-router
|
|
172
|
+
Route, // Route component imported from react-router package
|
|
84
173
|
},
|
|
85
174
|
},
|
|
86
175
|
}),
|
|
87
176
|
],
|
|
88
177
|
});
|
|
178
|
+
```
|
|
89
179
|
|
|
90
|
-
|
|
91
|
-
|
|
180
|
+
To instrument React Router v4, v5 import the `<FaroRoute/>` component and use it instead of the
|
|
181
|
+
React router `<Route />` component, for example:
|
|
92
182
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
]);
|
|
183
|
+
```tsx
|
|
184
|
+
import { FaroRoute } from '@grafana/faro-react';
|
|
96
185
|
|
|
97
|
-
|
|
186
|
+
// during render
|
|
187
|
+
<Switch>
|
|
188
|
+
<FaroRoute path="/">
|
|
189
|
+
<Home />
|
|
190
|
+
</FaroRoute>
|
|
191
|
+
{/* ... */}
|
|
192
|
+
</Switch>;
|
|
98
193
|
```
|
|
99
194
|
|
|
100
|
-
|
|
195
|
+
## React ErrorBoundary support
|
|
196
|
+
|
|
197
|
+
React Error boundaries are components that allow you to render a fallback UI in case an error occurs
|
|
198
|
+
in the respective React component tree.
|
|
199
|
+
|
|
200
|
+
Faro provides its own error boundary component which enhances the standard React error boundary with
|
|
201
|
+
Faro specific functionality.
|
|
202
|
+
|
|
203
|
+
In case of an error it sends a Faro error event which contains the error message, the React component
|
|
204
|
+
stack of the component which contains the exception, and the name of name of the error boundary
|
|
205
|
+
if configured.
|
|
206
|
+
|
|
207
|
+
```ts
|
|
208
|
+
import { initializeFaro } from '@grafana/faro-react';
|
|
209
|
+
|
|
210
|
+
initializeFaro({
|
|
211
|
+
// required: the URL of the Grafana collector
|
|
212
|
+
url: 'my/collector/url',
|
|
213
|
+
|
|
214
|
+
// required: the identification label of your application
|
|
215
|
+
app: {
|
|
216
|
+
name: 'my-react-app',
|
|
217
|
+
},
|
|
218
|
+
|
|
219
|
+
instrumentations: [
|
|
220
|
+
// Load the default Web instrumentations
|
|
221
|
+
...getWebInstrumentations(),
|
|
222
|
+
|
|
223
|
+
// Must be initialized to get FaroErrorBoundary support
|
|
224
|
+
new ReactIntegration(),
|
|
225
|
+
],
|
|
226
|
+
});
|
|
227
|
+
```
|
|
101
228
|
|
|
102
229
|
```tsx
|
|
103
230
|
import { FaroErrorBoundary } from '@grafana/faro-react';
|
|
@@ -116,130 +243,150 @@ import { withErrorBoundary } from '@grafana/faro-react';
|
|
|
116
243
|
export default withErrorBoundary(App);
|
|
117
244
|
```
|
|
118
245
|
|
|
119
|
-
|
|
246
|
+
### FaroErrorBoundary properties
|
|
120
247
|
|
|
121
|
-
|
|
248
|
+
Configuration options:
|
|
249
|
+
|
|
250
|
+
- `fallback`: The fallback UI to render instead, either:
|
|
251
|
+
- a `ReactElement`
|
|
252
|
+
- `FaroErrorBoundaryFallbackRender` function that passes the Error object and a callback function
|
|
253
|
+
to reset the error boundary to it’s initial state when called
|
|
254
|
+
- `pushErrorOptions`: Options passed to the pushError API, for example additional context to an error
|
|
122
255
|
|
|
256
|
+
Lifecycle callbacks:
|
|
257
|
+
|
|
258
|
+
- `beforeCapture`: Executed before the Faro pushError API call, with the Error object as a parameter
|
|
259
|
+
- `onError`: Executed when an error occurs, with the Error object as a parameter
|
|
260
|
+
- `onMount`: Executed when React calls the componentDidMount lifecycle hook
|
|
261
|
+
- `onUnmount`: Executed when React calls the componentWillUnmount lifecycle hook, with the Error
|
|
262
|
+
object as a parameter
|
|
263
|
+
- `onReset`: Executed when React calls resetErrorBoundary, with the Error object as a parameter
|
|
264
|
+
|
|
265
|
+
```tsx
|
|
123
266
|
import { FaroErrorBoundary, PushErrorOptions } from '@grafana/faro-react';
|
|
124
267
|
|
|
125
268
|
const pushErrorOptions: PushErrorOptions = {
|
|
126
269
|
type: "Custom Error Type"
|
|
127
270
|
context: {
|
|
128
271
|
foo: "bar",
|
|
129
|
-
baz: "
|
|
272
|
+
baz: "abc"
|
|
130
273
|
},
|
|
131
|
-
|
|
132
|
-
}
|
|
274
|
+
};
|
|
133
275
|
|
|
134
276
|
// during render
|
|
135
|
-
<FaroErrorBoundary
|
|
277
|
+
<FaroErrorBoundary
|
|
278
|
+
beforeCapture={(error) => handleBeforeCapture(error)}
|
|
279
|
+
onError={(error) => handleError(error)}
|
|
280
|
+
onMount={() => handleOnMount()}
|
|
281
|
+
onUnmount={(error) => handleUnmount(error)}
|
|
282
|
+
onReset={(error) => handleReset(error)}
|
|
283
|
+
pushErrorOptions={pushErrorOptions}
|
|
284
|
+
fallback={(error, resetBoundary) => {
|
|
285
|
+
return errorBoundaryFallbackRenderer(error, resetBoundary) }}
|
|
286
|
+
>
|
|
136
287
|
<App />
|
|
137
288
|
</FaroErrorBoundary>;
|
|
138
289
|
```
|
|
139
290
|
|
|
140
|
-
|
|
291
|
+
## React erver side rendering support
|
|
141
292
|
|
|
142
|
-
|
|
293
|
+
Follow this guide to learn how to initialize your Faro instrumentation to support React Server Side
|
|
294
|
+
Rendering (SSR) for:
|
|
143
295
|
|
|
144
|
-
|
|
145
|
-
import { FaroRoutes } from '@grafana/faro-react';
|
|
296
|
+
React Router v6 without a data router:
|
|
146
297
|
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
298
|
+
```tsx
|
|
299
|
+
import { FaroErrorBoundary, setReactRouterV6SSRDependencies } from '@grafana/faro-react';
|
|
300
|
+
setReactRouterV6SSRDependencies({ Routes });
|
|
301
|
+
|
|
302
|
+
export function renderToString(...) {
|
|
303
|
+
return reactRenderToString(
|
|
304
|
+
<FaroErrorBoundary>
|
|
305
|
+
<StaticRouter location={...}>
|
|
306
|
+
<App />
|
|
307
|
+
</StaticRouter>
|
|
308
|
+
</FaroErrorBoundary>
|
|
309
|
+
),
|
|
310
|
+
}
|
|
152
311
|
```
|
|
153
312
|
|
|
154
|
-
|
|
313
|
+
React Router v6 with a data router:
|
|
155
314
|
|
|
156
|
-
|
|
157
|
-
2. Instrument the data router to receive route changes by wrapping it with `withFaroRouterInstrumentation()`
|
|
315
|
+
Wrap your data router with `withFaroRouterInstrumentation(dataRouter)` in your routes file.
|
|
158
316
|
|
|
159
|
-
|
|
160
|
-
const reactBrowserRouter = createBrowserRouter([
|
|
161
|
-
//...
|
|
162
|
-
]);
|
|
317
|
+
React Router v5:
|
|
163
318
|
|
|
164
|
-
|
|
319
|
+
```tsx
|
|
320
|
+
import { FaroErrorBoundary, setReactRouterV4V5SSRDependencies } from '@grafana/faro-react';
|
|
321
|
+
setReactRouterV4V5SSRDependencies({ Route, history });
|
|
322
|
+
|
|
323
|
+
export function renderToString(...) {
|
|
324
|
+
return reactRenderToString(
|
|
325
|
+
<FaroErrorBoundary>
|
|
326
|
+
<StaticRouter location={...}>
|
|
327
|
+
<App />
|
|
328
|
+
</StaticRouter>
|
|
329
|
+
</FaroErrorBoundary>
|
|
330
|
+
),
|
|
331
|
+
}
|
|
165
332
|
```
|
|
166
333
|
|
|
167
|
-
|
|
334
|
+
## React component profiling
|
|
168
335
|
|
|
169
|
-
|
|
170
|
-
|
|
336
|
+
Follow this guide to setup and use the Faro Profiler to get insights into the render performance of
|
|
337
|
+
a React components.
|
|
171
338
|
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
339
|
+
> WARNING
|
|
340
|
+
> Using the profiler has an impact on performance and should not be used in production.
|
|
341
|
+
|
|
342
|
+
To use the Faro profiler, import the Faro web-tracing package and initialize Faro-React as follows:
|
|
343
|
+
|
|
344
|
+
```ts
|
|
345
|
+
import { withFaroProfiler } from '@grafana/faro-react';
|
|
346
|
+
|
|
347
|
+
export default withFaroProfiler(MyReactComponent);
|
|
179
348
|
```
|
|
180
349
|
|
|
181
|
-
|
|
350
|
+
## Upgrading from a v4, v5, v6 router to data router
|
|
351
|
+
|
|
352
|
+
This section describes how to upgrade the Faro React router instrumentation if you already have a
|
|
353
|
+
React app instrumented which doesn’t use data routers.
|
|
182
354
|
|
|
183
|
-
|
|
355
|
+
In the `ReactIntegration` call, change the `version` property from `ReactRouterVersion.[V4|V5|V6]` to
|
|
356
|
+
`ReactRouterVersion.V6_data_router`.
|
|
184
357
|
|
|
185
|
-
|
|
186
|
-
|
|
358
|
+
If you use React Router v4 or v5 remove the `history` and `Route` dependencies and add the `matchRoutes`
|
|
359
|
+
function exported by `react-router-dom`.
|
|
360
|
+
|
|
361
|
+
If you use React Router v6 remove the following dependencies from the dependencies object:
|
|
187
362
|
|
|
188
363
|
- `createRoutesFromChildren`
|
|
189
364
|
- `Routes`
|
|
190
365
|
- `useLocation`
|
|
191
366
|
- `useNavigationType`
|
|
192
367
|
|
|
193
|
-
|
|
368
|
+
The ReactIntegration call should look similar to:
|
|
369
|
+
|
|
370
|
+
```tsx
|
|
371
|
+
import { matchRoutes } from 'react-router-dom';
|
|
372
|
+
|
|
373
|
+
import { getWebInstrumentations, initializeFaro, ReactIntegration, ReactRouterVersion } from '@grafana/faro-react';
|
|
194
374
|
|
|
195
|
-
```ts
|
|
196
375
|
initializeFaro({
|
|
197
376
|
// ...
|
|
377
|
+
|
|
198
378
|
instrumentations: [
|
|
199
379
|
// Load the default Web instrumentations
|
|
200
380
|
...getWebInstrumentations(),
|
|
201
381
|
|
|
202
|
-
// Tracing Instrumentation is needed if you want to use the React Profiler
|
|
203
|
-
new TracingInstrumentation(),
|
|
204
|
-
|
|
205
382
|
new ReactIntegration({
|
|
206
|
-
// Only needed if you want to use the React Router instrumentation
|
|
207
383
|
router: {
|
|
208
|
-
// version: ReactRouterVersion.V6 // => change to .V6_data_router,
|
|
209
384
|
version: ReactRouterVersion.V6_data_router,
|
|
210
385
|
dependencies: {
|
|
211
386
|
matchRoutes,
|
|
212
|
-
// +++ remove the following dependencies +++
|
|
213
|
-
// createRoutesFromChildren,
|
|
214
|
-
// Routes,
|
|
215
|
-
// useLocation,
|
|
216
|
-
// useNavigationType,
|
|
217
387
|
},
|
|
218
388
|
},
|
|
219
389
|
}),
|
|
220
390
|
],
|
|
221
391
|
});
|
|
222
392
|
```
|
|
223
|
-
|
|
224
|
-
##### Change Router instrumentation
|
|
225
|
-
|
|
226
|
-
1. Remove `<FaroRoutes>` component. This will not work anymore with V6 data routers.
|
|
227
|
-
2. Create a data router and wrap it with `withFaroRouterInstrumentation(dataRouter)`
|
|
228
|
-
|
|
229
|
-
Example: Instrument Router
|
|
230
|
-
|
|
231
|
-
```ts
|
|
232
|
-
const reactBrowserRouter = createBrowserRouter([
|
|
233
|
-
// your routes
|
|
234
|
-
]);
|
|
235
|
-
|
|
236
|
-
const browserRouter = withFaroRouterInstrumentation(reactBrowserRouter);
|
|
237
|
-
```
|
|
238
|
-
|
|
239
|
-
### Profiler
|
|
240
|
-
|
|
241
|
-
```tsx
|
|
242
|
-
import { withFaroProfiler } from '@grafana/faro-react';
|
|
243
|
-
|
|
244
|
-
export default withFaroProfiler(App);
|
|
245
|
-
```
|
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
import type { ReactElement, ReactNode } from 'react';
|
|
2
2
|
import type { ReactRouterLocation } from '../types';
|
|
3
|
+
interface IndexRouteObjectV6DataRouter {
|
|
4
|
+
caseSensitive?: boolean;
|
|
5
|
+
children?: undefined;
|
|
6
|
+
element?: React.ReactNode | null;
|
|
7
|
+
index: true;
|
|
8
|
+
path?: string;
|
|
9
|
+
}
|
|
10
|
+
export interface NonIndexRouteObjectV6DataRouter {
|
|
11
|
+
caseSensitive?: boolean;
|
|
12
|
+
children?: RouteObjectV6DataRouter[];
|
|
13
|
+
element?: React.ReactNode | null;
|
|
14
|
+
index?: false;
|
|
15
|
+
path?: string;
|
|
16
|
+
}
|
|
17
|
+
export type RouteObjectV6DataRouter = IndexRouteObjectV6DataRouter | NonIndexRouteObjectV6DataRouter;
|
|
3
18
|
export interface ReactRouterV6BaseRouteObject {
|
|
4
19
|
action?: (...args: any[]) => any;
|
|
5
20
|
caseSensitive?: boolean;
|
|
@@ -50,3 +65,4 @@ export type EventRouteTransitionAttributes = {
|
|
|
50
65
|
fromRoute?: string;
|
|
51
66
|
fromUrl?: string;
|
|
52
67
|
};
|
|
68
|
+
export {};
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { NavigationType, ReactRouterLocation } from '../types';
|
|
2
|
-
import type {
|
|
2
|
+
import type { RouteObjectV6DataRouter } from './types';
|
|
3
3
|
interface RouterState {
|
|
4
4
|
historyAction: NavigationType | any;
|
|
5
5
|
location: ReactRouterLocation;
|
|
6
6
|
}
|
|
7
7
|
interface Router {
|
|
8
8
|
state: RouterState;
|
|
9
|
-
routes:
|
|
9
|
+
routes: RouteObjectV6DataRouter[];
|
|
10
10
|
subscribe(fn: (state: RouterState) => void): () => void;
|
|
11
11
|
}
|
|
12
12
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/router/v6/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { ReactElement, ReactNode } from 'react';\n\nimport type { ReactRouterLocation } from '../types';\n\nexport interface ReactRouterV6BaseRouteObject {\n action?: (...args: any[]) => any;\n caseSensitive?: boolean;\n hasErrorBoundary?: boolean;\n handle?: any;\n id?: string;\n loader?: (...args: any[]) => any;\n path?: string;\n shouldRevalidate?: (...args: any[]) => any;\n}\n\nexport type ReactRouterV6RouteObject = ReactRouterV6BaseRouteObject &\n (\n | {\n children?: undefined;\n index: true;\n }\n | {\n children?: ReactRouterV6RouteObject[];\n index?: false;\n }\n );\n\nexport interface ReactRouterV6RoutesProps {\n children?: ReactNode;\n location?: Partial<ReactRouterLocation> | string;\n routesComponent?: ReactRouterV6RoutesShape;\n}\n\nexport type ReactRouterV6Params<Key extends string = string> = {\n readonly [key in Key]: string | undefined;\n};\n\nexport interface ReactRouterV6RouteMatch<ParamKey extends string = string> {\n params: ReactRouterV6Params<ParamKey>;\n pathname: string;\n pathnameBase: string;\n route: ReactRouterV6RouteObject;\n}\n\nexport type ReactRouterV6CreateRoutesFromChildren = (children: ReactNode) => ReactRouterV6RouteObject[];\n\nexport type ReactRouterV6MatchRoutes = (\n routes: ReactRouterV6RouteObject[],\n location: Partial<ReactRouterLocation> | string,\n basename?: string | undefined\n) => ReactRouterV6RouteMatch[] | null;\n\nexport type ReactRouterV6RoutesShape = (props: ReactRouterV6RoutesProps) => ReactElement | null;\n\nexport type ReactRouterV6UseLocation = () => ReactRouterLocation;\n\nexport type ReactRouterV6UseNavigationType = () => 'POP' | 'PUSH' | 'REPLACE';\n\nexport interface ReactRouterV6Dependencies {\n createRoutesFromChildren: ReactRouterV6CreateRoutesFromChildren;\n matchRoutes: ReactRouterV6MatchRoutes;\n Routes: ReactRouterV6RoutesShape;\n useLocation: ReactRouterV6UseLocation;\n useNavigationType: ReactRouterV6UseNavigationType;\n}\n\nexport interface ReactRouterV6DataRouterDependencies {\n matchRoutes: ReactRouterV6MatchRoutes;\n}\n\nexport type EventRouteTransitionAttributes = {\n fromRoute?: string;\n fromUrl?: string;\n};\n"]}
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/router/v6/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { ReactElement, ReactNode } from 'react';\n\nimport type { ReactRouterLocation } from '../types';\n\ninterface IndexRouteObjectV6DataRouter {\n caseSensitive?: boolean;\n children?: undefined;\n element?: React.ReactNode | null;\n index: true;\n path?: string;\n}\n\nexport interface NonIndexRouteObjectV6DataRouter {\n caseSensitive?: boolean;\n children?: RouteObjectV6DataRouter[];\n element?: React.ReactNode | null;\n index?: false;\n path?: string;\n}\n\nexport type RouteObjectV6DataRouter = IndexRouteObjectV6DataRouter | NonIndexRouteObjectV6DataRouter;\n\nexport interface ReactRouterV6BaseRouteObject {\n action?: (...args: any[]) => any;\n caseSensitive?: boolean;\n hasErrorBoundary?: boolean;\n handle?: any;\n id?: string;\n loader?: (...args: any[]) => any;\n path?: string;\n shouldRevalidate?: (...args: any[]) => any;\n}\n\nexport type ReactRouterV6RouteObject = ReactRouterV6BaseRouteObject &\n (\n | {\n children?: undefined;\n index: true;\n }\n | {\n children?: ReactRouterV6RouteObject[];\n index?: false;\n }\n );\n\nexport interface ReactRouterV6RoutesProps {\n children?: ReactNode;\n location?: Partial<ReactRouterLocation> | string;\n routesComponent?: ReactRouterV6RoutesShape;\n}\n\nexport type ReactRouterV6Params<Key extends string = string> = {\n readonly [key in Key]: string | undefined;\n};\n\nexport interface ReactRouterV6RouteMatch<ParamKey extends string = string> {\n params: ReactRouterV6Params<ParamKey>;\n pathname: string;\n pathnameBase: string;\n route: ReactRouterV6RouteObject;\n}\n\nexport type ReactRouterV6CreateRoutesFromChildren = (children: ReactNode) => ReactRouterV6RouteObject[];\n\nexport type ReactRouterV6MatchRoutes = (\n routes: ReactRouterV6RouteObject[],\n location: Partial<ReactRouterLocation> | string,\n basename?: string | undefined\n) => ReactRouterV6RouteMatch[] | null;\n\nexport type ReactRouterV6RoutesShape = (props: ReactRouterV6RoutesProps) => ReactElement | null;\n\nexport type ReactRouterV6UseLocation = () => ReactRouterLocation;\n\nexport type ReactRouterV6UseNavigationType = () => 'POP' | 'PUSH' | 'REPLACE';\n\nexport interface ReactRouterV6Dependencies {\n createRoutesFromChildren: ReactRouterV6CreateRoutesFromChildren;\n matchRoutes: ReactRouterV6MatchRoutes;\n Routes: ReactRouterV6RoutesShape;\n useLocation: ReactRouterV6UseLocation;\n useNavigationType: ReactRouterV6UseNavigationType;\n}\n\nexport interface ReactRouterV6DataRouterDependencies {\n matchRoutes: ReactRouterV6MatchRoutes;\n}\n\nexport type EventRouteTransitionAttributes = {\n fromRoute?: string;\n fromUrl?: string;\n};\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"withFaroRouterInstrumentation.js","sourceRoot":"","sources":["../../../../src/router/v6/withFaroRouterInstrumentation.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,sDAAyE;AAEzE,mDAAyC;AACzC,kCAA+D;AAE/D,2DAAqD;AAErD,iCAA+C;AAa/C;;GAEG;AACH,SAAgB,6BAA6B,CAA4B,MAAS;IAChF,IAAI,SAAS,GAAmC,EAAE,CAAC;IAEnD,MAAM,CAAC,SAAS,CAAC,UAAC,KAAK;;QACrB,IAAM,cAAc,GAAmB,KAAK,CAAC,aAAa,CAAC;QAC3D,IAAM,QAAQ,GAAG,KAAK,CAAC,QAAQ,CAAC;QAChC,IAAM,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC;QAE7B,IAAI,kCAAa,IAAI,CAAC,cAAc,KAAK,sBAAc,CAAC,IAAI,IAAI,cAAc,KAAK,sBAAc,CAAC,GAAG,CAAC,EAAE;YACtG,IAAM,KAAK,GAAG,IAAA,4BAAoB,EAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;YACrD,IAAM,GAAG,GAAG,MAAA,2BAAY,CAAC,QAAQ,0CAAE,IAAI,CAAC;YAExC,kBAAG,CAAC,SAAS,CAAC,iCAAkB,aAC9B,OAAO,EAAE,KAAK,EACd,KAAK,EAAE,MAAA,2BAAY,CAAC,QAAQ,0CAAE,IAAI,IAC/B,SAAS,EACZ,CAAC;YAEH,SAAS,GAAG;gBACV,SAAS,EAAE,KAAK;gBAChB,OAAO,EAAE,GAAG;aACb,CAAC;SACH;IACH,CAAC,CAAC,CAAC;IAEH,OAAO,MAAM,CAAC;AAChB,CAAC;AA1BD,sEA0BC","sourcesContent":["import { EVENT_ROUTE_CHANGE, globalObject } from '@grafana/faro-web-sdk';\n\nimport { api } from '../../dependencies';\nimport { NavigationType, ReactRouterLocation } from '../types';\n\nimport { isInitialized } from './routerDependencies';\nimport type { EventRouteTransitionAttributes,
|
|
1
|
+
{"version":3,"file":"withFaroRouterInstrumentation.js","sourceRoot":"","sources":["../../../../src/router/v6/withFaroRouterInstrumentation.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,sDAAyE;AAEzE,mDAAyC;AACzC,kCAA+D;AAE/D,2DAAqD;AAErD,iCAA+C;AAa/C;;GAEG;AACH,SAAgB,6BAA6B,CAA4B,MAAS;IAChF,IAAI,SAAS,GAAmC,EAAE,CAAC;IAEnD,MAAM,CAAC,SAAS,CAAC,UAAC,KAAK;;QACrB,IAAM,cAAc,GAAmB,KAAK,CAAC,aAAa,CAAC;QAC3D,IAAM,QAAQ,GAAG,KAAK,CAAC,QAAQ,CAAC;QAChC,IAAM,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC;QAE7B,IAAI,kCAAa,IAAI,CAAC,cAAc,KAAK,sBAAc,CAAC,IAAI,IAAI,cAAc,KAAK,sBAAc,CAAC,GAAG,CAAC,EAAE;YACtG,IAAM,KAAK,GAAG,IAAA,4BAAoB,EAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;YACrD,IAAM,GAAG,GAAG,MAAA,2BAAY,CAAC,QAAQ,0CAAE,IAAI,CAAC;YAExC,kBAAG,CAAC,SAAS,CAAC,iCAAkB,aAC9B,OAAO,EAAE,KAAK,EACd,KAAK,EAAE,MAAA,2BAAY,CAAC,QAAQ,0CAAE,IAAI,IAC/B,SAAS,EACZ,CAAC;YAEH,SAAS,GAAG;gBACV,SAAS,EAAE,KAAK;gBAChB,OAAO,EAAE,GAAG;aACb,CAAC;SACH;IACH,CAAC,CAAC,CAAC;IAEH,OAAO,MAAM,CAAC;AAChB,CAAC;AA1BD,sEA0BC","sourcesContent":["import { EVENT_ROUTE_CHANGE, globalObject } from '@grafana/faro-web-sdk';\n\nimport { api } from '../../dependencies';\nimport { NavigationType, ReactRouterLocation } from '../types';\n\nimport { isInitialized } from './routerDependencies';\nimport type { EventRouteTransitionAttributes, RouteObjectV6DataRouter } from './types';\nimport { getRouteFromLocation } from './utils';\n\ninterface RouterState {\n historyAction: NavigationType | any;\n location: ReactRouterLocation;\n}\n\ninterface Router {\n state: RouterState;\n routes: RouteObjectV6DataRouter[];\n subscribe(fn: (state: RouterState) => void): () => void;\n}\n\n/**\n * To use with React Router 6.4 data APIs.\n */\nexport function withFaroRouterInstrumentation<R extends Router = Router>(router: R) {\n let lastRoute: EventRouteTransitionAttributes = {};\n\n router.subscribe((state) => {\n const navigationType: NavigationType = state.historyAction;\n const location = state.location;\n const routes = router.routes;\n\n if (isInitialized && (navigationType === NavigationType.Push || navigationType === NavigationType.Pop)) {\n const route = getRouteFromLocation(routes, location);\n const url = globalObject.location?.href;\n\n api.pushEvent(EVENT_ROUTE_CHANGE, {\n toRoute: route,\n toUrl: globalObject.location?.href,\n ...lastRoute,\n });\n\n lastRoute = {\n fromRoute: route,\n fromUrl: url,\n };\n }\n });\n\n return router;\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/router/v6/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { ReactElement, ReactNode } from 'react';\n\nimport type { ReactRouterLocation } from '../types';\n\nexport interface ReactRouterV6BaseRouteObject {\n action?: (...args: any[]) => any;\n caseSensitive?: boolean;\n hasErrorBoundary?: boolean;\n handle?: any;\n id?: string;\n loader?: (...args: any[]) => any;\n path?: string;\n shouldRevalidate?: (...args: any[]) => any;\n}\n\nexport type ReactRouterV6RouteObject = ReactRouterV6BaseRouteObject &\n (\n | {\n children?: undefined;\n index: true;\n }\n | {\n children?: ReactRouterV6RouteObject[];\n index?: false;\n }\n );\n\nexport interface ReactRouterV6RoutesProps {\n children?: ReactNode;\n location?: Partial<ReactRouterLocation> | string;\n routesComponent?: ReactRouterV6RoutesShape;\n}\n\nexport type ReactRouterV6Params<Key extends string = string> = {\n readonly [key in Key]: string | undefined;\n};\n\nexport interface ReactRouterV6RouteMatch<ParamKey extends string = string> {\n params: ReactRouterV6Params<ParamKey>;\n pathname: string;\n pathnameBase: string;\n route: ReactRouterV6RouteObject;\n}\n\nexport type ReactRouterV6CreateRoutesFromChildren = (children: ReactNode) => ReactRouterV6RouteObject[];\n\nexport type ReactRouterV6MatchRoutes = (\n routes: ReactRouterV6RouteObject[],\n location: Partial<ReactRouterLocation> | string,\n basename?: string | undefined\n) => ReactRouterV6RouteMatch[] | null;\n\nexport type ReactRouterV6RoutesShape = (props: ReactRouterV6RoutesProps) => ReactElement | null;\n\nexport type ReactRouterV6UseLocation = () => ReactRouterLocation;\n\nexport type ReactRouterV6UseNavigationType = () => 'POP' | 'PUSH' | 'REPLACE';\n\nexport interface ReactRouterV6Dependencies {\n createRoutesFromChildren: ReactRouterV6CreateRoutesFromChildren;\n matchRoutes: ReactRouterV6MatchRoutes;\n Routes: ReactRouterV6RoutesShape;\n useLocation: ReactRouterV6UseLocation;\n useNavigationType: ReactRouterV6UseNavigationType;\n}\n\nexport interface ReactRouterV6DataRouterDependencies {\n matchRoutes: ReactRouterV6MatchRoutes;\n}\n\nexport type EventRouteTransitionAttributes = {\n fromRoute?: string;\n fromUrl?: string;\n};\n"]}
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/router/v6/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { ReactElement, ReactNode } from 'react';\n\nimport type { ReactRouterLocation } from '../types';\n\ninterface IndexRouteObjectV6DataRouter {\n caseSensitive?: boolean;\n children?: undefined;\n element?: React.ReactNode | null;\n index: true;\n path?: string;\n}\n\nexport interface NonIndexRouteObjectV6DataRouter {\n caseSensitive?: boolean;\n children?: RouteObjectV6DataRouter[];\n element?: React.ReactNode | null;\n index?: false;\n path?: string;\n}\n\nexport type RouteObjectV6DataRouter = IndexRouteObjectV6DataRouter | NonIndexRouteObjectV6DataRouter;\n\nexport interface ReactRouterV6BaseRouteObject {\n action?: (...args: any[]) => any;\n caseSensitive?: boolean;\n hasErrorBoundary?: boolean;\n handle?: any;\n id?: string;\n loader?: (...args: any[]) => any;\n path?: string;\n shouldRevalidate?: (...args: any[]) => any;\n}\n\nexport type ReactRouterV6RouteObject = ReactRouterV6BaseRouteObject &\n (\n | {\n children?: undefined;\n index: true;\n }\n | {\n children?: ReactRouterV6RouteObject[];\n index?: false;\n }\n );\n\nexport interface ReactRouterV6RoutesProps {\n children?: ReactNode;\n location?: Partial<ReactRouterLocation> | string;\n routesComponent?: ReactRouterV6RoutesShape;\n}\n\nexport type ReactRouterV6Params<Key extends string = string> = {\n readonly [key in Key]: string | undefined;\n};\n\nexport interface ReactRouterV6RouteMatch<ParamKey extends string = string> {\n params: ReactRouterV6Params<ParamKey>;\n pathname: string;\n pathnameBase: string;\n route: ReactRouterV6RouteObject;\n}\n\nexport type ReactRouterV6CreateRoutesFromChildren = (children: ReactNode) => ReactRouterV6RouteObject[];\n\nexport type ReactRouterV6MatchRoutes = (\n routes: ReactRouterV6RouteObject[],\n location: Partial<ReactRouterLocation> | string,\n basename?: string | undefined\n) => ReactRouterV6RouteMatch[] | null;\n\nexport type ReactRouterV6RoutesShape = (props: ReactRouterV6RoutesProps) => ReactElement | null;\n\nexport type ReactRouterV6UseLocation = () => ReactRouterLocation;\n\nexport type ReactRouterV6UseNavigationType = () => 'POP' | 'PUSH' | 'REPLACE';\n\nexport interface ReactRouterV6Dependencies {\n createRoutesFromChildren: ReactRouterV6CreateRoutesFromChildren;\n matchRoutes: ReactRouterV6MatchRoutes;\n Routes: ReactRouterV6RoutesShape;\n useLocation: ReactRouterV6UseLocation;\n useNavigationType: ReactRouterV6UseNavigationType;\n}\n\nexport interface ReactRouterV6DataRouterDependencies {\n matchRoutes: ReactRouterV6MatchRoutes;\n}\n\nexport type EventRouteTransitionAttributes = {\n fromRoute?: string;\n fromUrl?: string;\n};\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"withFaroRouterInstrumentation.js","sourceRoot":"","sources":["../../../../src/router/v6/withFaroRouterInstrumentation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAEzE,OAAO,EAAE,GAAG,EAAE,MAAM,oBAAoB,CAAC;AACzC,OAAO,EAAE,cAAc,EAAuB,MAAM,UAAU,CAAC;AAE/D,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAErD,OAAO,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAC;AAa/C;;GAEG;AACH,MAAM,UAAU,6BAA6B,CAA4B,MAAS;IAChF,IAAI,SAAS,GAAmC,EAAE,CAAC;IAEnD,MAAM,CAAC,SAAS,CAAC,CAAC,KAAK,EAAE,EAAE;;QACzB,MAAM,cAAc,GAAmB,KAAK,CAAC,aAAa,CAAC;QAC3D,MAAM,QAAQ,GAAG,KAAK,CAAC,QAAQ,CAAC;QAChC,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC;QAE7B,IAAI,aAAa,IAAI,CAAC,cAAc,KAAK,cAAc,CAAC,IAAI,IAAI,cAAc,KAAK,cAAc,CAAC,GAAG,CAAC,EAAE;YACtG,MAAM,KAAK,GAAG,oBAAoB,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;YACrD,MAAM,GAAG,GAAG,MAAA,YAAY,CAAC,QAAQ,0CAAE,IAAI,CAAC;YAExC,GAAG,CAAC,SAAS,CAAC,kBAAkB,kBAC9B,OAAO,EAAE,KAAK,EACd,KAAK,EAAE,MAAA,YAAY,CAAC,QAAQ,0CAAE,IAAI,IAC/B,SAAS,EACZ,CAAC;YAEH,SAAS,GAAG;gBACV,SAAS,EAAE,KAAK;gBAChB,OAAO,EAAE,GAAG;aACb,CAAC;SACH;IACH,CAAC,CAAC,CAAC;IAEH,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import { EVENT_ROUTE_CHANGE, globalObject } from '@grafana/faro-web-sdk';\n\nimport { api } from '../../dependencies';\nimport { NavigationType, ReactRouterLocation } from '../types';\n\nimport { isInitialized } from './routerDependencies';\nimport type { EventRouteTransitionAttributes,
|
|
1
|
+
{"version":3,"file":"withFaroRouterInstrumentation.js","sourceRoot":"","sources":["../../../../src/router/v6/withFaroRouterInstrumentation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAEzE,OAAO,EAAE,GAAG,EAAE,MAAM,oBAAoB,CAAC;AACzC,OAAO,EAAE,cAAc,EAAuB,MAAM,UAAU,CAAC;AAE/D,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAErD,OAAO,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAC;AAa/C;;GAEG;AACH,MAAM,UAAU,6BAA6B,CAA4B,MAAS;IAChF,IAAI,SAAS,GAAmC,EAAE,CAAC;IAEnD,MAAM,CAAC,SAAS,CAAC,CAAC,KAAK,EAAE,EAAE;;QACzB,MAAM,cAAc,GAAmB,KAAK,CAAC,aAAa,CAAC;QAC3D,MAAM,QAAQ,GAAG,KAAK,CAAC,QAAQ,CAAC;QAChC,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC;QAE7B,IAAI,aAAa,IAAI,CAAC,cAAc,KAAK,cAAc,CAAC,IAAI,IAAI,cAAc,KAAK,cAAc,CAAC,GAAG,CAAC,EAAE;YACtG,MAAM,KAAK,GAAG,oBAAoB,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;YACrD,MAAM,GAAG,GAAG,MAAA,YAAY,CAAC,QAAQ,0CAAE,IAAI,CAAC;YAExC,GAAG,CAAC,SAAS,CAAC,kBAAkB,kBAC9B,OAAO,EAAE,KAAK,EACd,KAAK,EAAE,MAAA,YAAY,CAAC,QAAQ,0CAAE,IAAI,IAC/B,SAAS,EACZ,CAAC;YAEH,SAAS,GAAG;gBACV,SAAS,EAAE,KAAK;gBAChB,OAAO,EAAE,GAAG;aACb,CAAC;SACH;IACH,CAAC,CAAC,CAAC;IAEH,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import { EVENT_ROUTE_CHANGE, globalObject } from '@grafana/faro-web-sdk';\n\nimport { api } from '../../dependencies';\nimport { NavigationType, ReactRouterLocation } from '../types';\n\nimport { isInitialized } from './routerDependencies';\nimport type { EventRouteTransitionAttributes, RouteObjectV6DataRouter } from './types';\nimport { getRouteFromLocation } from './utils';\n\ninterface RouterState {\n historyAction: NavigationType | any;\n location: ReactRouterLocation;\n}\n\ninterface Router {\n state: RouterState;\n routes: RouteObjectV6DataRouter[];\n subscribe(fn: (state: RouterState) => void): () => void;\n}\n\n/**\n * To use with React Router 6.4 data APIs.\n */\nexport function withFaroRouterInstrumentation<R extends Router = Router>(router: R) {\n let lastRoute: EventRouteTransitionAttributes = {};\n\n router.subscribe((state) => {\n const navigationType: NavigationType = state.historyAction;\n const location = state.location;\n const routes = router.routes;\n\n if (isInitialized && (navigationType === NavigationType.Push || navigationType === NavigationType.Pop)) {\n const route = getRouteFromLocation(routes, location);\n const url = globalObject.location?.href;\n\n api.pushEvent(EVENT_ROUTE_CHANGE, {\n toRoute: route,\n toUrl: globalObject.location?.href,\n ...lastRoute,\n });\n\n lastRoute = {\n fromRoute: route,\n fromUrl: url,\n };\n }\n });\n\n return router;\n}\n"]}
|
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
import type { ReactElement, ReactNode } from 'react';
|
|
2
2
|
import type { ReactRouterLocation } from '../types';
|
|
3
|
+
interface IndexRouteObjectV6DataRouter {
|
|
4
|
+
caseSensitive?: boolean;
|
|
5
|
+
children?: undefined;
|
|
6
|
+
element?: React.ReactNode | null;
|
|
7
|
+
index: true;
|
|
8
|
+
path?: string;
|
|
9
|
+
}
|
|
10
|
+
export interface NonIndexRouteObjectV6DataRouter {
|
|
11
|
+
caseSensitive?: boolean;
|
|
12
|
+
children?: RouteObjectV6DataRouter[];
|
|
13
|
+
element?: React.ReactNode | null;
|
|
14
|
+
index?: false;
|
|
15
|
+
path?: string;
|
|
16
|
+
}
|
|
17
|
+
export type RouteObjectV6DataRouter = IndexRouteObjectV6DataRouter | NonIndexRouteObjectV6DataRouter;
|
|
3
18
|
export interface ReactRouterV6BaseRouteObject {
|
|
4
19
|
action?: (...args: any[]) => any;
|
|
5
20
|
caseSensitive?: boolean;
|
|
@@ -50,3 +65,4 @@ export type EventRouteTransitionAttributes = {
|
|
|
50
65
|
fromRoute?: string;
|
|
51
66
|
fromUrl?: string;
|
|
52
67
|
};
|
|
68
|
+
export {};
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { NavigationType, ReactRouterLocation } from '../types';
|
|
2
|
-
import type {
|
|
2
|
+
import type { RouteObjectV6DataRouter } from './types';
|
|
3
3
|
interface RouterState {
|
|
4
4
|
historyAction: NavigationType | any;
|
|
5
5
|
location: ReactRouterLocation;
|
|
6
6
|
}
|
|
7
7
|
interface Router {
|
|
8
8
|
state: RouterState;
|
|
9
|
-
routes:
|
|
9
|
+
routes: RouteObjectV6DataRouter[];
|
|
10
10
|
subscribe(fn: (state: RouterState) => void): () => void;
|
|
11
11
|
}
|
|
12
12
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@grafana/faro-react",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.7.1",
|
|
4
4
|
"description": "Faro package that enables easier integration in projects built with React.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"observability",
|
|
@@ -52,8 +52,8 @@
|
|
|
52
52
|
"quality:circular-deps": "madge --circular ."
|
|
53
53
|
},
|
|
54
54
|
"dependencies": {
|
|
55
|
-
"@grafana/faro-web-sdk": "^1.
|
|
56
|
-
"@grafana/faro-web-tracing": "^1.
|
|
55
|
+
"@grafana/faro-web-sdk": "^1.7.1",
|
|
56
|
+
"@grafana/faro-web-tracing": "^1.7.1",
|
|
57
57
|
"hoist-non-react-statics": "^3.3.2"
|
|
58
58
|
},
|
|
59
59
|
"devDependencies": {
|
|
@@ -71,5 +71,5 @@
|
|
|
71
71
|
"publishConfig": {
|
|
72
72
|
"access": "public"
|
|
73
73
|
},
|
|
74
|
-
"gitHead": "
|
|
74
|
+
"gitHead": "11fba62c05d570dfdbc0f83fc1a3dbdc3abafecd"
|
|
75
75
|
}
|