@datadog/browser-rum-nextjs 7.16.1 → 7.17.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/cjs/domain/error/addNextjsError.js +1 -2
- package/cjs/domain/error/errorBoundary.js +1 -2
- package/cjs/domain/error/errorBoundary.js.map +1 -1
- package/cjs/domain/nextJSRouter/computeViewNameFromParams.js +1 -2
- package/cjs/domain/nextJSRouter/datadogAppRouter.js +2 -8
- package/cjs/domain/nextJSRouter/datadogAppRouter.js.map +1 -1
- package/cjs/domain/nextJSRouter/datadogPagesRouter.js +1 -2
- package/cjs/domain/nextjsPlugin.d.ts +1 -0
- package/cjs/domain/nextjsPlugin.js +8 -2
- package/cjs/domain/nextjsPlugin.js.map +1 -1
- package/esm/domain/error/addNextjsError.mjs +1 -2
- package/esm/domain/error/errorBoundary.mjs +1 -2
- package/esm/domain/nextJSRouter/computeViewNameFromParams.mjs +1 -2
- package/esm/domain/nextJSRouter/datadogAppRouter.mjs +3 -9
- package/esm/domain/nextJSRouter/datadogAppRouter.mjs.map +1 -1
- package/esm/domain/nextJSRouter/datadogPagesRouter.mjs +1 -2
- package/esm/domain/nextjsPlugin.mjs +8 -3
- package/esm/domain/nextjsPlugin.mjs.map +1 -1
- package/package.json +8 -8
- package/src/domain/nextJSRouter/datadogAppRouter.tsx +2 -7
- package/src/domain/nextjsPlugin.ts +12 -0
|
@@ -2,7 +2,7 @@ const require_nextjsPlugin = require("../nextjsPlugin.js");
|
|
|
2
2
|
let _datadog_browser_core = require("@datadog/browser-core");
|
|
3
3
|
let _datadog_js_core_time = require("@datadog/js-core/time");
|
|
4
4
|
let _datadog_js_core_monitor = require("@datadog/js-core/monitor");
|
|
5
|
-
|
|
5
|
+
// src/domain/error/addNextjsError.ts
|
|
6
6
|
/**
|
|
7
7
|
* Add a Next.js error to the RUM session.
|
|
8
8
|
*
|
|
@@ -41,7 +41,6 @@ function addNextjsError(error, errorInfo) {
|
|
|
41
41
|
});
|
|
42
42
|
});
|
|
43
43
|
}
|
|
44
|
-
//#endregion
|
|
45
44
|
exports.addNextjsError = addNextjsError;
|
|
46
45
|
|
|
47
46
|
//# sourceMappingURL=addNextjsError.js.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
const require_addNextjsError = require("./addNextjsError.js");
|
|
3
|
-
|
|
3
|
+
// src/domain/error/errorBoundary.ts
|
|
4
4
|
/**
|
|
5
5
|
* ErrorBoundary component to report React errors to Datadog using the Next.js error context.
|
|
6
6
|
*
|
|
@@ -17,7 +17,6 @@ const require_addNextjsError = require("./addNextjsError.js");
|
|
|
17
17
|
* ```
|
|
18
18
|
*/
|
|
19
19
|
const ErrorBoundary = (0, require("@datadog/browser-rum-react/internal").createErrorBoundary)(require_addNextjsError.addNextjsError);
|
|
20
|
-
//#endregion
|
|
21
20
|
exports.ErrorBoundary = ErrorBoundary;
|
|
22
21
|
|
|
23
22
|
//# sourceMappingURL=errorBoundary.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errorBoundary.js","names":["createErrorBoundary","addNextjsError"],"sources":["../../../src/domain/error/errorBoundary.ts"],"sourcesContent":["'use client'\nimport { createErrorBoundary } from '@datadog/browser-rum-react/internal'\nexport type { ErrorBoundaryFallback, ErrorBoundaryProps } from '@datadog/browser-rum-react/internal'\nimport { addNextjsError } from './addNextjsError'\n\n/**\n * ErrorBoundary component to report React errors to Datadog using the Next.js error context.\n *\n * For more advanced error handling, you can use the {@link addNextjsError} function.\n *\n * @category Error\n * @example\n * ```ts\n * import { ErrorBoundary } from '@datadog/browser-rum-nextjs'\n *\n * <ErrorBoundary fallback={() => null}>\n * <Component />\n * </ErrorBoundary>\n * ```\n */\n// eslint-disable-next-line local-rules/disallow-side-effects\nexport const ErrorBoundary = createErrorBoundary(addNextjsError)\n"],"mappings":";;;;;;;;;;;;;;;;;;AAqBA,MAAa,iBAAA,
|
|
1
|
+
{"version":3,"file":"errorBoundary.js","names":["createErrorBoundary","addNextjsError"],"sources":["../../../src/domain/error/errorBoundary.ts"],"sourcesContent":["'use client'\nimport { createErrorBoundary } from '@datadog/browser-rum-react/internal'\nexport type { ErrorBoundaryFallback, ErrorBoundaryProps } from '@datadog/browser-rum-react/internal'\nimport { addNextjsError } from './addNextjsError'\n\n/**\n * ErrorBoundary component to report React errors to Datadog using the Next.js error context.\n *\n * For more advanced error handling, you can use the {@link addNextjsError} function.\n *\n * @category Error\n * @example\n * ```ts\n * import { ErrorBoundary } from '@datadog/browser-rum-nextjs'\n *\n * <ErrorBoundary fallback={() => null}>\n * <Component />\n * </ErrorBoundary>\n * ```\n */\n// eslint-disable-next-line local-rules/disallow-side-effects\nexport const ErrorBoundary = createErrorBoundary(addNextjsError)\n"],"mappings":";;;;;;;;;;;;;;;;;;AAqBA,MAAa,iBAAA,G,6CAAgBA,CAAAA,CAAAA,oBAAAA,CAAoBC,uBAAAA,cAAc"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
// src/domain/nextJSRouter/computeViewNameFromParams.ts
|
|
2
2
|
function computeViewNameFromParams(pathname, params) {
|
|
3
3
|
if (Object.keys(params).length === 0) return pathname;
|
|
4
4
|
const segments = pathname.split("/");
|
|
@@ -16,7 +16,6 @@ function computeViewNameFromParams(pathname, params) {
|
|
|
16
16
|
}
|
|
17
17
|
return segments.join("/");
|
|
18
18
|
}
|
|
19
|
-
//#endregion
|
|
20
19
|
exports.computeViewNameFromParams = computeViewNameFromParams;
|
|
21
20
|
|
|
22
21
|
//# sourceMappingURL=computeViewNameFromParams.js.map
|
|
@@ -2,20 +2,14 @@
|
|
|
2
2
|
const require_nextjsPlugin = require("../nextjsPlugin.js");
|
|
3
3
|
const require_computeViewNameFromParams = require("./computeViewNameFromParams.js");
|
|
4
4
|
let _datadog_js_core_util = require("@datadog/js-core/util");
|
|
5
|
-
let react = require("react");
|
|
6
5
|
let next_navigation = require("next/navigation");
|
|
7
|
-
|
|
6
|
+
// src/domain/nextJSRouter/datadogAppRouter.tsx
|
|
8
7
|
function DatadogAppRouter() {
|
|
9
8
|
const pathname = (0, _datadog_js_core_util.mockable)(next_navigation.usePathname)();
|
|
10
9
|
const params = (0, _datadog_js_core_util.mockable)(next_navigation.useParams)();
|
|
11
|
-
|
|
12
|
-
if (previousPathname.current !== pathname) {
|
|
13
|
-
previousPathname.current = pathname;
|
|
14
|
-
require_nextjsPlugin.startNextjsView(require_computeViewNameFromParams.computeViewNameFromParams(pathname, params));
|
|
15
|
-
}
|
|
10
|
+
require_nextjsPlugin.startAppRouterView(pathname, require_computeViewNameFromParams.computeViewNameFromParams(pathname, params));
|
|
16
11
|
return null;
|
|
17
12
|
}
|
|
18
|
-
//#endregion
|
|
19
13
|
exports.DatadogAppRouter = DatadogAppRouter;
|
|
20
14
|
|
|
21
15
|
//# sourceMappingURL=datadogAppRouter.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"datadogAppRouter.js","names":["mockable","usePathname","useParams","
|
|
1
|
+
{"version":3,"file":"datadogAppRouter.js","names":["mockable","usePathname","useParams","computeViewNameFromParams"],"sources":["../../../src/domain/nextJSRouter/datadogAppRouter.tsx"],"sourcesContent":["'use client'\n\nimport { usePathname, useParams } from 'next/navigation'\nimport { mockable } from '@datadog/js-core/util'\nimport { startAppRouterView } from '../nextjsPlugin'\nimport { computeViewNameFromParams } from './computeViewNameFromParams'\n\nexport function DatadogAppRouter() {\n const pathname = mockable(usePathname)()\n const params = mockable(useParams)()\n\n startAppRouterView(pathname, computeViewNameFromParams(pathname, params))\n\n return null\n}\n"],"mappings":";;;;;;AAOA,SAAgB,mBAAmB;CACjC,MAAM,YAAA,GAAWA,sBAAAA,SAAAA,CAASC,gBAAAA,WAAW,CAAC,CAAC;CACvC,MAAM,UAAA,GAASD,sBAAAA,SAAAA,CAASE,gBAAAA,SAAS,CAAC,CAAC;CAEnC,qBAAA,mBAAmB,UAAUC,kCAAAA,0BAA0B,UAAU,MAAM,CAAC;CAExE,OAAO;AACT"}
|
|
@@ -2,7 +2,7 @@ const require_nextjsPlugin = require("../nextjsPlugin.js");
|
|
|
2
2
|
let _datadog_js_core_util = require("@datadog/js-core/util");
|
|
3
3
|
let react = require("react");
|
|
4
4
|
let next_router = require("next/router");
|
|
5
|
-
|
|
5
|
+
// src/domain/nextJSRouter/datadogPagesRouter.tsx
|
|
6
6
|
function DatadogPagesRouter() {
|
|
7
7
|
const router = (0, _datadog_js_core_util.mockable)(next_router.useRouter)();
|
|
8
8
|
const previousPath = (0, _datadog_js_core_util.mockable)(react.useRef)(null);
|
|
@@ -14,7 +14,6 @@ function DatadogPagesRouter() {
|
|
|
14
14
|
}
|
|
15
15
|
return null;
|
|
16
16
|
}
|
|
17
|
-
//#endregion
|
|
18
17
|
exports.DatadogPagesRouter = DatadogPagesRouter;
|
|
19
18
|
|
|
20
19
|
//# sourceMappingURL=datadogPagesRouter.js.map
|
|
@@ -3,6 +3,7 @@ export type NextjsPlugin = Pick<Required<RumPlugin>, 'name' | 'onInit' | 'onRumS
|
|
|
3
3
|
type InitSubscriber = (rumPublicApi: RumPublicApi) => void;
|
|
4
4
|
type StartSubscriber = (addError: StartRumResult['addError']) => void;
|
|
5
5
|
export declare function nextjsPlugin(): NextjsPlugin;
|
|
6
|
+
export declare function startAppRouterView(pathname: string, viewName: string): void;
|
|
6
7
|
export declare function startNextjsView(viewName: string): void;
|
|
7
8
|
export declare function onRouterTransitionStart(url: string): void;
|
|
8
9
|
export declare function onRumInit(callback: InitSubscriber): void;
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
let _datadog_js_core_util = require("@datadog/js-core/util");
|
|
2
2
|
let _datadog_browser_core = require("@datadog/browser-core");
|
|
3
|
-
|
|
3
|
+
// src/domain/nextjsPlugin.ts
|
|
4
4
|
let globalPublicApi;
|
|
5
5
|
let globalAddError;
|
|
6
6
|
let lastNavigationUrl;
|
|
7
|
+
let lastStartedAppRouterPathname;
|
|
7
8
|
let routerType;
|
|
8
9
|
const onRumInitSubscribers = [];
|
|
9
10
|
const onRumStartSubscribers = [];
|
|
@@ -32,6 +33,11 @@ function nextjsPlugin() {
|
|
|
32
33
|
function detectNextjsRouterType() {
|
|
33
34
|
return document.getElementById("__NEXT_DATA__") ? "pages-router" : "app-router";
|
|
34
35
|
}
|
|
36
|
+
function startAppRouterView(pathname, viewName) {
|
|
37
|
+
if (!globalPublicApi || pathname === lastStartedAppRouterPathname) return;
|
|
38
|
+
lastStartedAppRouterPathname = pathname;
|
|
39
|
+
startNextjsView(viewName);
|
|
40
|
+
}
|
|
35
41
|
function startNextjsView(viewName) {
|
|
36
42
|
if (globalPublicApi) {
|
|
37
43
|
const url = lastNavigationUrl ? (0, _datadog_js_core_util.buildUrl)(lastNavigationUrl, window.location.origin).href : void 0;
|
|
@@ -49,10 +55,10 @@ function onRumStart(callback) {
|
|
|
49
55
|
if (globalAddError) callback(globalAddError);
|
|
50
56
|
else onRumStartSubscribers.push(callback);
|
|
51
57
|
}
|
|
52
|
-
//#endregion
|
|
53
58
|
exports.nextjsPlugin = nextjsPlugin;
|
|
54
59
|
exports.onRouterTransitionStart = onRouterTransitionStart;
|
|
55
60
|
exports.onRumStart = onRumStart;
|
|
61
|
+
exports.startAppRouterView = startAppRouterView;
|
|
56
62
|
exports.startNextjsView = startNextjsView;
|
|
57
63
|
|
|
58
64
|
//# sourceMappingURL=nextjsPlugin.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"nextjsPlugin.js","names":["mockable","globalObject","toIntegrations","toMajorVersionIntegration","buildUrl"],"sources":["../../src/domain/nextjsPlugin.ts"],"sourcesContent":["import { buildUrl, globalObject, mockable } from '@datadog/js-core/util'\nimport { toIntegrations, toMajorVersionIntegration } from '@datadog/browser-core'\nimport type { RumPlugin, RumPublicApi, StartRumResult } from '@datadog/browser-rum-core'\n\nexport type NextjsPlugin = Pick<Required<RumPlugin>, 'name' | 'onInit' | 'onRumStart' | 'getConfigurationTelemetry'>\n\ntype NextjsRouterType = 'app-router' | 'pages-router'\ninterface NextjsGlobalObject {\n next?: { version?: string }\n}\ntype InitSubscriber = (rumPublicApi: RumPublicApi) => void\ntype StartSubscriber = (addError: StartRumResult['addError']) => void\n\nlet globalPublicApi: RumPublicApi | undefined\nlet globalAddError: StartRumResult['addError'] | undefined\nlet lastNavigationUrl: string | undefined\nlet routerType: NextjsRouterType | undefined\n\nconst onRumInitSubscribers: InitSubscriber[] = []\nconst onRumStartSubscribers: StartSubscriber[] = []\n\nexport function nextjsPlugin(): NextjsPlugin {\n return {\n name: 'nextjs',\n onInit({ publicApi, initConfiguration }) {\n globalPublicApi = publicApi\n initConfiguration.trackViewsManually = true\n routerType = mockable(detectNextjsRouterType)()\n\n for (const subscriber of onRumInitSubscribers) {\n subscriber(publicApi)\n }\n },\n onRumStart({ addError }) {\n globalAddError = addError\n if (addError) {\n for (const subscriber of onRumStartSubscribers) {\n subscriber(addError)\n }\n }\n },\n getConfigurationTelemetry() {\n const nextjsVersion = (globalObject as NextjsGlobalObject).next?.version\n return {\n router: true,\n integrations: toIntegrations(nextjsVersion && toMajorVersionIntegration('nextjs', nextjsVersion), routerType),\n }\n },\n } satisfies RumPlugin\n}\n\n// The App Router doesn't hydrate from a `__NEXT_DATA__` payload (it streams RSC data instead),\n// so its absence is used as a best-effort signal that the app router is in use.\nfunction detectNextjsRouterType(): NextjsRouterType {\n return document.getElementById('__NEXT_DATA__') ? 'pages-router' : 'app-router'\n}\n\nexport function startNextjsView(viewName: string) {\n if (globalPublicApi) {\n // Use the URL captured by onRouterTransitionStart if available, since React renders before pushState updates window.location\n const url = lastNavigationUrl ? buildUrl(lastNavigationUrl, window.location.origin).href : undefined\n lastNavigationUrl = undefined\n globalPublicApi.startView({ name: viewName, url })\n }\n}\n\n// Must be re-exported from the user's instrumentation-client.ts so we can capture the URL before React renders\nexport function onRouterTransitionStart(url: string) {\n lastNavigationUrl = url\n}\n\nexport function onRumInit(callback: InitSubscriber) {\n if (globalPublicApi) {\n callback(globalPublicApi)\n } else {\n onRumInitSubscribers.push(callback)\n }\n}\n\nexport function onRumStart(callback: StartSubscriber) {\n if (globalAddError) {\n callback(globalAddError)\n } else {\n onRumStartSubscribers.push(callback)\n }\n}\n\nexport function resetNextjsPlugin() {\n globalPublicApi = undefined\n globalAddError = undefined\n onRumInitSubscribers.length = 0\n onRumStartSubscribers.length = 0\n lastNavigationUrl = undefined\n routerType = undefined\n}\n"],"mappings":";;;AAaA,IAAI;AACJ,IAAI;AACJ,IAAI;AACJ,IAAI;AAEJ,MAAM,uBAAyC,CAAC;AAChD,MAAM,wBAA2C,CAAC;AAElD,SAAgB,eAA6B;CAC3C,OAAO;EACL,MAAM;EACN,OAAO,EAAE,WAAW,qBAAqB;GACvC,kBAAkB;GAClB,kBAAkB,qBAAqB;GACvC,cAAA,GAAaA,sBAAAA,SAAAA,CAAS,sBAAsB,CAAC,CAAC;GAE9C,KAAK,MAAM,cAAc,sBACvB,WAAW,SAAS;EAExB;EACA,WAAW,EAAE,YAAY;GACvB,iBAAiB;GACjB,IAAI,UACF,KAAK,MAAM,cAAc,uBACvB,WAAW,QAAQ;EAGzB;EACA,4BAA4B;GAC1B,MAAM,gBAAiBC,sBAAAA,aAAoC,MAAM;GACjE,OAAO;IACL,QAAQ;IACR,eAAA,GAAcC,sBAAAA,eAAAA,CAAe,kBAAA,GAAiBC,sBAAAA,0BAAAA,CAA0B,UAAU,aAAa,GAAG,UAAU;GAC9G;EACF;CACF;AACF;AAIA,SAAS,yBAA2C;CAClD,OAAO,SAAS,eAAe,eAAe,IAAI,iBAAiB;AACrE;AAEA,SAAgB,gBAAgB,UAAkB;CAChD,IAAI,iBAAiB;EAEnB,MAAM,MAAM,qBAAA,GAAoBC,sBAAAA,SAAAA,CAAS,mBAAmB,OAAO,SAAS,MAAM,CAAC,CAAC,OAAO,KAAA;EAC3F,oBAAoB,KAAA;EACpB,gBAAgB,UAAU;GAAE,MAAM;GAAU;EAAI,CAAC;CACnD;AACF;AAGA,SAAgB,wBAAwB,KAAa;CACnD,oBAAoB;AACtB;AAUA,SAAgB,WAAW,UAA2B;CACpD,IAAI,gBACF,SAAS,cAAc;MAEvB,sBAAsB,KAAK,QAAQ;AAEvC"}
|
|
1
|
+
{"version":3,"file":"nextjsPlugin.js","names":["mockable","globalObject","toIntegrations","toMajorVersionIntegration","buildUrl"],"sources":["../../src/domain/nextjsPlugin.ts"],"sourcesContent":["import { buildUrl, globalObject, mockable } from '@datadog/js-core/util'\nimport { toIntegrations, toMajorVersionIntegration } from '@datadog/browser-core'\nimport type { RumPlugin, RumPublicApi, StartRumResult } from '@datadog/browser-rum-core'\n\nexport type NextjsPlugin = Pick<Required<RumPlugin>, 'name' | 'onInit' | 'onRumStart' | 'getConfigurationTelemetry'>\n\ntype NextjsRouterType = 'app-router' | 'pages-router'\ninterface NextjsGlobalObject {\n next?: { version?: string }\n}\ntype InitSubscriber = (rumPublicApi: RumPublicApi) => void\ntype StartSubscriber = (addError: StartRumResult['addError']) => void\n\nlet globalPublicApi: RumPublicApi | undefined\nlet globalAddError: StartRumResult['addError'] | undefined\nlet lastNavigationUrl: string | undefined\nlet lastStartedAppRouterPathname: string | undefined\nlet routerType: NextjsRouterType | undefined\n\nconst onRumInitSubscribers: InitSubscriber[] = []\nconst onRumStartSubscribers: StartSubscriber[] = []\n\nexport function nextjsPlugin(): NextjsPlugin {\n return {\n name: 'nextjs',\n onInit({ publicApi, initConfiguration }) {\n globalPublicApi = publicApi\n initConfiguration.trackViewsManually = true\n routerType = mockable(detectNextjsRouterType)()\n\n for (const subscriber of onRumInitSubscribers) {\n subscriber(publicApi)\n }\n },\n onRumStart({ addError }) {\n globalAddError = addError\n if (addError) {\n for (const subscriber of onRumStartSubscribers) {\n subscriber(addError)\n }\n }\n },\n getConfigurationTelemetry() {\n const nextjsVersion = (globalObject as NextjsGlobalObject).next?.version\n return {\n router: true,\n integrations: toIntegrations(nextjsVersion && toMajorVersionIntegration('nextjs', nextjsVersion), routerType),\n }\n },\n } satisfies RumPlugin\n}\n\n// The App Router doesn't hydrate from a `__NEXT_DATA__` payload (it streams RSC data instead),\n// so its absence is used as a best-effort signal that the app router is in use.\nfunction detectNextjsRouterType(): NextjsRouterType {\n return document.getElementById('__NEXT_DATA__') ? 'pages-router' : 'app-router'\n}\n\nexport function startAppRouterView(pathname: string, viewName: string) {\n if (!globalPublicApi || pathname === lastStartedAppRouterPathname) {\n return\n }\n\n // Keep the guard outside React so discarded mount renders do not reset it.\n lastStartedAppRouterPathname = pathname\n startNextjsView(viewName)\n}\n\nexport function startNextjsView(viewName: string) {\n if (globalPublicApi) {\n // Use the URL captured by onRouterTransitionStart if available, since React renders before pushState updates window.location\n const url = lastNavigationUrl ? buildUrl(lastNavigationUrl, window.location.origin).href : undefined\n lastNavigationUrl = undefined\n globalPublicApi.startView({ name: viewName, url })\n }\n}\n\n// Must be re-exported from the user's instrumentation-client.ts so we can capture the URL before React renders\nexport function onRouterTransitionStart(url: string) {\n lastNavigationUrl = url\n}\n\nexport function onRumInit(callback: InitSubscriber) {\n if (globalPublicApi) {\n callback(globalPublicApi)\n } else {\n onRumInitSubscribers.push(callback)\n }\n}\n\nexport function onRumStart(callback: StartSubscriber) {\n if (globalAddError) {\n callback(globalAddError)\n } else {\n onRumStartSubscribers.push(callback)\n }\n}\n\nexport function resetNextjsPlugin() {\n globalPublicApi = undefined\n globalAddError = undefined\n onRumInitSubscribers.length = 0\n onRumStartSubscribers.length = 0\n lastNavigationUrl = undefined\n lastStartedAppRouterPathname = undefined\n routerType = undefined\n}\n"],"mappings":";;;AAaA,IAAI;AACJ,IAAI;AACJ,IAAI;AACJ,IAAI;AACJ,IAAI;AAEJ,MAAM,uBAAyC,CAAC;AAChD,MAAM,wBAA2C,CAAC;AAElD,SAAgB,eAA6B;CAC3C,OAAO;EACL,MAAM;EACN,OAAO,EAAE,WAAW,qBAAqB;GACvC,kBAAkB;GAClB,kBAAkB,qBAAqB;GACvC,cAAA,GAAaA,sBAAAA,SAAAA,CAAS,sBAAsB,CAAC,CAAC;GAE9C,KAAK,MAAM,cAAc,sBACvB,WAAW,SAAS;EAExB;EACA,WAAW,EAAE,YAAY;GACvB,iBAAiB;GACjB,IAAI,UACF,KAAK,MAAM,cAAc,uBACvB,WAAW,QAAQ;EAGzB;EACA,4BAA4B;GAC1B,MAAM,gBAAiBC,sBAAAA,aAAoC,MAAM;GACjE,OAAO;IACL,QAAQ;IACR,eAAA,GAAcC,sBAAAA,eAAAA,CAAe,kBAAA,GAAiBC,sBAAAA,0BAAAA,CAA0B,UAAU,aAAa,GAAG,UAAU;GAC9G;EACF;CACF;AACF;AAIA,SAAS,yBAA2C;CAClD,OAAO,SAAS,eAAe,eAAe,IAAI,iBAAiB;AACrE;AAEA,SAAgB,mBAAmB,UAAkB,UAAkB;CACrE,IAAI,CAAC,mBAAmB,aAAa,8BACnC;CAIF,+BAA+B;CAC/B,gBAAgB,QAAQ;AAC1B;AAEA,SAAgB,gBAAgB,UAAkB;CAChD,IAAI,iBAAiB;EAEnB,MAAM,MAAM,qBAAA,GAAoBC,sBAAAA,SAAAA,CAAS,mBAAmB,OAAO,SAAS,MAAM,CAAC,CAAC,OAAO,KAAA;EAC3F,oBAAoB,KAAA;EACpB,gBAAgB,UAAU;GAAE,MAAM;GAAU;EAAI,CAAC;CACnD;AACF;AAGA,SAAgB,wBAAwB,KAAa;CACnD,oBAAoB;AACtB;AAUA,SAAgB,WAAW,UAA2B;CACpD,IAAI,gBACF,SAAS,cAAc;MAEvB,sBAAsB,KAAK,QAAQ;AAEvC"}
|
|
@@ -2,7 +2,7 @@ import { onRumStart } from "../nextjsPlugin.mjs";
|
|
|
2
2
|
import { createHandlingStack } from "@datadog/browser-core";
|
|
3
3
|
import { clocksNow } from "@datadog/js-core/time";
|
|
4
4
|
import { callMonitored } from "@datadog/js-core/monitor";
|
|
5
|
-
|
|
5
|
+
// src/domain/error/addNextjsError.ts
|
|
6
6
|
/**
|
|
7
7
|
* Add a Next.js error to the RUM session.
|
|
8
8
|
*
|
|
@@ -41,7 +41,6 @@ function addNextjsError(error, errorInfo) {
|
|
|
41
41
|
});
|
|
42
42
|
});
|
|
43
43
|
}
|
|
44
|
-
//#endregion
|
|
45
44
|
export { addNextjsError };
|
|
46
45
|
|
|
47
46
|
//# sourceMappingURL=addNextjsError.mjs.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { addNextjsError } from "./addNextjsError.mjs";
|
|
3
3
|
import { createErrorBoundary } from "@datadog/browser-rum-react/internal";
|
|
4
|
-
|
|
4
|
+
// src/domain/error/errorBoundary.ts
|
|
5
5
|
/**
|
|
6
6
|
* ErrorBoundary component to report React errors to Datadog using the Next.js error context.
|
|
7
7
|
*
|
|
@@ -18,7 +18,6 @@ import { createErrorBoundary } from "@datadog/browser-rum-react/internal";
|
|
|
18
18
|
* ```
|
|
19
19
|
*/
|
|
20
20
|
const ErrorBoundary = createErrorBoundary(addNextjsError);
|
|
21
|
-
//#endregion
|
|
22
21
|
export { ErrorBoundary };
|
|
23
22
|
|
|
24
23
|
//# sourceMappingURL=errorBoundary.mjs.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
// src/domain/nextJSRouter/computeViewNameFromParams.ts
|
|
2
2
|
function computeViewNameFromParams(pathname, params) {
|
|
3
3
|
if (Object.keys(params).length === 0) return pathname;
|
|
4
4
|
const segments = pathname.split("/");
|
|
@@ -16,7 +16,6 @@ function computeViewNameFromParams(pathname, params) {
|
|
|
16
16
|
}
|
|
17
17
|
return segments.join("/");
|
|
18
18
|
}
|
|
19
|
-
//#endregion
|
|
20
19
|
export { computeViewNameFromParams };
|
|
21
20
|
|
|
22
21
|
//# sourceMappingURL=computeViewNameFromParams.mjs.map
|
|
@@ -1,21 +1,15 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import {
|
|
2
|
+
import { startAppRouterView } from "../nextjsPlugin.mjs";
|
|
3
3
|
import { computeViewNameFromParams } from "./computeViewNameFromParams.mjs";
|
|
4
4
|
import { mockable } from "@datadog/js-core/util";
|
|
5
|
-
import { useRef } from "react";
|
|
6
5
|
import { useParams, usePathname } from "next/navigation";
|
|
7
|
-
|
|
6
|
+
// src/domain/nextJSRouter/datadogAppRouter.tsx
|
|
8
7
|
function DatadogAppRouter() {
|
|
9
8
|
const pathname = mockable(usePathname)();
|
|
10
9
|
const params = mockable(useParams)();
|
|
11
|
-
|
|
12
|
-
if (previousPathname.current !== pathname) {
|
|
13
|
-
previousPathname.current = pathname;
|
|
14
|
-
startNextjsView(computeViewNameFromParams(pathname, params));
|
|
15
|
-
}
|
|
10
|
+
startAppRouterView(pathname, computeViewNameFromParams(pathname, params));
|
|
16
11
|
return null;
|
|
17
12
|
}
|
|
18
|
-
//#endregion
|
|
19
13
|
export { DatadogAppRouter };
|
|
20
14
|
|
|
21
15
|
//# sourceMappingURL=datadogAppRouter.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"datadogAppRouter.mjs","names":[],"sources":["../../../src/domain/nextJSRouter/datadogAppRouter.tsx"],"sourcesContent":["'use client'\n\nimport {
|
|
1
|
+
{"version":3,"file":"datadogAppRouter.mjs","names":[],"sources":["../../../src/domain/nextJSRouter/datadogAppRouter.tsx"],"sourcesContent":["'use client'\n\nimport { usePathname, useParams } from 'next/navigation'\nimport { mockable } from '@datadog/js-core/util'\nimport { startAppRouterView } from '../nextjsPlugin'\nimport { computeViewNameFromParams } from './computeViewNameFromParams'\n\nexport function DatadogAppRouter() {\n const pathname = mockable(usePathname)()\n const params = mockable(useParams)()\n\n startAppRouterView(pathname, computeViewNameFromParams(pathname, params))\n\n return null\n}\n"],"mappings":";;;;;;AAOA,SAAgB,mBAAmB;CACjC,MAAM,WAAW,SAAS,WAAW,CAAC,CAAC;CACvC,MAAM,SAAS,SAAS,SAAS,CAAC,CAAC;CAEnC,mBAAmB,UAAU,0BAA0B,UAAU,MAAM,CAAC;CAExE,OAAO;AACT"}
|
|
@@ -2,7 +2,7 @@ import { startNextjsView } from "../nextjsPlugin.mjs";
|
|
|
2
2
|
import { mockable } from "@datadog/js-core/util";
|
|
3
3
|
import { useRef } from "react";
|
|
4
4
|
import { useRouter } from "next/router";
|
|
5
|
-
|
|
5
|
+
// src/domain/nextJSRouter/datadogPagesRouter.tsx
|
|
6
6
|
function DatadogPagesRouter() {
|
|
7
7
|
const router = mockable(useRouter)();
|
|
8
8
|
const previousPath = mockable(useRef)(null);
|
|
@@ -14,7 +14,6 @@ function DatadogPagesRouter() {
|
|
|
14
14
|
}
|
|
15
15
|
return null;
|
|
16
16
|
}
|
|
17
|
-
//#endregion
|
|
18
17
|
export { DatadogPagesRouter };
|
|
19
18
|
|
|
20
19
|
//# sourceMappingURL=datadogPagesRouter.mjs.map
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { buildUrl, globalObject, mockable } from "@datadog/js-core/util";
|
|
2
2
|
import { toIntegrations, toMajorVersionIntegration } from "@datadog/browser-core";
|
|
3
|
-
|
|
3
|
+
// src/domain/nextjsPlugin.ts
|
|
4
4
|
let globalPublicApi;
|
|
5
5
|
let globalAddError;
|
|
6
6
|
let lastNavigationUrl;
|
|
7
|
+
let lastStartedAppRouterPathname;
|
|
7
8
|
let routerType;
|
|
8
9
|
const onRumInitSubscribers = [];
|
|
9
10
|
const onRumStartSubscribers = [];
|
|
@@ -32,6 +33,11 @@ function nextjsPlugin() {
|
|
|
32
33
|
function detectNextjsRouterType() {
|
|
33
34
|
return document.getElementById("__NEXT_DATA__") ? "pages-router" : "app-router";
|
|
34
35
|
}
|
|
36
|
+
function startAppRouterView(pathname, viewName) {
|
|
37
|
+
if (!globalPublicApi || pathname === lastStartedAppRouterPathname) return;
|
|
38
|
+
lastStartedAppRouterPathname = pathname;
|
|
39
|
+
startNextjsView(viewName);
|
|
40
|
+
}
|
|
35
41
|
function startNextjsView(viewName) {
|
|
36
42
|
if (globalPublicApi) {
|
|
37
43
|
const url = lastNavigationUrl ? buildUrl(lastNavigationUrl, window.location.origin).href : void 0;
|
|
@@ -49,7 +55,6 @@ function onRumStart(callback) {
|
|
|
49
55
|
if (globalAddError) callback(globalAddError);
|
|
50
56
|
else onRumStartSubscribers.push(callback);
|
|
51
57
|
}
|
|
52
|
-
|
|
53
|
-
export { nextjsPlugin, onRouterTransitionStart, onRumStart, startNextjsView };
|
|
58
|
+
export { nextjsPlugin, onRouterTransitionStart, onRumStart, startAppRouterView, startNextjsView };
|
|
54
59
|
|
|
55
60
|
//# sourceMappingURL=nextjsPlugin.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"nextjsPlugin.mjs","names":[],"sources":["../../src/domain/nextjsPlugin.ts"],"sourcesContent":["import { buildUrl, globalObject, mockable } from '@datadog/js-core/util'\nimport { toIntegrations, toMajorVersionIntegration } from '@datadog/browser-core'\nimport type { RumPlugin, RumPublicApi, StartRumResult } from '@datadog/browser-rum-core'\n\nexport type NextjsPlugin = Pick<Required<RumPlugin>, 'name' | 'onInit' | 'onRumStart' | 'getConfigurationTelemetry'>\n\ntype NextjsRouterType = 'app-router' | 'pages-router'\ninterface NextjsGlobalObject {\n next?: { version?: string }\n}\ntype InitSubscriber = (rumPublicApi: RumPublicApi) => void\ntype StartSubscriber = (addError: StartRumResult['addError']) => void\n\nlet globalPublicApi: RumPublicApi | undefined\nlet globalAddError: StartRumResult['addError'] | undefined\nlet lastNavigationUrl: string | undefined\nlet routerType: NextjsRouterType | undefined\n\nconst onRumInitSubscribers: InitSubscriber[] = []\nconst onRumStartSubscribers: StartSubscriber[] = []\n\nexport function nextjsPlugin(): NextjsPlugin {\n return {\n name: 'nextjs',\n onInit({ publicApi, initConfiguration }) {\n globalPublicApi = publicApi\n initConfiguration.trackViewsManually = true\n routerType = mockable(detectNextjsRouterType)()\n\n for (const subscriber of onRumInitSubscribers) {\n subscriber(publicApi)\n }\n },\n onRumStart({ addError }) {\n globalAddError = addError\n if (addError) {\n for (const subscriber of onRumStartSubscribers) {\n subscriber(addError)\n }\n }\n },\n getConfigurationTelemetry() {\n const nextjsVersion = (globalObject as NextjsGlobalObject).next?.version\n return {\n router: true,\n integrations: toIntegrations(nextjsVersion && toMajorVersionIntegration('nextjs', nextjsVersion), routerType),\n }\n },\n } satisfies RumPlugin\n}\n\n// The App Router doesn't hydrate from a `__NEXT_DATA__` payload (it streams RSC data instead),\n// so its absence is used as a best-effort signal that the app router is in use.\nfunction detectNextjsRouterType(): NextjsRouterType {\n return document.getElementById('__NEXT_DATA__') ? 'pages-router' : 'app-router'\n}\n\nexport function startNextjsView(viewName: string) {\n if (globalPublicApi) {\n // Use the URL captured by onRouterTransitionStart if available, since React renders before pushState updates window.location\n const url = lastNavigationUrl ? buildUrl(lastNavigationUrl, window.location.origin).href : undefined\n lastNavigationUrl = undefined\n globalPublicApi.startView({ name: viewName, url })\n }\n}\n\n// Must be re-exported from the user's instrumentation-client.ts so we can capture the URL before React renders\nexport function onRouterTransitionStart(url: string) {\n lastNavigationUrl = url\n}\n\nexport function onRumInit(callback: InitSubscriber) {\n if (globalPublicApi) {\n callback(globalPublicApi)\n } else {\n onRumInitSubscribers.push(callback)\n }\n}\n\nexport function onRumStart(callback: StartSubscriber) {\n if (globalAddError) {\n callback(globalAddError)\n } else {\n onRumStartSubscribers.push(callback)\n }\n}\n\nexport function resetNextjsPlugin() {\n globalPublicApi = undefined\n globalAddError = undefined\n onRumInitSubscribers.length = 0\n onRumStartSubscribers.length = 0\n lastNavigationUrl = undefined\n routerType = undefined\n}\n"],"mappings":";;;AAaA,IAAI;AACJ,IAAI;AACJ,IAAI;AACJ,IAAI;AAEJ,MAAM,uBAAyC,CAAC;AAChD,MAAM,wBAA2C,CAAC;AAElD,SAAgB,eAA6B;CAC3C,OAAO;EACL,MAAM;EACN,OAAO,EAAE,WAAW,qBAAqB;GACvC,kBAAkB;GAClB,kBAAkB,qBAAqB;GACvC,aAAa,SAAS,sBAAsB,CAAC,CAAC;GAE9C,KAAK,MAAM,cAAc,sBACvB,WAAW,SAAS;EAExB;EACA,WAAW,EAAE,YAAY;GACvB,iBAAiB;GACjB,IAAI,UACF,KAAK,MAAM,cAAc,uBACvB,WAAW,QAAQ;EAGzB;EACA,4BAA4B;GAC1B,MAAM,gBAAiB,aAAoC,MAAM;GACjE,OAAO;IACL,QAAQ;IACR,cAAc,eAAe,iBAAiB,0BAA0B,UAAU,aAAa,GAAG,UAAU;GAC9G;EACF;CACF;AACF;AAIA,SAAS,yBAA2C;CAClD,OAAO,SAAS,eAAe,eAAe,IAAI,iBAAiB;AACrE;AAEA,SAAgB,gBAAgB,UAAkB;CAChD,IAAI,iBAAiB;EAEnB,MAAM,MAAM,oBAAoB,SAAS,mBAAmB,OAAO,SAAS,MAAM,CAAC,CAAC,OAAO,KAAA;EAC3F,oBAAoB,KAAA;EACpB,gBAAgB,UAAU;GAAE,MAAM;GAAU;EAAI,CAAC;CACnD;AACF;AAGA,SAAgB,wBAAwB,KAAa;CACnD,oBAAoB;AACtB;AAUA,SAAgB,WAAW,UAA2B;CACpD,IAAI,gBACF,SAAS,cAAc;MAEvB,sBAAsB,KAAK,QAAQ;AAEvC"}
|
|
1
|
+
{"version":3,"file":"nextjsPlugin.mjs","names":[],"sources":["../../src/domain/nextjsPlugin.ts"],"sourcesContent":["import { buildUrl, globalObject, mockable } from '@datadog/js-core/util'\nimport { toIntegrations, toMajorVersionIntegration } from '@datadog/browser-core'\nimport type { RumPlugin, RumPublicApi, StartRumResult } from '@datadog/browser-rum-core'\n\nexport type NextjsPlugin = Pick<Required<RumPlugin>, 'name' | 'onInit' | 'onRumStart' | 'getConfigurationTelemetry'>\n\ntype NextjsRouterType = 'app-router' | 'pages-router'\ninterface NextjsGlobalObject {\n next?: { version?: string }\n}\ntype InitSubscriber = (rumPublicApi: RumPublicApi) => void\ntype StartSubscriber = (addError: StartRumResult['addError']) => void\n\nlet globalPublicApi: RumPublicApi | undefined\nlet globalAddError: StartRumResult['addError'] | undefined\nlet lastNavigationUrl: string | undefined\nlet lastStartedAppRouterPathname: string | undefined\nlet routerType: NextjsRouterType | undefined\n\nconst onRumInitSubscribers: InitSubscriber[] = []\nconst onRumStartSubscribers: StartSubscriber[] = []\n\nexport function nextjsPlugin(): NextjsPlugin {\n return {\n name: 'nextjs',\n onInit({ publicApi, initConfiguration }) {\n globalPublicApi = publicApi\n initConfiguration.trackViewsManually = true\n routerType = mockable(detectNextjsRouterType)()\n\n for (const subscriber of onRumInitSubscribers) {\n subscriber(publicApi)\n }\n },\n onRumStart({ addError }) {\n globalAddError = addError\n if (addError) {\n for (const subscriber of onRumStartSubscribers) {\n subscriber(addError)\n }\n }\n },\n getConfigurationTelemetry() {\n const nextjsVersion = (globalObject as NextjsGlobalObject).next?.version\n return {\n router: true,\n integrations: toIntegrations(nextjsVersion && toMajorVersionIntegration('nextjs', nextjsVersion), routerType),\n }\n },\n } satisfies RumPlugin\n}\n\n// The App Router doesn't hydrate from a `__NEXT_DATA__` payload (it streams RSC data instead),\n// so its absence is used as a best-effort signal that the app router is in use.\nfunction detectNextjsRouterType(): NextjsRouterType {\n return document.getElementById('__NEXT_DATA__') ? 'pages-router' : 'app-router'\n}\n\nexport function startAppRouterView(pathname: string, viewName: string) {\n if (!globalPublicApi || pathname === lastStartedAppRouterPathname) {\n return\n }\n\n // Keep the guard outside React so discarded mount renders do not reset it.\n lastStartedAppRouterPathname = pathname\n startNextjsView(viewName)\n}\n\nexport function startNextjsView(viewName: string) {\n if (globalPublicApi) {\n // Use the URL captured by onRouterTransitionStart if available, since React renders before pushState updates window.location\n const url = lastNavigationUrl ? buildUrl(lastNavigationUrl, window.location.origin).href : undefined\n lastNavigationUrl = undefined\n globalPublicApi.startView({ name: viewName, url })\n }\n}\n\n// Must be re-exported from the user's instrumentation-client.ts so we can capture the URL before React renders\nexport function onRouterTransitionStart(url: string) {\n lastNavigationUrl = url\n}\n\nexport function onRumInit(callback: InitSubscriber) {\n if (globalPublicApi) {\n callback(globalPublicApi)\n } else {\n onRumInitSubscribers.push(callback)\n }\n}\n\nexport function onRumStart(callback: StartSubscriber) {\n if (globalAddError) {\n callback(globalAddError)\n } else {\n onRumStartSubscribers.push(callback)\n }\n}\n\nexport function resetNextjsPlugin() {\n globalPublicApi = undefined\n globalAddError = undefined\n onRumInitSubscribers.length = 0\n onRumStartSubscribers.length = 0\n lastNavigationUrl = undefined\n lastStartedAppRouterPathname = undefined\n routerType = undefined\n}\n"],"mappings":";;;AAaA,IAAI;AACJ,IAAI;AACJ,IAAI;AACJ,IAAI;AACJ,IAAI;AAEJ,MAAM,uBAAyC,CAAC;AAChD,MAAM,wBAA2C,CAAC;AAElD,SAAgB,eAA6B;CAC3C,OAAO;EACL,MAAM;EACN,OAAO,EAAE,WAAW,qBAAqB;GACvC,kBAAkB;GAClB,kBAAkB,qBAAqB;GACvC,aAAa,SAAS,sBAAsB,CAAC,CAAC;GAE9C,KAAK,MAAM,cAAc,sBACvB,WAAW,SAAS;EAExB;EACA,WAAW,EAAE,YAAY;GACvB,iBAAiB;GACjB,IAAI,UACF,KAAK,MAAM,cAAc,uBACvB,WAAW,QAAQ;EAGzB;EACA,4BAA4B;GAC1B,MAAM,gBAAiB,aAAoC,MAAM;GACjE,OAAO;IACL,QAAQ;IACR,cAAc,eAAe,iBAAiB,0BAA0B,UAAU,aAAa,GAAG,UAAU;GAC9G;EACF;CACF;AACF;AAIA,SAAS,yBAA2C;CAClD,OAAO,SAAS,eAAe,eAAe,IAAI,iBAAiB;AACrE;AAEA,SAAgB,mBAAmB,UAAkB,UAAkB;CACrE,IAAI,CAAC,mBAAmB,aAAa,8BACnC;CAIF,+BAA+B;CAC/B,gBAAgB,QAAQ;AAC1B;AAEA,SAAgB,gBAAgB,UAAkB;CAChD,IAAI,iBAAiB;EAEnB,MAAM,MAAM,oBAAoB,SAAS,mBAAmB,OAAO,SAAS,MAAM,CAAC,CAAC,OAAO,KAAA;EAC3F,oBAAoB,KAAA;EACpB,gBAAgB,UAAU;GAAE,MAAM;GAAU;EAAI,CAAC;CACnD;AACF;AAGA,SAAgB,wBAAwB,KAAa;CACnD,oBAAoB;AACtB;AAUA,SAAgB,WAAW,UAA2B;CACpD,IAAI,gBACF,SAAS,cAAc;MAEvB,sBAAsB,KAAK,QAAQ;AAEvC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@datadog/browser-rum-nextjs",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.17.0",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"main": "cjs/entries/main.js",
|
|
6
6
|
"module": "esm/entries/main.mjs",
|
|
@@ -17,10 +17,10 @@
|
|
|
17
17
|
"prepack": "yarn build"
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"@datadog/browser-core": "7.
|
|
21
|
-
"@datadog/browser-rum-core": "7.
|
|
22
|
-
"@datadog/browser-rum-react": "7.
|
|
23
|
-
"@datadog/js-core": "0.0.
|
|
20
|
+
"@datadog/browser-core": "7.17.0",
|
|
21
|
+
"@datadog/browser-rum-core": "7.17.0",
|
|
22
|
+
"@datadog/browser-rum-react": "7.17.0",
|
|
23
|
+
"@datadog/js-core": "0.0.20"
|
|
24
24
|
},
|
|
25
25
|
"peerDependencies": {
|
|
26
26
|
"next": ">=13.0.0",
|
|
@@ -44,8 +44,8 @@
|
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
46
|
"@types/react": "19.3.0",
|
|
47
|
-
"next": "16.3
|
|
48
|
-
"react": "19.3.
|
|
49
|
-
"react-dom": "19.3.
|
|
47
|
+
"next": "16.4.3",
|
|
48
|
+
"react": "19.3.1",
|
|
49
|
+
"react-dom": "19.3.1"
|
|
50
50
|
}
|
|
51
51
|
}
|
|
@@ -1,20 +1,15 @@
|
|
|
1
1
|
'use client'
|
|
2
2
|
|
|
3
|
-
import { useRef } from 'react'
|
|
4
3
|
import { usePathname, useParams } from 'next/navigation'
|
|
5
4
|
import { mockable } from '@datadog/js-core/util'
|
|
6
|
-
import {
|
|
5
|
+
import { startAppRouterView } from '../nextjsPlugin'
|
|
7
6
|
import { computeViewNameFromParams } from './computeViewNameFromParams'
|
|
8
7
|
|
|
9
8
|
export function DatadogAppRouter() {
|
|
10
9
|
const pathname = mockable(usePathname)()
|
|
11
10
|
const params = mockable(useParams)()
|
|
12
|
-
const previousPathname = mockable(useRef)<string | null>(null)
|
|
13
11
|
|
|
14
|
-
|
|
15
|
-
previousPathname.current = pathname
|
|
16
|
-
startNextjsView(computeViewNameFromParams(pathname, params))
|
|
17
|
-
}
|
|
12
|
+
startAppRouterView(pathname, computeViewNameFromParams(pathname, params))
|
|
18
13
|
|
|
19
14
|
return null
|
|
20
15
|
}
|
|
@@ -14,6 +14,7 @@ type StartSubscriber = (addError: StartRumResult['addError']) => void
|
|
|
14
14
|
let globalPublicApi: RumPublicApi | undefined
|
|
15
15
|
let globalAddError: StartRumResult['addError'] | undefined
|
|
16
16
|
let lastNavigationUrl: string | undefined
|
|
17
|
+
let lastStartedAppRouterPathname: string | undefined
|
|
17
18
|
let routerType: NextjsRouterType | undefined
|
|
18
19
|
|
|
19
20
|
const onRumInitSubscribers: InitSubscriber[] = []
|
|
@@ -55,6 +56,16 @@ function detectNextjsRouterType(): NextjsRouterType {
|
|
|
55
56
|
return document.getElementById('__NEXT_DATA__') ? 'pages-router' : 'app-router'
|
|
56
57
|
}
|
|
57
58
|
|
|
59
|
+
export function startAppRouterView(pathname: string, viewName: string) {
|
|
60
|
+
if (!globalPublicApi || pathname === lastStartedAppRouterPathname) {
|
|
61
|
+
return
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// Keep the guard outside React so discarded mount renders do not reset it.
|
|
65
|
+
lastStartedAppRouterPathname = pathname
|
|
66
|
+
startNextjsView(viewName)
|
|
67
|
+
}
|
|
68
|
+
|
|
58
69
|
export function startNextjsView(viewName: string) {
|
|
59
70
|
if (globalPublicApi) {
|
|
60
71
|
// Use the URL captured by onRouterTransitionStart if available, since React renders before pushState updates window.location
|
|
@@ -91,5 +102,6 @@ export function resetNextjsPlugin() {
|
|
|
91
102
|
onRumInitSubscribers.length = 0
|
|
92
103
|
onRumStartSubscribers.length = 0
|
|
93
104
|
lastNavigationUrl = undefined
|
|
105
|
+
lastStartedAppRouterPathname = undefined
|
|
94
106
|
routerType = undefined
|
|
95
107
|
}
|