@trackunit/react-core-contexts-test 1.7.17 → 1.7.20
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/index.cjs.js +12 -3
- package/index.esm.js +12 -3
- package/package.json +5 -5
- package/src/useDebugger.d.ts +2 -1
- package/src/utils/queryFor.d.ts +1 -1
package/index.cjs.js
CHANGED
|
@@ -1007,11 +1007,12 @@ const useIsFirstRender = () => {
|
|
|
1007
1007
|
*
|
|
1008
1008
|
* @param id optional id to use for logging or it will guess the id from the stack trace
|
|
1009
1009
|
* @param propsToWatch all the props to watch for changes
|
|
1010
|
+
* @param dontLogReRender if true, will not log the re-render message nice if you have a lot of re-renders
|
|
1010
1011
|
* @example
|
|
1011
1012
|
* const propsToWatch = { foo: props.foo, bar: props.bar };
|
|
1012
1013
|
* useDebugger(propsToWatch);
|
|
1013
1014
|
*/
|
|
1014
|
-
const useDebugger = (propsToWatch, id) => {
|
|
1015
|
+
const useDebugger = (propsToWatch, id, dontLogReRender) => {
|
|
1015
1016
|
const prevPropsRef = React.useRef(propsToWatch);
|
|
1016
1017
|
const uniqueId = React.useMemo(() => {
|
|
1017
1018
|
let stackId = id || (propsToWatch && propsToWatch.id);
|
|
@@ -1030,7 +1031,14 @@ const useDebugger = (propsToWatch, id) => {
|
|
|
1030
1031
|
}, [id, propsToWatch]);
|
|
1031
1032
|
const isFirstRender = useIsFirstRender();
|
|
1032
1033
|
// eslint-disable-next-line no-console
|
|
1033
|
-
|
|
1034
|
+
if (isFirstRender) {
|
|
1035
|
+
// eslint-disable-next-line no-console
|
|
1036
|
+
console.log("First-render", uniqueId, window.location.pathname);
|
|
1037
|
+
}
|
|
1038
|
+
else if (dontLogReRender !== true) {
|
|
1039
|
+
// eslint-disable-next-line no-console
|
|
1040
|
+
console.log("Re-render", uniqueId, window.location.pathname);
|
|
1041
|
+
}
|
|
1034
1042
|
React.useEffect(() => {
|
|
1035
1043
|
const changedProps = Object.entries(propsToWatch || {}).reduce((result, [key, value]) => {
|
|
1036
1044
|
if (prevPropsRef.current && prevPropsRef.current[key] !== value) {
|
|
@@ -1139,13 +1147,14 @@ const safeStringify = (obj) => {
|
|
|
1139
1147
|
* expect(screen.getByText(`Brand: ${mock.data.asset?.brand}`)).toBeInTheDocument();
|
|
1140
1148
|
* });
|
|
1141
1149
|
*/
|
|
1142
|
-
const queryFor = (document, variables, data, error) => {
|
|
1150
|
+
const queryFor = (document, variables, data, error, maxUsageCount = 1) => {
|
|
1143
1151
|
return {
|
|
1144
1152
|
request: {
|
|
1145
1153
|
query: document,
|
|
1146
1154
|
variables,
|
|
1147
1155
|
},
|
|
1148
1156
|
data,
|
|
1157
|
+
maxUsageCount,
|
|
1149
1158
|
newData: () => {
|
|
1150
1159
|
if (process.env.VSCODE_INSPECTOR_OPTIONS || process.env.DEBUG) {
|
|
1151
1160
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
package/index.esm.js
CHANGED
|
@@ -1005,11 +1005,12 @@ const useIsFirstRender = () => {
|
|
|
1005
1005
|
*
|
|
1006
1006
|
* @param id optional id to use for logging or it will guess the id from the stack trace
|
|
1007
1007
|
* @param propsToWatch all the props to watch for changes
|
|
1008
|
+
* @param dontLogReRender if true, will not log the re-render message nice if you have a lot of re-renders
|
|
1008
1009
|
* @example
|
|
1009
1010
|
* const propsToWatch = { foo: props.foo, bar: props.bar };
|
|
1010
1011
|
* useDebugger(propsToWatch);
|
|
1011
1012
|
*/
|
|
1012
|
-
const useDebugger = (propsToWatch, id) => {
|
|
1013
|
+
const useDebugger = (propsToWatch, id, dontLogReRender) => {
|
|
1013
1014
|
const prevPropsRef = useRef(propsToWatch);
|
|
1014
1015
|
const uniqueId = useMemo(() => {
|
|
1015
1016
|
let stackId = id || (propsToWatch && propsToWatch.id);
|
|
@@ -1028,7 +1029,14 @@ const useDebugger = (propsToWatch, id) => {
|
|
|
1028
1029
|
}, [id, propsToWatch]);
|
|
1029
1030
|
const isFirstRender = useIsFirstRender();
|
|
1030
1031
|
// eslint-disable-next-line no-console
|
|
1031
|
-
|
|
1032
|
+
if (isFirstRender) {
|
|
1033
|
+
// eslint-disable-next-line no-console
|
|
1034
|
+
console.log("First-render", uniqueId, window.location.pathname);
|
|
1035
|
+
}
|
|
1036
|
+
else if (dontLogReRender !== true) {
|
|
1037
|
+
// eslint-disable-next-line no-console
|
|
1038
|
+
console.log("Re-render", uniqueId, window.location.pathname);
|
|
1039
|
+
}
|
|
1032
1040
|
useEffect(() => {
|
|
1033
1041
|
const changedProps = Object.entries(propsToWatch || {}).reduce((result, [key, value]) => {
|
|
1034
1042
|
if (prevPropsRef.current && prevPropsRef.current[key] !== value) {
|
|
@@ -1137,13 +1145,14 @@ const safeStringify = (obj) => {
|
|
|
1137
1145
|
* expect(screen.getByText(`Brand: ${mock.data.asset?.brand}`)).toBeInTheDocument();
|
|
1138
1146
|
* });
|
|
1139
1147
|
*/
|
|
1140
|
-
const queryFor = (document, variables, data, error) => {
|
|
1148
|
+
const queryFor = (document, variables, data, error, maxUsageCount = 1) => {
|
|
1141
1149
|
return {
|
|
1142
1150
|
request: {
|
|
1143
1151
|
query: document,
|
|
1144
1152
|
variables,
|
|
1145
1153
|
},
|
|
1146
1154
|
data,
|
|
1155
|
+
maxUsageCount,
|
|
1147
1156
|
newData: () => {
|
|
1148
1157
|
if (process.env.VSCODE_INSPECTOR_OPTIONS || process.env.DEBUG) {
|
|
1149
1158
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trackunit/react-core-contexts-test",
|
|
3
|
-
"version": "1.7.
|
|
3
|
+
"version": "1.7.20",
|
|
4
4
|
"repository": "https://github.com/Trackunit/manager",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE.txt",
|
|
6
6
|
"engines": {
|
|
@@ -11,10 +11,10 @@
|
|
|
11
11
|
"@testing-library/react": "16.2.0",
|
|
12
12
|
"react": "19.0.0",
|
|
13
13
|
"graphql": "^16.10.0",
|
|
14
|
-
"@trackunit/react-core-contexts-api": "1.8.
|
|
15
|
-
"@trackunit/react-core-hooks": "1.7.
|
|
16
|
-
"@trackunit/shared-utils": "1.9.
|
|
17
|
-
"@trackunit/react-test-setup": "1.4.
|
|
14
|
+
"@trackunit/react-core-contexts-api": "1.8.19",
|
|
15
|
+
"@trackunit/react-core-hooks": "1.7.20",
|
|
16
|
+
"@trackunit/shared-utils": "1.9.17",
|
|
17
|
+
"@trackunit/react-test-setup": "1.4.17",
|
|
18
18
|
"@tanstack/react-router": "1.114.29",
|
|
19
19
|
"@tanstack/router-core": "1.114.29",
|
|
20
20
|
"es-toolkit": "^1.39.10"
|
package/src/useDebugger.d.ts
CHANGED
|
@@ -8,11 +8,12 @@ type PropsToWatch<P> = P extends object ? P : never;
|
|
|
8
8
|
*
|
|
9
9
|
* @param id optional id to use for logging or it will guess the id from the stack trace
|
|
10
10
|
* @param propsToWatch all the props to watch for changes
|
|
11
|
+
* @param dontLogReRender if true, will not log the re-render message nice if you have a lot of re-renders
|
|
11
12
|
* @example
|
|
12
13
|
* const propsToWatch = { foo: props.foo, bar: props.bar };
|
|
13
14
|
* useDebugger(propsToWatch);
|
|
14
15
|
*/
|
|
15
|
-
export declare const useDebugger: <P extends object>(propsToWatch: PropsToWatch<P> | null, id?: string) => void;
|
|
16
|
+
export declare const useDebugger: <P extends object>(propsToWatch: PropsToWatch<P> | null, id?: string, dontLogReRender?: boolean) => void;
|
|
16
17
|
/**
|
|
17
18
|
* Debugger component for debugging state changes and re-renders.
|
|
18
19
|
*
|
package/src/utils/queryFor.d.ts
CHANGED
|
@@ -30,7 +30,7 @@ type DeepPartialNullableArray<T> = Array<DeepPartialNullable<T>>;
|
|
|
30
30
|
* expect(screen.getByText(`Brand: ${mock.data.asset?.brand}`)).toBeInTheDocument();
|
|
31
31
|
* });
|
|
32
32
|
*/
|
|
33
|
-
export declare const queryFor: <TData, TVariables extends OperationVariables = OperationVariables>(document: TypedDocumentNode<TData, TVariables>, variables: TVariables, data?: TData | null, error?: ApolloError | Error) => MockedResponse<TData> & {
|
|
33
|
+
export declare const queryFor: <TData, TVariables extends OperationVariables = OperationVariables>(document: TypedDocumentNode<TData, TVariables>, variables: TVariables, data?: TData | null, error?: ApolloError | Error, maxUsageCount?: number) => MockedResponse<TData> & {
|
|
34
34
|
data: NonNullable<TData>;
|
|
35
35
|
};
|
|
36
36
|
type QueryReturn<TData, TVariables extends OperationVariables = OperationVariables> = ReturnType<typeof useQuery<TData, TVariables>>;
|