@trackunit/react-core-contexts-test 1.18.16 → 1.18.18

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,9 +1,10 @@
1
1
  'use strict';
2
2
 
3
3
  var index = require('./index2.cjs.js');
4
- require('@trackunit/iris-app-runtime-core-api');
5
4
  require('react/jsx-runtime');
6
5
  require('react');
6
+ require('@trackunit/shared-utils');
7
+ require('@trackunit/iris-app-runtime-core-api');
7
8
  require('react-dom/test-utils');
8
9
  require('react-dom');
9
10
  require('react-dom/client');
@@ -13,7 +14,6 @@ require('@apollo/client');
13
14
  require('@apollo/client/dev');
14
15
  require('@apollo/client/link/error');
15
16
  require('@apollo/client/testing');
16
- require('@trackunit/shared-utils');
17
17
  require('@apollo/client/react');
18
18
  require('@tanstack/react-router');
19
19
  require('graphql');
@@ -1,7 +1,8 @@
1
1
  import { a as act, r as renderHook, f as flushPromises, b as flushPromisesInAct } from './index2.esm.js';
2
- import '@trackunit/iris-app-runtime-core-api';
3
2
  import 'react/jsx-runtime';
4
3
  import 'react';
4
+ import '@trackunit/shared-utils';
5
+ import '@trackunit/iris-app-runtime-core-api';
5
6
  import 'react-dom/test-utils';
6
7
  import 'react-dom';
7
8
  import 'react-dom/client';
@@ -11,7 +12,6 @@ import '@apollo/client';
11
12
  import '@apollo/client/dev';
12
13
  import '@apollo/client/link/error';
13
14
  import '@apollo/client/testing';
14
- import '@trackunit/shared-utils';
15
15
  import '@apollo/client/react';
16
16
  import '@tanstack/react-router';
17
17
  import 'graphql';
package/index.cjs.js CHANGED
@@ -1,9 +1,10 @@
1
1
  'use strict';
2
2
 
3
3
  var index = require('./index2.cjs.js');
4
- require('@trackunit/iris-app-runtime-core-api');
5
4
  require('react/jsx-runtime');
6
5
  require('react');
6
+ require('@trackunit/shared-utils');
7
+ require('@trackunit/iris-app-runtime-core-api');
7
8
  require('react-dom/test-utils');
8
9
  require('react-dom');
9
10
  require('react-dom/client');
@@ -13,7 +14,6 @@ require('@apollo/client');
13
14
  require('@apollo/client/dev');
14
15
  require('@apollo/client/link/error');
15
16
  require('@apollo/client/testing');
16
- require('@trackunit/shared-utils');
17
17
  require('@apollo/client/react');
18
18
  require('@tanstack/react-router');
19
19
  require('graphql');
package/index.esm.js CHANGED
@@ -1,7 +1,8 @@
1
1
  export { D as Debugger, T as TrackunitProvidersMockBuilder, d as doNothing, f as flushPromises, b as flushPromisesInAct, m as mergeDeepVars, c as mockAnalyticsContext, e as mockAssetSortingContext, g as mockCurrentUserContext, h as mockEnvironmentContext, i as mockFeatureFlagContext, j as mockFilterBarContext, k as mockNavigationContext, l as mockOemBrandingContext, n as mockToastContext, o as mockUserSubscriptionContext, q as queryFor, p as queryForHook, t as trackunitProviders, u as useDebugger, v as validateIrisApp } from './index2.esm.js';
2
- import '@trackunit/iris-app-runtime-core-api';
3
2
  import 'react/jsx-runtime';
4
3
  import 'react';
4
+ import '@trackunit/shared-utils';
5
+ import '@trackunit/iris-app-runtime-core-api';
5
6
  import 'react-dom/test-utils';
6
7
  import 'react-dom';
7
8
  import 'react-dom/client';
@@ -11,7 +12,6 @@ import '@apollo/client';
11
12
  import '@apollo/client/dev';
12
13
  import '@apollo/client/link/error';
13
14
  import '@apollo/client/testing';
14
- import '@trackunit/shared-utils';
15
15
  import '@apollo/client/react';
16
16
  import '@tanstack/react-router';
17
17
  import 'graphql';
package/index2.cjs.js CHANGED
@@ -1,8 +1,9 @@
1
1
  'use strict';
2
2
 
3
- var irisAppRuntimeCoreApi = require('@trackunit/iris-app-runtime-core-api');
4
3
  var jsxRuntime = require('react/jsx-runtime');
5
4
  var React = require('react');
5
+ var sharedUtils = require('@trackunit/shared-utils');
6
+ var irisAppRuntimeCoreApi = require('@trackunit/iris-app-runtime-core-api');
6
7
  var DeprecatedReactTestUtils = require('react-dom/test-utils');
7
8
  var ReactDOM = require('react-dom');
8
9
  var ReactDOMClient = require('react-dom/client');
@@ -12,7 +13,6 @@ var client = require('@apollo/client');
12
13
  var dev = require('@apollo/client/dev');
13
14
  var error = require('@apollo/client/link/error');
14
15
  var testing = require('@apollo/client/testing');
15
- var sharedUtils = require('@trackunit/shared-utils');
16
16
  var react = require('@apollo/client/react');
17
17
  var reactRouter = require('@tanstack/react-router');
18
18
  var graphql = require('graphql');
@@ -38,6 +38,143 @@ var React__namespace = /*#__PURE__*/_interopNamespaceDefault(React);
38
38
  var DeprecatedReactTestUtils__namespace = /*#__PURE__*/_interopNamespaceDefault(DeprecatedReactTestUtils);
39
39
  var ReactDOMClient__namespace = /*#__PURE__*/_interopNamespaceDefault(ReactDOMClient);
40
40
 
41
+ /**
42
+ * Differentiate between the first and subsequent renders.
43
+ *
44
+ * @returns {boolean} Returns true if it is the first render, false otherwise.
45
+ */
46
+ const useIsFirstRender = () => {
47
+ const [isFirstRender, setIsFirstRender] = React.useState(true);
48
+ React.useEffect(() => {
49
+ setIsFirstRender(false);
50
+ }, []);
51
+ return isFirstRender;
52
+ };
53
+
54
+ /**
55
+ * Logs props that have changed.
56
+ * Use this for debugging which props force a component to re-render.
57
+ * This is a hook version of the class component lifecycle method `componentDidUpdate`.
58
+ * ALWAYS wrap in your own object.
59
+ *
60
+ * @param propsToWatch all the props to watch for changes
61
+ * @param id optional id to use for logging or it will guess the id from the stack trace
62
+ * @param dontLogReRender if true, will not log the re-render message nice if you have a lot of re-renders
63
+ * @example
64
+ * const propsToWatch = { foo: props.foo, bar: props.bar };
65
+ * useDebugger(propsToWatch);
66
+ */
67
+ const useDebugger = (propsToWatch, id, dontLogReRender) => {
68
+ const prevPropsRef = React.useRef(propsToWatch);
69
+ const uniqueId = React.useMemo(() => {
70
+ let stackId = id || (propsToWatch && propsToWatch.id);
71
+ const stack = new Error().stack;
72
+ if (!stackId && stack) {
73
+ const stackLines = stack.split("\n");
74
+ for (let i = 0; i < stackLines.length; i++) {
75
+ const stackLine = stackLines[i];
76
+ if (stackLine?.includes("useDebugger")) {
77
+ stackId = stackLines[i + 1]?.trim().split(" ")[1];
78
+ break;
79
+ }
80
+ }
81
+ }
82
+ return stackId || "unknown-id";
83
+ }, [id, propsToWatch]);
84
+ const isFirstRender = useIsFirstRender();
85
+ if (isFirstRender) {
86
+ // eslint-disable-next-line no-console
87
+ console.log("First-render", uniqueId, window.location.pathname);
88
+ }
89
+ else if (dontLogReRender !== true) {
90
+ // eslint-disable-next-line no-console
91
+ console.log("Re-render", uniqueId, window.location.pathname);
92
+ }
93
+ React.useEffect(() => {
94
+ const changedProps = Object.entries(propsToWatch || {}).reduce((result, [key, value]) => {
95
+ if (prevPropsRef.current && prevPropsRef.current[key] !== value) {
96
+ result[`${key}`] = [prevPropsRef.current[key], value];
97
+ }
98
+ return result;
99
+ }, {});
100
+ if (sharedUtils.objectKeys(changedProps).length > 0) {
101
+ sharedUtils.objectKeys(changedProps).forEach(changedProp => {
102
+ // eslint-disable-next-line no-console
103
+ console.log(`${uniqueId} changed property: ${changedProp}`);
104
+ // JSON stringify is used to avoid console.table from logging the object reference
105
+ const result = JSON.parse(safeStringify(changedProps[changedProp]));
106
+ const result0 = result[0];
107
+ const result1 = result[1];
108
+ if (result0 && typeof result0 === "object") {
109
+ sharedUtils.objectKeys(result0).forEach(prop => {
110
+ result0[prop] = typeof result0[prop] === "object" ? JSON.stringify(result0[prop]) : result0[prop];
111
+ });
112
+ }
113
+ if (result1 && typeof result1 === "object") {
114
+ sharedUtils.objectKeys(result1).forEach(prop => {
115
+ result1[prop] = typeof result1[prop] === "object" ? JSON.stringify(result1[prop]) : result1[prop];
116
+ });
117
+ }
118
+ // eslint-disable-next-line no-console
119
+ console.table([result0, result1]);
120
+ });
121
+ // eslint-disable-next-line no-console
122
+ console.dir(changedProps);
123
+ }
124
+ prevPropsRef.current = propsToWatch;
125
+ }, [propsToWatch, uniqueId]);
126
+ };
127
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
128
+ const safeStringify = (obj) => {
129
+ const seen = new WeakSet();
130
+ return JSON.stringify(obj, function (_key, value) {
131
+ if (typeof value === "object" && value !== null) {
132
+ if (seen.has(value)) {
133
+ return undefined; // Omit circular reference
134
+ }
135
+ seen.add(value);
136
+ }
137
+ return value;
138
+ });
139
+ };
140
+
141
+ /**
142
+ * Debugger component for debugging state changes and re-renders.
143
+ *
144
+ * This component will log when it is mounted, re-renders or unmounted.
145
+ * It will also log when any of its props change.
146
+ *
147
+ * @param props - The component props.
148
+ * @param props.id - Optional id to use for logging.
149
+ * @param props.stop - If true, will stop execution and open debugger.
150
+ * @param props.logPropsChanges - Optional object with props to watch for changes.
151
+ * @param props.children - The children to render.
152
+ * @returns {ReactElement} The rendered debugger component.
153
+ */
154
+ const Debugger = ({ id, logPropsChanges, stop = false, children, }) => {
155
+ const uniqueId = id ||
156
+ // @ts-ignore
157
+ React["__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED"]?.ReactCurrentOwner?.current?._debugOwner?.type?.name ||
158
+ new Error().stack?.split("\n")[2]?.trim() ||
159
+ "unknown-id";
160
+ useDebugger(logPropsChanges || {}, id);
161
+ const uniqueIdRef = React.useRef(uniqueId);
162
+ React.useEffect(() => {
163
+ const currentUniqueId = uniqueIdRef.current;
164
+ // eslint-disable-next-line no-console
165
+ console.log(`${currentUniqueId} Debugger is mounting`);
166
+ return () => {
167
+ // eslint-disable-next-line no-console
168
+ console.log(`${currentUniqueId} Debugger is unmounting`);
169
+ };
170
+ }, []);
171
+ if (stop === true) {
172
+ // eslint-disable-next-line no-debugger
173
+ debugger;
174
+ }
175
+ return jsxRuntime.jsx("div", { className: "Debugger", children: children });
176
+ };
177
+
41
178
  /**
42
179
  * Do nothing
43
180
  */
@@ -14355,142 +14492,6 @@ class TrackunitProvidersMockBuilder {
14355
14492
  */
14356
14493
  const trackunitProviders = () => new TrackunitProvidersMockBuilder();
14357
14494
 
14358
- /**
14359
- * Differentiate between the first and subsequent renders.
14360
- *
14361
- * @returns {boolean} Returns true if it is the first render, false otherwise.
14362
- */
14363
- const useIsFirstRender = () => {
14364
- const [isFirstRender, setIsFirstRender] = React.useState(true);
14365
- React.useEffect(() => {
14366
- setIsFirstRender(false);
14367
- }, []);
14368
- return isFirstRender;
14369
- };
14370
-
14371
- /**
14372
- * Logs props that have changed.
14373
- * Use this for debugging which props force a component to re-render.
14374
- * This is a hook version of the class component lifecycle method `componentDidUpdate`.
14375
- * ALWAYS wrap in your own object.
14376
- *
14377
- * @param propsToWatch all the props to watch for changes
14378
- * @param id optional id to use for logging or it will guess the id from the stack trace
14379
- * @param dontLogReRender if true, will not log the re-render message nice if you have a lot of re-renders
14380
- * @example
14381
- * const propsToWatch = { foo: props.foo, bar: props.bar };
14382
- * useDebugger(propsToWatch);
14383
- */
14384
- const useDebugger = (propsToWatch, id, dontLogReRender) => {
14385
- const prevPropsRef = React.useRef(propsToWatch);
14386
- const uniqueId = React.useMemo(() => {
14387
- let stackId = id || (propsToWatch && propsToWatch.id);
14388
- const stack = new Error().stack;
14389
- if (!stackId && stack) {
14390
- const stackLines = stack.split("\n");
14391
- for (let i = 0; i < stackLines.length; i++) {
14392
- const stackLine = stackLines[i];
14393
- if (stackLine?.includes("useDebugger")) {
14394
- stackId = stackLines[i + 1]?.trim().split(" ")[1];
14395
- break;
14396
- }
14397
- }
14398
- }
14399
- return stackId || "unknown-id";
14400
- }, [id, propsToWatch]);
14401
- const isFirstRender = useIsFirstRender();
14402
- if (isFirstRender) {
14403
- // eslint-disable-next-line no-console
14404
- console.log("First-render", uniqueId, window.location.pathname);
14405
- }
14406
- else if (dontLogReRender !== true) {
14407
- // eslint-disable-next-line no-console
14408
- console.log("Re-render", uniqueId, window.location.pathname);
14409
- }
14410
- React.useEffect(() => {
14411
- const changedProps = Object.entries(propsToWatch || {}).reduce((result, [key, value]) => {
14412
- if (prevPropsRef.current && prevPropsRef.current[key] !== value) {
14413
- result[`${key}`] = [prevPropsRef.current[key], value];
14414
- }
14415
- return result;
14416
- }, {});
14417
- if (sharedUtils.objectKeys(changedProps).length > 0) {
14418
- sharedUtils.objectKeys(changedProps).forEach(changedProp => {
14419
- // eslint-disable-next-line no-console
14420
- console.log(`${uniqueId} changed property: ${changedProp}`);
14421
- // JSON stringify is used to avoid console.table from logging the object reference
14422
- const result = JSON.parse(safeStringify(changedProps[changedProp]));
14423
- const result0 = result[0];
14424
- const result1 = result[1];
14425
- if (result0 && typeof result0 === "object") {
14426
- sharedUtils.objectKeys(result0).forEach(prop => {
14427
- result0[prop] = typeof result0[prop] === "object" ? JSON.stringify(result0[prop]) : result0[prop];
14428
- });
14429
- }
14430
- if (result1 && typeof result1 === "object") {
14431
- sharedUtils.objectKeys(result1).forEach(prop => {
14432
- result1[prop] = typeof result1[prop] === "object" ? JSON.stringify(result1[prop]) : result1[prop];
14433
- });
14434
- }
14435
- // eslint-disable-next-line no-console
14436
- console.table([result0, result1]);
14437
- });
14438
- // eslint-disable-next-line no-console
14439
- console.dir(changedProps);
14440
- }
14441
- prevPropsRef.current = propsToWatch;
14442
- }, [propsToWatch, uniqueId]);
14443
- };
14444
- /**
14445
- * Debugger component for debugging state changes and re-renders.
14446
- *
14447
- * This component will log when it is mounted, re-renders or unmounted.
14448
- * It will also log when any of its props change.
14449
- *
14450
- * @param props - The component props.
14451
- * @param props.id - Optional id to use for logging.
14452
- * @param props.stop - If true, will stop execution and open debugger.
14453
- * @param props.logPropsChanges - Optional object with props to watch for changes.
14454
- * @param props.children - The children to render.
14455
- * @returns {ReactElement} The rendered debugger component.
14456
- */
14457
- const Debugger = ({ id, logPropsChanges, stop = false, children, }) => {
14458
- const uniqueId = id ||
14459
- // @ts-ignore
14460
- React["__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED"]?.ReactCurrentOwner?.current?._debugOwner?.type?.name ||
14461
- new Error().stack?.split("\n")[2]?.trim() ||
14462
- "unknown-id";
14463
- useDebugger(logPropsChanges || {}, id);
14464
- const uniqueIdRef = React.useRef(uniqueId);
14465
- React.useEffect(() => {
14466
- const currentUniqueId = uniqueIdRef.current;
14467
- // eslint-disable-next-line no-console
14468
- console.log(`${currentUniqueId} Debugger is mounting`);
14469
- return () => {
14470
- // eslint-disable-next-line no-console
14471
- console.log(`${currentUniqueId} Debugger is unmounting`);
14472
- };
14473
- }, []);
14474
- if (stop === true) {
14475
- // eslint-disable-next-line no-debugger
14476
- debugger;
14477
- }
14478
- return jsxRuntime.jsx("div", { className: "Debugger", children: children });
14479
- };
14480
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
14481
- const safeStringify = (obj) => {
14482
- const seen = new WeakSet();
14483
- return JSON.stringify(obj, function (_key, value) {
14484
- if (typeof value === "object" && value !== null) {
14485
- if (seen.has(value)) {
14486
- return undefined; // Omit circular reference
14487
- }
14488
- seen.add(value);
14489
- }
14490
- return value;
14491
- });
14492
- };
14493
-
14494
14495
  /**
14495
14496
  * Deep merge for GraphQL mock variables that preserves `undefined` values.
14496
14497
  *
package/index2.esm.js CHANGED
@@ -1,7 +1,8 @@
1
- import { SortOrder, AssetSortByProperty } from '@trackunit/iris-app-runtime-core-api';
2
1
  import { jsx, Fragment, jsxs } from 'react/jsx-runtime';
3
2
  import * as React from 'react';
4
- import React__default, { createContext, useContext, Children, isValidElement, createElement, useRef, useEffect, useCallback, useMemo, useState } from 'react';
3
+ import React__default, { useState, useEffect, useRef, useMemo, createContext, useContext, Children, isValidElement, createElement, useCallback } from 'react';
4
+ import { objectKeys, doNothing as doNothing$1, objectValues } from '@trackunit/shared-utils';
5
+ import { SortOrder, AssetSortByProperty } from '@trackunit/iris-app-runtime-core-api';
5
6
  import * as DeprecatedReactTestUtils from 'react-dom/test-utils';
6
7
  import ReactDOM from 'react-dom';
7
8
  import * as ReactDOMClient from 'react-dom/client';
@@ -11,11 +12,147 @@ import { ApolloLink } from '@apollo/client';
11
12
  import { loadDevMessages, loadErrorMessages } from '@apollo/client/dev';
12
13
  import { onError } from '@apollo/client/link/error';
13
14
  import { MockLink, MockedProvider } from '@apollo/client/testing';
14
- import { doNothing as doNothing$1, objectValues, objectKeys } from '@trackunit/shared-utils';
15
15
  import { useApolloClient } from '@apollo/client/react';
16
16
  import { createMemoryHistory, createRootRoute, createRoute, createRouter, RouterProvider, Outlet } from '@tanstack/react-router';
17
17
  import { GraphQLError } from 'graphql';
18
18
 
19
+ /**
20
+ * Differentiate between the first and subsequent renders.
21
+ *
22
+ * @returns {boolean} Returns true if it is the first render, false otherwise.
23
+ */
24
+ const useIsFirstRender = () => {
25
+ const [isFirstRender, setIsFirstRender] = useState(true);
26
+ useEffect(() => {
27
+ setIsFirstRender(false);
28
+ }, []);
29
+ return isFirstRender;
30
+ };
31
+
32
+ /**
33
+ * Logs props that have changed.
34
+ * Use this for debugging which props force a component to re-render.
35
+ * This is a hook version of the class component lifecycle method `componentDidUpdate`.
36
+ * ALWAYS wrap in your own object.
37
+ *
38
+ * @param propsToWatch all the props to watch for changes
39
+ * @param id optional id to use for logging or it will guess the id from the stack trace
40
+ * @param dontLogReRender if true, will not log the re-render message nice if you have a lot of re-renders
41
+ * @example
42
+ * const propsToWatch = { foo: props.foo, bar: props.bar };
43
+ * useDebugger(propsToWatch);
44
+ */
45
+ const useDebugger = (propsToWatch, id, dontLogReRender) => {
46
+ const prevPropsRef = useRef(propsToWatch);
47
+ const uniqueId = useMemo(() => {
48
+ let stackId = id || (propsToWatch && propsToWatch.id);
49
+ const stack = new Error().stack;
50
+ if (!stackId && stack) {
51
+ const stackLines = stack.split("\n");
52
+ for (let i = 0; i < stackLines.length; i++) {
53
+ const stackLine = stackLines[i];
54
+ if (stackLine?.includes("useDebugger")) {
55
+ stackId = stackLines[i + 1]?.trim().split(" ")[1];
56
+ break;
57
+ }
58
+ }
59
+ }
60
+ return stackId || "unknown-id";
61
+ }, [id, propsToWatch]);
62
+ const isFirstRender = useIsFirstRender();
63
+ if (isFirstRender) {
64
+ // eslint-disable-next-line no-console
65
+ console.log("First-render", uniqueId, window.location.pathname);
66
+ }
67
+ else if (dontLogReRender !== true) {
68
+ // eslint-disable-next-line no-console
69
+ console.log("Re-render", uniqueId, window.location.pathname);
70
+ }
71
+ useEffect(() => {
72
+ const changedProps = Object.entries(propsToWatch || {}).reduce((result, [key, value]) => {
73
+ if (prevPropsRef.current && prevPropsRef.current[key] !== value) {
74
+ result[`${key}`] = [prevPropsRef.current[key], value];
75
+ }
76
+ return result;
77
+ }, {});
78
+ if (objectKeys(changedProps).length > 0) {
79
+ objectKeys(changedProps).forEach(changedProp => {
80
+ // eslint-disable-next-line no-console
81
+ console.log(`${uniqueId} changed property: ${changedProp}`);
82
+ // JSON stringify is used to avoid console.table from logging the object reference
83
+ const result = JSON.parse(safeStringify(changedProps[changedProp]));
84
+ const result0 = result[0];
85
+ const result1 = result[1];
86
+ if (result0 && typeof result0 === "object") {
87
+ objectKeys(result0).forEach(prop => {
88
+ result0[prop] = typeof result0[prop] === "object" ? JSON.stringify(result0[prop]) : result0[prop];
89
+ });
90
+ }
91
+ if (result1 && typeof result1 === "object") {
92
+ objectKeys(result1).forEach(prop => {
93
+ result1[prop] = typeof result1[prop] === "object" ? JSON.stringify(result1[prop]) : result1[prop];
94
+ });
95
+ }
96
+ // eslint-disable-next-line no-console
97
+ console.table([result0, result1]);
98
+ });
99
+ // eslint-disable-next-line no-console
100
+ console.dir(changedProps);
101
+ }
102
+ prevPropsRef.current = propsToWatch;
103
+ }, [propsToWatch, uniqueId]);
104
+ };
105
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
106
+ const safeStringify = (obj) => {
107
+ const seen = new WeakSet();
108
+ return JSON.stringify(obj, function (_key, value) {
109
+ if (typeof value === "object" && value !== null) {
110
+ if (seen.has(value)) {
111
+ return undefined; // Omit circular reference
112
+ }
113
+ seen.add(value);
114
+ }
115
+ return value;
116
+ });
117
+ };
118
+
119
+ /**
120
+ * Debugger component for debugging state changes and re-renders.
121
+ *
122
+ * This component will log when it is mounted, re-renders or unmounted.
123
+ * It will also log when any of its props change.
124
+ *
125
+ * @param props - The component props.
126
+ * @param props.id - Optional id to use for logging.
127
+ * @param props.stop - If true, will stop execution and open debugger.
128
+ * @param props.logPropsChanges - Optional object with props to watch for changes.
129
+ * @param props.children - The children to render.
130
+ * @returns {ReactElement} The rendered debugger component.
131
+ */
132
+ const Debugger = ({ id, logPropsChanges, stop = false, children, }) => {
133
+ const uniqueId = id ||
134
+ // @ts-ignore
135
+ React__default["__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED"]?.ReactCurrentOwner?.current?._debugOwner?.type?.name ||
136
+ new Error().stack?.split("\n")[2]?.trim() ||
137
+ "unknown-id";
138
+ useDebugger(logPropsChanges || {}, id);
139
+ const uniqueIdRef = useRef(uniqueId);
140
+ useEffect(() => {
141
+ const currentUniqueId = uniqueIdRef.current;
142
+ // eslint-disable-next-line no-console
143
+ console.log(`${currentUniqueId} Debugger is mounting`);
144
+ return () => {
145
+ // eslint-disable-next-line no-console
146
+ console.log(`${currentUniqueId} Debugger is unmounting`);
147
+ };
148
+ }, []);
149
+ if (stop === true) {
150
+ // eslint-disable-next-line no-debugger
151
+ debugger;
152
+ }
153
+ return jsx("div", { className: "Debugger", children: children });
154
+ };
155
+
19
156
  /**
20
157
  * Do nothing
21
158
  */
@@ -14333,142 +14470,6 @@ class TrackunitProvidersMockBuilder {
14333
14470
  */
14334
14471
  const trackunitProviders = () => new TrackunitProvidersMockBuilder();
14335
14472
 
14336
- /**
14337
- * Differentiate between the first and subsequent renders.
14338
- *
14339
- * @returns {boolean} Returns true if it is the first render, false otherwise.
14340
- */
14341
- const useIsFirstRender = () => {
14342
- const [isFirstRender, setIsFirstRender] = useState(true);
14343
- useEffect(() => {
14344
- setIsFirstRender(false);
14345
- }, []);
14346
- return isFirstRender;
14347
- };
14348
-
14349
- /**
14350
- * Logs props that have changed.
14351
- * Use this for debugging which props force a component to re-render.
14352
- * This is a hook version of the class component lifecycle method `componentDidUpdate`.
14353
- * ALWAYS wrap in your own object.
14354
- *
14355
- * @param propsToWatch all the props to watch for changes
14356
- * @param id optional id to use for logging or it will guess the id from the stack trace
14357
- * @param dontLogReRender if true, will not log the re-render message nice if you have a lot of re-renders
14358
- * @example
14359
- * const propsToWatch = { foo: props.foo, bar: props.bar };
14360
- * useDebugger(propsToWatch);
14361
- */
14362
- const useDebugger = (propsToWatch, id, dontLogReRender) => {
14363
- const prevPropsRef = useRef(propsToWatch);
14364
- const uniqueId = useMemo(() => {
14365
- let stackId = id || (propsToWatch && propsToWatch.id);
14366
- const stack = new Error().stack;
14367
- if (!stackId && stack) {
14368
- const stackLines = stack.split("\n");
14369
- for (let i = 0; i < stackLines.length; i++) {
14370
- const stackLine = stackLines[i];
14371
- if (stackLine?.includes("useDebugger")) {
14372
- stackId = stackLines[i + 1]?.trim().split(" ")[1];
14373
- break;
14374
- }
14375
- }
14376
- }
14377
- return stackId || "unknown-id";
14378
- }, [id, propsToWatch]);
14379
- const isFirstRender = useIsFirstRender();
14380
- if (isFirstRender) {
14381
- // eslint-disable-next-line no-console
14382
- console.log("First-render", uniqueId, window.location.pathname);
14383
- }
14384
- else if (dontLogReRender !== true) {
14385
- // eslint-disable-next-line no-console
14386
- console.log("Re-render", uniqueId, window.location.pathname);
14387
- }
14388
- useEffect(() => {
14389
- const changedProps = Object.entries(propsToWatch || {}).reduce((result, [key, value]) => {
14390
- if (prevPropsRef.current && prevPropsRef.current[key] !== value) {
14391
- result[`${key}`] = [prevPropsRef.current[key], value];
14392
- }
14393
- return result;
14394
- }, {});
14395
- if (objectKeys(changedProps).length > 0) {
14396
- objectKeys(changedProps).forEach(changedProp => {
14397
- // eslint-disable-next-line no-console
14398
- console.log(`${uniqueId} changed property: ${changedProp}`);
14399
- // JSON stringify is used to avoid console.table from logging the object reference
14400
- const result = JSON.parse(safeStringify(changedProps[changedProp]));
14401
- const result0 = result[0];
14402
- const result1 = result[1];
14403
- if (result0 && typeof result0 === "object") {
14404
- objectKeys(result0).forEach(prop => {
14405
- result0[prop] = typeof result0[prop] === "object" ? JSON.stringify(result0[prop]) : result0[prop];
14406
- });
14407
- }
14408
- if (result1 && typeof result1 === "object") {
14409
- objectKeys(result1).forEach(prop => {
14410
- result1[prop] = typeof result1[prop] === "object" ? JSON.stringify(result1[prop]) : result1[prop];
14411
- });
14412
- }
14413
- // eslint-disable-next-line no-console
14414
- console.table([result0, result1]);
14415
- });
14416
- // eslint-disable-next-line no-console
14417
- console.dir(changedProps);
14418
- }
14419
- prevPropsRef.current = propsToWatch;
14420
- }, [propsToWatch, uniqueId]);
14421
- };
14422
- /**
14423
- * Debugger component for debugging state changes and re-renders.
14424
- *
14425
- * This component will log when it is mounted, re-renders or unmounted.
14426
- * It will also log when any of its props change.
14427
- *
14428
- * @param props - The component props.
14429
- * @param props.id - Optional id to use for logging.
14430
- * @param props.stop - If true, will stop execution and open debugger.
14431
- * @param props.logPropsChanges - Optional object with props to watch for changes.
14432
- * @param props.children - The children to render.
14433
- * @returns {ReactElement} The rendered debugger component.
14434
- */
14435
- const Debugger = ({ id, logPropsChanges, stop = false, children, }) => {
14436
- const uniqueId = id ||
14437
- // @ts-ignore
14438
- React__default["__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED"]?.ReactCurrentOwner?.current?._debugOwner?.type?.name ||
14439
- new Error().stack?.split("\n")[2]?.trim() ||
14440
- "unknown-id";
14441
- useDebugger(logPropsChanges || {}, id);
14442
- const uniqueIdRef = useRef(uniqueId);
14443
- useEffect(() => {
14444
- const currentUniqueId = uniqueIdRef.current;
14445
- // eslint-disable-next-line no-console
14446
- console.log(`${currentUniqueId} Debugger is mounting`);
14447
- return () => {
14448
- // eslint-disable-next-line no-console
14449
- console.log(`${currentUniqueId} Debugger is unmounting`);
14450
- };
14451
- }, []);
14452
- if (stop === true) {
14453
- // eslint-disable-next-line no-debugger
14454
- debugger;
14455
- }
14456
- return jsx("div", { className: "Debugger", children: children });
14457
- };
14458
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
14459
- const safeStringify = (obj) => {
14460
- const seen = new WeakSet();
14461
- return JSON.stringify(obj, function (_key, value) {
14462
- if (typeof value === "object" && value !== null) {
14463
- if (seen.has(value)) {
14464
- return undefined; // Omit circular reference
14465
- }
14466
- seen.add(value);
14467
- }
14468
- return value;
14469
- });
14470
- };
14471
-
14472
14473
  /**
14473
14474
  * Deep merge for GraphQL mock variables that preserves `undefined` values.
14474
14475
  *
package/package.json CHANGED
@@ -1,16 +1,16 @@
1
1
  {
2
2
  "name": "@trackunit/react-core-contexts-test",
3
- "version": "1.18.16",
3
+ "version": "1.18.18",
4
4
  "repository": "https://github.com/Trackunit/manager",
5
5
  "license": "SEE LICENSE IN LICENSE.txt",
6
6
  "engines": {
7
7
  "node": ">=24.x"
8
8
  },
9
9
  "dependencies": {
10
- "@trackunit/shared-utils": "1.16.16",
10
+ "@trackunit/shared-utils": "1.16.18",
11
11
  "@tanstack/router-core": "1.114.29",
12
- "@trackunit/iris-app-runtime-core-api": "1.17.16",
13
- "@trackunit/react-core-contexts-api": "1.18.16",
12
+ "@trackunit/iris-app-runtime-core-api": "1.17.18",
13
+ "@trackunit/react-core-contexts-api": "1.18.18",
14
14
  "es-toolkit": "^1.39.10"
15
15
  },
16
16
  "peerDependencies": {
@@ -0,0 +1,20 @@
1
+ import { ReactElement, ReactNode } from "react";
2
+ /**
3
+ * Debugger component for debugging state changes and re-renders.
4
+ *
5
+ * This component will log when it is mounted, re-renders or unmounted.
6
+ * It will also log when any of its props change.
7
+ *
8
+ * @param props - The component props.
9
+ * @param props.id - Optional id to use for logging.
10
+ * @param props.stop - If true, will stop execution and open debugger.
11
+ * @param props.logPropsChanges - Optional object with props to watch for changes.
12
+ * @param props.children - The children to render.
13
+ * @returns {ReactElement} The rendered debugger component.
14
+ */
15
+ export declare const Debugger: ({ id, logPropsChanges, stop, children, }: {
16
+ children?: ReactNode;
17
+ id?: string;
18
+ stop?: boolean;
19
+ logPropsChanges?: Record<string, unknown>;
20
+ }) => ReactElement;
@@ -4,7 +4,7 @@ import { RenderResult } from "@testing-library/react";
4
4
  import { AnalyticsRuntimeApiSync, AssetSortingState, ConfirmationDialogRuntimeApi, CurrentUserPreferenceState, CurrentUserState, EnvironmentState, ErrorHandlingContextValue, FeatureFlagState, FilterBarContext, ModalDialogRuntimeApi, NavigationRuntimeApi, OemBrandingRuntimeApi, TimeRangeContext, TokenContext, UserSubscription, WidgetConfigContext } from "@trackunit/iris-app-runtime-core-api";
5
5
  import { ExportDataContextState, GeolocationContextValue, ToastContextValue } from "@trackunit/react-core-contexts-api";
6
6
  import { ReactElement, ReactNode } from "react";
7
- import { MemoryRouterProps } from "./utils/routingUtils";
7
+ import { MemoryRouterProps } from "./utils/RouterContainer";
8
8
  /**
9
9
  * This builder allows you to enable trackunit providers using the builder pattern, and then call 1 of either:
10
10
  * For React Components:
package/src/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ export * from "./Debugger";
1
2
  export * from "./mocks/mockAnalyticsContext";
2
3
  export * from "./mocks/mockAssetSortingContext";
3
4
  export * from "./mocks/mockCurrentUserContext";
@@ -10,8 +11,8 @@ export * from "./mocks/mockToastContext";
10
11
  export * from "./mocks/mockUserSubscriptionContext";
11
12
  export * from "./TrackunitProvidersMockBuilder";
12
13
  export * from "./useDebugger";
13
- export * from "./utils/mergeDeepVars";
14
14
  export * from "./utils/doNothing";
15
+ export * from "./utils/mergeDeepVars";
15
16
  export * from "./utils/queryFor";
16
17
  export * from "./utils/validateIrisApp";
17
18
  export * from "./utils/wait";
@@ -1,4 +1,3 @@
1
- import { ReactElement, ReactNode } from "react";
2
1
  type PropsToWatch<TProps> = TProps extends object ? TProps : never;
3
2
  /**
4
3
  * Logs props that have changed.
@@ -14,23 +13,4 @@ type PropsToWatch<TProps> = TProps extends object ? TProps : never;
14
13
  * useDebugger(propsToWatch);
15
14
  */
16
15
  export declare const useDebugger: <TProps extends object>(propsToWatch: PropsToWatch<TProps> | null, id?: string, dontLogReRender?: boolean) => void;
17
- /**
18
- * Debugger component for debugging state changes and re-renders.
19
- *
20
- * This component will log when it is mounted, re-renders or unmounted.
21
- * It will also log when any of its props change.
22
- *
23
- * @param props - The component props.
24
- * @param props.id - Optional id to use for logging.
25
- * @param props.stop - If true, will stop execution and open debugger.
26
- * @param props.logPropsChanges - Optional object with props to watch for changes.
27
- * @param props.children - The children to render.
28
- * @returns {ReactElement} The rendered debugger component.
29
- */
30
- export declare const Debugger: ({ id, logPropsChanges, stop, children, }: {
31
- children?: ReactNode;
32
- id?: string;
33
- stop?: boolean;
34
- logPropsChanges?: Record<string, unknown>;
35
- }) => ReactElement;
36
16
  export {};