@servicetitan/datadog-rum 40.3.0 → 40.4.0
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/hash-routing.d.ts.map +1 -1
- package/dist/hash-routing.js +48 -19
- package/dist/hash-routing.js.map +1 -1
- package/package.json +1 -1
- package/src/hash-routing.tsx +55 -20
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hash-routing.d.ts","sourceRoot":"","sources":["../src/hash-routing.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,EAAE,
|
|
1
|
+
{"version":3,"file":"hash-routing.d.ts","sourceRoot":"","sources":["../src/hash-routing.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,EAAE,EAAoC,MAAM,OAAO,CAAC;AAO7D,MAAM,WAAW,kBAAkB;IAC/B,gGAAgG;IAChG,eAAe,CAAC,EAAE,MAAM,EAAE,CAAC;CAC9B;AAED,eAAO,MAAM,WAAW,EAAE,EAAE,CAAC,kBAAkB,CAG9C,CAAC"}
|
package/dist/hash-routing.js
CHANGED
|
@@ -1,31 +1,60 @@
|
|
|
1
1
|
import { datadogRum } from '@datadog/browser-rum';
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
2
|
+
import { useLayoutEffect, useMemo, useRef } from 'react';
|
|
3
|
+
import * as ReactRouterDom from 'react-router-dom';
|
|
4
4
|
import { sanitizeViewName } from './sanitize-view-name';
|
|
5
|
+
/* `useHistory` is react-router v5 only; a named import fails to build on v6+. */ const { useHistory, useLocation } = ReactRouterDom;
|
|
5
6
|
export const HashRouting = ({ redirectedViews })=>{
|
|
6
7
|
useHashRouting(redirectedViews);
|
|
7
8
|
return null;
|
|
8
9
|
};
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
}
|
|
10
|
+
const useHashRouting = typeof useHistory === 'function' ? useHistoryRouting : useLocationRouting;
|
|
11
|
+
/*
|
|
12
|
+
* Starts views from the router's history, before it re-renders and the page sends requests.
|
|
13
|
+
* A layout effect subscribes before pages' componentDidMount, so a page's first redirect is seen too.
|
|
14
|
+
*/ function useHistoryRouting(redirectedViews = []) {
|
|
15
|
+
const history = useHistory();
|
|
16
|
+
const redirects = useSanitizedViewNames(redirectedViews);
|
|
17
|
+
const view = useRef(noView);
|
|
18
|
+
useLayoutEffect(()=>{
|
|
19
|
+
const update = ({ pathname })=>{
|
|
20
|
+
view.current = updateView(view.current, pathname, redirects);
|
|
21
|
+
};
|
|
22
|
+
update(history.location);
|
|
23
|
+
return history.listen(update);
|
|
24
24
|
}, [
|
|
25
|
-
|
|
26
|
-
|
|
25
|
+
history,
|
|
26
|
+
redirects
|
|
27
27
|
]);
|
|
28
28
|
}
|
|
29
|
+
/* A layout effect starts the view before pages' componentDidMount and effects send requests. */ function useLocationRouting(redirectedViews = []) {
|
|
30
|
+
const { pathname } = useLocation();
|
|
31
|
+
const redirects = useSanitizedViewNames(redirectedViews);
|
|
32
|
+
const view = useRef(noView);
|
|
33
|
+
useLayoutEffect(()=>{
|
|
34
|
+
view.current = updateView(view.current, pathname, redirects);
|
|
35
|
+
}, [
|
|
36
|
+
pathname,
|
|
37
|
+
redirects
|
|
38
|
+
]);
|
|
39
|
+
}
|
|
40
|
+
const noView = {
|
|
41
|
+
isRedirect: false
|
|
42
|
+
};
|
|
43
|
+
function updateView(view, pathname, redirects) {
|
|
44
|
+
const name = sanitizeViewName(pathname);
|
|
45
|
+
if (name === view.name) {
|
|
46
|
+
return view;
|
|
47
|
+
}
|
|
48
|
+
/* A redirect's destination takes over the view the redirect started. */ if (view.isRedirect) {
|
|
49
|
+
datadogRum.setViewName(name);
|
|
50
|
+
} else {
|
|
51
|
+
datadogRum.startView(name);
|
|
52
|
+
}
|
|
53
|
+
return {
|
|
54
|
+
name,
|
|
55
|
+
isRedirect: redirects.has(name)
|
|
56
|
+
};
|
|
57
|
+
}
|
|
29
58
|
function useSanitizedViewNames(viewNames) {
|
|
30
59
|
const key = viewNames.join('\n'); // handles when callers pass a new array on every render
|
|
31
60
|
// eslint-disable-next-line react-hooks/exhaustive-deps -- key covers viewNames
|
package/dist/hash-routing.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/hash-routing.tsx"],"sourcesContent":["import { datadogRum } from '@datadog/browser-rum';\nimport { FC,
|
|
1
|
+
{"version":3,"sources":["../src/hash-routing.tsx"],"sourcesContent":["import { datadogRum } from '@datadog/browser-rum';\nimport { FC, useLayoutEffect, useMemo, useRef } from 'react';\nimport * as ReactRouterDom from 'react-router-dom';\nimport { sanitizeViewName } from './sanitize-view-name';\n\n/* `useHistory` is react-router v5 only; a named import fails to build on v6+. */\nconst { useHistory, useLocation } = ReactRouterDom;\n\nexport interface HashRoutingOptions {\n /** RUM view names of routes that only redirect to another route, such as `/lead/index/{id}`. */\n redirectedViews?: string[];\n}\n\nexport const HashRouting: FC<HashRoutingOptions> = ({ redirectedViews }) => {\n useHashRouting(redirectedViews);\n return null;\n};\n\nconst useHashRouting = typeof useHistory === 'function' ? useHistoryRouting : useLocationRouting;\n\n/*\n * Starts views from the router's history, before it re-renders and the page sends requests.\n * A layout effect subscribes before pages' componentDidMount, so a page's first redirect is seen too.\n */\nfunction useHistoryRouting(redirectedViews: string[] = []) {\n const history = useHistory();\n const redirects = useSanitizedViewNames(redirectedViews);\n const view = useRef(noView);\n\n useLayoutEffect(() => {\n const update = ({ pathname }: { pathname: string }) => {\n view.current = updateView(view.current, pathname, redirects);\n };\n update(history.location);\n return history.listen(update);\n }, [history, redirects]);\n}\n\n/* A layout effect starts the view before pages' componentDidMount and effects send requests. */\nfunction useLocationRouting(redirectedViews: string[] = []) {\n const { pathname } = useLocation();\n const redirects = useSanitizedViewNames(redirectedViews);\n const view = useRef(noView);\n\n useLayoutEffect(() => {\n view.current = updateView(view.current, pathname, redirects);\n }, [pathname, redirects]);\n}\n\ninterface View {\n name?: string;\n isRedirect: boolean;\n}\n\nconst noView: View = { isRedirect: false };\n\nfunction updateView(view: View, pathname: string, redirects: ReadonlySet<string>): View {\n const name = sanitizeViewName(pathname);\n if (name === view.name) {\n return view;\n }\n /* A redirect's destination takes over the view the redirect started. */\n if (view.isRedirect) {\n datadogRum.setViewName(name);\n } else {\n datadogRum.startView(name);\n }\n return { name, isRedirect: redirects.has(name) };\n}\n\nfunction useSanitizedViewNames(viewNames: string[]) {\n const key = viewNames.join('\\n'); // handles when callers pass a new array on every render\n // eslint-disable-next-line react-hooks/exhaustive-deps -- key covers viewNames\n return useMemo(() => new Set(viewNames.map(sanitizeViewName)), [key]);\n}\n"],"names":["datadogRum","useLayoutEffect","useMemo","useRef","ReactRouterDom","sanitizeViewName","useHistory","useLocation","HashRouting","redirectedViews","useHashRouting","useHistoryRouting","useLocationRouting","history","redirects","useSanitizedViewNames","view","noView","update","pathname","current","updateView","location","listen","isRedirect","name","setViewName","startView","has","viewNames","key","join","Set","map"],"mappings":"AAAA,SAASA,UAAU,QAAQ,uBAAuB;AAClD,SAAaC,eAAe,EAAEC,OAAO,EAAEC,MAAM,QAAQ,QAAQ;AAC7D,YAAYC,oBAAoB,mBAAmB;AACnD,SAASC,gBAAgB,QAAQ,uBAAuB;AAExD,+EAA+E,GAC/E,MAAM,EAAEC,UAAU,EAAEC,WAAW,EAAE,GAAGH;AAOpC,OAAO,MAAMI,cAAsC,CAAC,EAAEC,eAAe,EAAE;IACnEC,eAAeD;IACf,OAAO;AACX,EAAE;AAEF,MAAMC,iBAAiB,OAAOJ,eAAe,aAAaK,oBAAoBC;AAE9E;;;CAGC,GACD,SAASD,kBAAkBF,kBAA4B,EAAE;IACrD,MAAMI,UAAUP;IAChB,MAAMQ,YAAYC,sBAAsBN;IACxC,MAAMO,OAAOb,OAAOc;IAEpBhB,gBAAgB;QACZ,MAAMiB,SAAS,CAAC,EAAEC,QAAQ,EAAwB;YAC9CH,KAAKI,OAAO,GAAGC,WAAWL,KAAKI,OAAO,EAAED,UAAUL;QACtD;QACAI,OAAOL,QAAQS,QAAQ;QACvB,OAAOT,QAAQU,MAAM,CAACL;IAC1B,GAAG;QAACL;QAASC;KAAU;AAC3B;AAEA,8FAA8F,GAC9F,SAASF,mBAAmBH,kBAA4B,EAAE;IACtD,MAAM,EAAEU,QAAQ,EAAE,GAAGZ;IACrB,MAAMO,YAAYC,sBAAsBN;IACxC,MAAMO,OAAOb,OAAOc;IAEpBhB,gBAAgB;QACZe,KAAKI,OAAO,GAAGC,WAAWL,KAAKI,OAAO,EAAED,UAAUL;IACtD,GAAG;QAACK;QAAUL;KAAU;AAC5B;AAOA,MAAMG,SAAe;IAAEO,YAAY;AAAM;AAEzC,SAASH,WAAWL,IAAU,EAAEG,QAAgB,EAAEL,SAA8B;IAC5E,MAAMW,OAAOpB,iBAAiBc;IAC9B,IAAIM,SAAST,KAAKS,IAAI,EAAE;QACpB,OAAOT;IACX;IACA,sEAAsE,GACtE,IAAIA,KAAKQ,UAAU,EAAE;QACjBxB,WAAW0B,WAAW,CAACD;IAC3B,OAAO;QACHzB,WAAW2B,SAAS,CAACF;IACzB;IACA,OAAO;QAAEA;QAAMD,YAAYV,UAAUc,GAAG,CAACH;IAAM;AACnD;AAEA,SAASV,sBAAsBc,SAAmB;IAC9C,MAAMC,MAAMD,UAAUE,IAAI,CAAC,OAAO,wDAAwD;IAC1F,+EAA+E;IAC/E,OAAO7B,QAAQ,IAAM,IAAI8B,IAAIH,UAAUI,GAAG,CAAC5B,oBAAoB;QAACyB;KAAI;AACxE"}
|
package/package.json
CHANGED
package/src/hash-routing.tsx
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import { datadogRum } from '@datadog/browser-rum';
|
|
2
|
-
import { FC,
|
|
3
|
-
import
|
|
2
|
+
import { FC, useLayoutEffect, useMemo, useRef } from 'react';
|
|
3
|
+
import * as ReactRouterDom from 'react-router-dom';
|
|
4
4
|
import { sanitizeViewName } from './sanitize-view-name';
|
|
5
5
|
|
|
6
|
+
/* `useHistory` is react-router v5 only; a named import fails to build on v6+. */
|
|
7
|
+
const { useHistory, useLocation } = ReactRouterDom;
|
|
8
|
+
|
|
6
9
|
export interface HashRoutingOptions {
|
|
7
10
|
/** RUM view names of routes that only redirect to another route, such as `/lead/index/{id}`. */
|
|
8
11
|
redirectedViews?: string[];
|
|
@@ -13,24 +16,56 @@ export const HashRouting: FC<HashRoutingOptions> = ({ redirectedViews }) => {
|
|
|
13
16
|
return null;
|
|
14
17
|
};
|
|
15
18
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
}, [
|
|
19
|
+
const useHashRouting = typeof useHistory === 'function' ? useHistoryRouting : useLocationRouting;
|
|
20
|
+
|
|
21
|
+
/*
|
|
22
|
+
* Starts views from the router's history, before it re-renders and the page sends requests.
|
|
23
|
+
* A layout effect subscribes before pages' componentDidMount, so a page's first redirect is seen too.
|
|
24
|
+
*/
|
|
25
|
+
function useHistoryRouting(redirectedViews: string[] = []) {
|
|
26
|
+
const history = useHistory();
|
|
27
|
+
const redirects = useSanitizedViewNames(redirectedViews);
|
|
28
|
+
const view = useRef(noView);
|
|
29
|
+
|
|
30
|
+
useLayoutEffect(() => {
|
|
31
|
+
const update = ({ pathname }: { pathname: string }) => {
|
|
32
|
+
view.current = updateView(view.current, pathname, redirects);
|
|
33
|
+
};
|
|
34
|
+
update(history.location);
|
|
35
|
+
return history.listen(update);
|
|
36
|
+
}, [history, redirects]);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/* A layout effect starts the view before pages' componentDidMount and effects send requests. */
|
|
40
|
+
function useLocationRouting(redirectedViews: string[] = []) {
|
|
41
|
+
const { pathname } = useLocation();
|
|
42
|
+
const redirects = useSanitizedViewNames(redirectedViews);
|
|
43
|
+
const view = useRef(noView);
|
|
44
|
+
|
|
45
|
+
useLayoutEffect(() => {
|
|
46
|
+
view.current = updateView(view.current, pathname, redirects);
|
|
47
|
+
}, [pathname, redirects]);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
interface View {
|
|
51
|
+
name?: string;
|
|
52
|
+
isRedirect: boolean;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const noView: View = { isRedirect: false };
|
|
56
|
+
|
|
57
|
+
function updateView(view: View, pathname: string, redirects: ReadonlySet<string>): View {
|
|
58
|
+
const name = sanitizeViewName(pathname);
|
|
59
|
+
if (name === view.name) {
|
|
60
|
+
return view;
|
|
61
|
+
}
|
|
62
|
+
/* A redirect's destination takes over the view the redirect started. */
|
|
63
|
+
if (view.isRedirect) {
|
|
64
|
+
datadogRum.setViewName(name);
|
|
65
|
+
} else {
|
|
66
|
+
datadogRum.startView(name);
|
|
67
|
+
}
|
|
68
|
+
return { name, isRedirect: redirects.has(name) };
|
|
34
69
|
}
|
|
35
70
|
|
|
36
71
|
function useSanitizedViewNames(viewNames: string[]) {
|