@servicetitan/datadog-rum 40.3.0 → 41.0.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.
@@ -1 +1 @@
1
- {"version":3,"file":"hash-routing.d.ts","sourceRoot":"","sources":["../src/hash-routing.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,EAAE,EAA8B,MAAM,OAAO,CAAC;AAIvD,MAAM,WAAW,kBAAkB;IAC/B,gGAAgG;IAChG,eAAe,CAAC,EAAE,MAAM,EAAE,CAAC;CAC9B;AAED,eAAO,MAAM,WAAW,EAAE,EAAE,CAAC,kBAAkB,CAG9C,CAAC"}
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"}
@@ -1,31 +1,60 @@
1
1
  import { datadogRum } from '@datadog/browser-rum';
2
- import { useEffect, useMemo, useRef } from 'react';
3
- import { useLocation } from 'react-router-dom';
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
- function useHashRouting(redirectedViews = []) {
10
- const pathname = sanitizeViewName(useLocation().pathname);
11
- const isRedirect = useSanitizedViewNames(redirectedViews).has(pathname);
12
- const lastPathname = useRef(undefined);
13
- const isRedirecting = useRef(false);
14
- useEffect(()=>{
15
- if (lastPathname.current !== pathname) {
16
- /* A redirect's destination takes over the view the redirect started. */ if (isRedirecting.current) {
17
- datadogRum.setViewName(pathname);
18
- } else {
19
- datadogRum.startView(pathname);
20
- }
21
- lastPathname.current = pathname;
22
- isRedirecting.current = isRedirect;
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
- isRedirect,
26
- pathname
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
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/hash-routing.tsx"],"sourcesContent":["import { datadogRum } from '@datadog/browser-rum';\nimport { FC, useEffect, useMemo, useRef } from 'react';\nimport { useLocation } from 'react-router-dom';\nimport { sanitizeViewName } from './sanitize-view-name';\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\nfunction useHashRouting(redirectedViews: string[] = []) {\n const pathname = sanitizeViewName(useLocation().pathname);\n const isRedirect = useSanitizedViewNames(redirectedViews).has(pathname);\n const lastPathname = useRef<string | undefined>(undefined);\n const isRedirecting = useRef(false);\n\n useEffect(() => {\n if (lastPathname.current !== pathname) {\n /* A redirect's destination takes over the view the redirect started. */\n if (isRedirecting.current) {\n datadogRum.setViewName(pathname);\n } else {\n datadogRum.startView(pathname);\n }\n lastPathname.current = pathname;\n isRedirecting.current = isRedirect;\n }\n }, [isRedirect, pathname]);\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","useEffect","useMemo","useRef","useLocation","sanitizeViewName","HashRouting","redirectedViews","useHashRouting","pathname","isRedirect","useSanitizedViewNames","has","lastPathname","undefined","isRedirecting","current","setViewName","startView","viewNames","key","join","Set","map"],"mappings":"AAAA,SAASA,UAAU,QAAQ,uBAAuB;AAClD,SAAaC,SAAS,EAAEC,OAAO,EAAEC,MAAM,QAAQ,QAAQ;AACvD,SAASC,WAAW,QAAQ,mBAAmB;AAC/C,SAASC,gBAAgB,QAAQ,uBAAuB;AAOxD,OAAO,MAAMC,cAAsC,CAAC,EAAEC,eAAe,EAAE;IACnEC,eAAeD;IACf,OAAO;AACX,EAAE;AAEF,SAASC,eAAeD,kBAA4B,EAAE;IAClD,MAAME,WAAWJ,iBAAiBD,cAAcK,QAAQ;IACxD,MAAMC,aAAaC,sBAAsBJ,iBAAiBK,GAAG,CAACH;IAC9D,MAAMI,eAAeV,OAA2BW;IAChD,MAAMC,gBAAgBZ,OAAO;IAE7BF,UAAU;QACN,IAAIY,aAAaG,OAAO,KAAKP,UAAU;YACnC,sEAAsE,GACtE,IAAIM,cAAcC,OAAO,EAAE;gBACvBhB,WAAWiB,WAAW,CAACR;YAC3B,OAAO;gBACHT,WAAWkB,SAAS,CAACT;YACzB;YACAI,aAAaG,OAAO,GAAGP;YACvBM,cAAcC,OAAO,GAAGN;QAC5B;IACJ,GAAG;QAACA;QAAYD;KAAS;AAC7B;AAEA,SAASE,sBAAsBQ,SAAmB;IAC9C,MAAMC,MAAMD,UAAUE,IAAI,CAAC,OAAO,wDAAwD;IAC1F,+EAA+E;IAC/E,OAAOnB,QAAQ,IAAM,IAAIoB,IAAIH,UAAUI,GAAG,CAAClB,oBAAoB;QAACe;KAAI;AACxE"}
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;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F,+EAA+E;IAC/E,OAAO7B,QAAQ,IAAM,IAAI8B,IAAIH,UAAUI,GAAG,CAAC5B,oBAAoB;QAACyB;KAAI;AACxE"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@servicetitan/datadog-rum",
3
- "version": "40.3.0",
3
+ "version": "41.0.0",
4
4
  "description": "DataDog RUM JS SDK configuration for standalone applications",
5
5
  "homepage": "https://docs.st.dev/docs/frontend/uikit/datadog-rum",
6
6
  "repository": {
@@ -26,9 +26,9 @@
26
26
  "!**/*.test.*"
27
27
  ],
28
28
  "devDependencies": {
29
- "@datadog/browser-rum": "^7.16.2",
29
+ "@datadog/browser-rum": "^7.18.0",
30
30
  "@testing-library/dom": "^10.4.2",
31
- "@testing-library/jest-dom": "^7.0.1",
31
+ "@testing-library/jest-dom": "^8.0.0",
32
32
  "@testing-library/react": "^16.3.3",
33
33
  "history": "~4.10.1",
34
34
  "react": "~18.3.1",
@@ -1,8 +1,11 @@
1
1
  import { datadogRum } from '@datadog/browser-rum';
2
- import { FC, useEffect, useMemo, useRef } from 'react';
3
- import { useLocation } from 'react-router-dom';
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
- function useHashRouting(redirectedViews: string[] = []) {
17
- const pathname = sanitizeViewName(useLocation().pathname);
18
- const isRedirect = useSanitizedViewNames(redirectedViews).has(pathname);
19
- const lastPathname = useRef<string | undefined>(undefined);
20
- const isRedirecting = useRef(false);
21
-
22
- useEffect(() => {
23
- if (lastPathname.current !== pathname) {
24
- /* A redirect's destination takes over the view the redirect started. */
25
- if (isRedirecting.current) {
26
- datadogRum.setViewName(pathname);
27
- } else {
28
- datadogRum.startView(pathname);
29
- }
30
- lastPathname.current = pathname;
31
- isRedirecting.current = isRedirect;
32
- }
33
- }, [isRedirect, pathname]);
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[]) {