@trackunit/react-core-contexts-test 1.12.41 → 1.12.42-alpha-57a40ea11fa.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/index.cjs2.js
CHANGED
|
@@ -13490,36 +13490,38 @@ const mockWidgetConfigContext = {
|
|
|
13490
13490
|
closeEditMode: async () => { },
|
|
13491
13491
|
};
|
|
13492
13492
|
|
|
13493
|
-
const RerenderContext = React.createContext({
|
|
13493
|
+
const RerenderContext = React.createContext({ counter: 0 });
|
|
13494
13494
|
/**
|
|
13495
|
-
*
|
|
13495
|
+
* Provides a rerender signal via context to force re-renders in tests.
|
|
13496
|
+
* TanStack Router wraps Match/MatchInner in React.memo, which blocks RTL's rerender() from
|
|
13497
|
+
* propagating to the hook under test. React context changes bypass React.memo boundaries,
|
|
13498
|
+
* so changing the context value triggers a re-render in any descendant consuming RerenderContext.
|
|
13499
|
+
*
|
|
13500
|
+
* The value is intentionally wrapped in a new object on every render. This ensures the context
|
|
13501
|
+
* identity always changes -- even when the external counter prop hasn't changed (e.g. during
|
|
13502
|
+
* HookRenderer's automatic rerender) -- so consumers are always notified.
|
|
13496
13503
|
*/
|
|
13497
|
-
const RerenderProvider = ({ children, counter }) => {
|
|
13498
|
-
const [rerenderCounter, setRerenderCounter] = React.useState(0);
|
|
13499
|
-
React.useEffect(() => {
|
|
13500
|
-
if (counter && rerenderCounter !== counter && rerenderCounter !== 0) {
|
|
13501
|
-
setRerenderCounter(counter);
|
|
13502
|
-
}
|
|
13503
|
-
}, [rerenderCounter, counter]);
|
|
13504
|
-
return (jsxRuntime.jsx(RerenderContext.Provider, { value: { rerenderCounter, setRerenderCounter }, children: children }));
|
|
13505
|
-
};
|
|
13504
|
+
const RerenderProvider = ({ children, counter }) => (jsxRuntime.jsx(RerenderContext.Provider, { value: { counter }, children: children }));
|
|
13506
13505
|
/**
|
|
13507
|
-
*
|
|
13506
|
+
* Returns the current rerender counter from context.
|
|
13508
13507
|
*/
|
|
13509
|
-
const useRerenderCounter = () =>
|
|
13510
|
-
return React.useContext(RerenderContext);
|
|
13511
|
-
};
|
|
13508
|
+
const useRerenderCounter = () => React.useContext(RerenderContext).counter;
|
|
13512
13509
|
|
|
13513
13510
|
/**
|
|
13514
|
-
*
|
|
13511
|
+
* Subscribes to RerenderContext so this subtree re-renders when the counter changes,
|
|
13512
|
+
* even when nested inside React.memo boundaries (like TanStack Router's Match/MatchInner).
|
|
13513
|
+
*
|
|
13514
|
+
* Consuming the context alone is not enough: React will bail out of re-rendering children
|
|
13515
|
+
* if the element references haven't changed. createElement produces new element instances
|
|
13516
|
+
* with a changed prop, which forces React to reconcile and re-render the test component.
|
|
13515
13517
|
*/
|
|
13516
13518
|
const RerenderComponent = ({ children }) => {
|
|
13517
|
-
const
|
|
13518
|
-
return (jsxRuntime.jsx(
|
|
13519
|
+
const counter = useRerenderCounter();
|
|
13520
|
+
return (jsxRuntime.jsx(jsxRuntime.Fragment, { children: React.Children.map(children, child => React.isValidElement(child)
|
|
13519
13521
|
? React.createElement(child.type, {
|
|
13520
13522
|
...child.props,
|
|
13521
13523
|
key: child.key,
|
|
13522
|
-
"data-rerender-counter":
|
|
13524
|
+
"data-rerender-counter": counter,
|
|
13523
13525
|
})
|
|
13524
13526
|
: child) }));
|
|
13525
13527
|
};
|
|
@@ -13661,7 +13663,7 @@ const RouterContainer = ({ addTestRootContainer, selectedRouterProps, rootRoute,
|
|
|
13661
13663
|
defaultPendingMs: 0,
|
|
13662
13664
|
defaultPendingMinMs: 0, // Add this to control minimum pending time
|
|
13663
13665
|
context: {
|
|
13664
|
-
|
|
13666
|
+
hasAccessToHostRoute: async () => {
|
|
13665
13667
|
return true;
|
|
13666
13668
|
},
|
|
13667
13669
|
showMarketplace: true,
|
|
@@ -13674,7 +13676,7 @@ const RouterContainer = ({ addTestRootContainer, selectedRouterProps, rootRoute,
|
|
|
13674
13676
|
});
|
|
13675
13677
|
}, [rootRoute]);
|
|
13676
13678
|
const context = React.useMemo(() => ({
|
|
13677
|
-
|
|
13679
|
+
hasAccessToHostRoute: async () => true,
|
|
13678
13680
|
isAuthenticated: true,
|
|
13679
13681
|
client,
|
|
13680
13682
|
defaultUserRoute: "/",
|
|
@@ -13957,7 +13959,6 @@ class TrackunitProvidersMockBuilder {
|
|
|
13957
13959
|
* @returns { TrackunitProvidersMockBuilder } - The builder.
|
|
13958
13960
|
*/
|
|
13959
13961
|
userSubscription(userSubscription) {
|
|
13960
|
-
//TODO DON'T SUPPORT THE WEIRD WAY OF PASSING FEATURES
|
|
13961
13962
|
const featuresConverted = userSubscription.features?.map(f => {
|
|
13962
13963
|
if (typeof f === "string") {
|
|
13963
13964
|
return { id: f, name: f };
|
package/index.esm2.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { SortOrder, AssetSortByProperty } from '@trackunit/iris-app-runtime-core-api';
|
|
2
|
-
import { jsx,
|
|
2
|
+
import { jsx, Fragment, jsxs } from 'react/jsx-runtime';
|
|
3
3
|
import * as React from 'react';
|
|
4
|
-
import React__default, { createContext,
|
|
4
|
+
import React__default, { createContext, useContext, Children, createElement, isValidElement, useRef, useEffect, useCallback, useMemo, useState } from 'react';
|
|
5
5
|
import * as DeprecatedReactTestUtils from 'react-dom/test-utils';
|
|
6
6
|
import ReactDOM from 'react-dom';
|
|
7
7
|
import * as ReactDOMClient from 'react-dom/client';
|
|
@@ -13468,36 +13468,38 @@ const mockWidgetConfigContext = {
|
|
|
13468
13468
|
closeEditMode: async () => { },
|
|
13469
13469
|
};
|
|
13470
13470
|
|
|
13471
|
-
const RerenderContext = createContext({
|
|
13471
|
+
const RerenderContext = createContext({ counter: 0 });
|
|
13472
13472
|
/**
|
|
13473
|
-
*
|
|
13473
|
+
* Provides a rerender signal via context to force re-renders in tests.
|
|
13474
|
+
* TanStack Router wraps Match/MatchInner in React.memo, which blocks RTL's rerender() from
|
|
13475
|
+
* propagating to the hook under test. React context changes bypass React.memo boundaries,
|
|
13476
|
+
* so changing the context value triggers a re-render in any descendant consuming RerenderContext.
|
|
13477
|
+
*
|
|
13478
|
+
* The value is intentionally wrapped in a new object on every render. This ensures the context
|
|
13479
|
+
* identity always changes -- even when the external counter prop hasn't changed (e.g. during
|
|
13480
|
+
* HookRenderer's automatic rerender) -- so consumers are always notified.
|
|
13474
13481
|
*/
|
|
13475
|
-
const RerenderProvider = ({ children, counter }) => {
|
|
13476
|
-
const [rerenderCounter, setRerenderCounter] = useState(0);
|
|
13477
|
-
useEffect(() => {
|
|
13478
|
-
if (counter && rerenderCounter !== counter && rerenderCounter !== 0) {
|
|
13479
|
-
setRerenderCounter(counter);
|
|
13480
|
-
}
|
|
13481
|
-
}, [rerenderCounter, counter]);
|
|
13482
|
-
return (jsx(RerenderContext.Provider, { value: { rerenderCounter, setRerenderCounter }, children: children }));
|
|
13483
|
-
};
|
|
13482
|
+
const RerenderProvider = ({ children, counter }) => (jsx(RerenderContext.Provider, { value: { counter }, children: children }));
|
|
13484
13483
|
/**
|
|
13485
|
-
*
|
|
13484
|
+
* Returns the current rerender counter from context.
|
|
13486
13485
|
*/
|
|
13487
|
-
const useRerenderCounter = () =>
|
|
13488
|
-
return useContext(RerenderContext);
|
|
13489
|
-
};
|
|
13486
|
+
const useRerenderCounter = () => useContext(RerenderContext).counter;
|
|
13490
13487
|
|
|
13491
13488
|
/**
|
|
13492
|
-
*
|
|
13489
|
+
* Subscribes to RerenderContext so this subtree re-renders when the counter changes,
|
|
13490
|
+
* even when nested inside React.memo boundaries (like TanStack Router's Match/MatchInner).
|
|
13491
|
+
*
|
|
13492
|
+
* Consuming the context alone is not enough: React will bail out of re-rendering children
|
|
13493
|
+
* if the element references haven't changed. createElement produces new element instances
|
|
13494
|
+
* with a changed prop, which forces React to reconcile and re-render the test component.
|
|
13493
13495
|
*/
|
|
13494
13496
|
const RerenderComponent = ({ children }) => {
|
|
13495
|
-
const
|
|
13496
|
-
return (jsx(
|
|
13497
|
+
const counter = useRerenderCounter();
|
|
13498
|
+
return (jsx(Fragment, { children: Children.map(children, child => isValidElement(child)
|
|
13497
13499
|
? createElement(child.type, {
|
|
13498
13500
|
...child.props,
|
|
13499
13501
|
key: child.key,
|
|
13500
|
-
"data-rerender-counter":
|
|
13502
|
+
"data-rerender-counter": counter,
|
|
13501
13503
|
})
|
|
13502
13504
|
: child) }));
|
|
13503
13505
|
};
|
|
@@ -13639,7 +13641,7 @@ const RouterContainer = ({ addTestRootContainer, selectedRouterProps, rootRoute,
|
|
|
13639
13641
|
defaultPendingMs: 0,
|
|
13640
13642
|
defaultPendingMinMs: 0, // Add this to control minimum pending time
|
|
13641
13643
|
context: {
|
|
13642
|
-
|
|
13644
|
+
hasAccessToHostRoute: async () => {
|
|
13643
13645
|
return true;
|
|
13644
13646
|
},
|
|
13645
13647
|
showMarketplace: true,
|
|
@@ -13652,7 +13654,7 @@ const RouterContainer = ({ addTestRootContainer, selectedRouterProps, rootRoute,
|
|
|
13652
13654
|
});
|
|
13653
13655
|
}, [rootRoute]);
|
|
13654
13656
|
const context = useMemo(() => ({
|
|
13655
|
-
|
|
13657
|
+
hasAccessToHostRoute: async () => true,
|
|
13656
13658
|
isAuthenticated: true,
|
|
13657
13659
|
client,
|
|
13658
13660
|
defaultUserRoute: "/",
|
|
@@ -13935,7 +13937,6 @@ class TrackunitProvidersMockBuilder {
|
|
|
13935
13937
|
* @returns { TrackunitProvidersMockBuilder } - The builder.
|
|
13936
13938
|
*/
|
|
13937
13939
|
userSubscription(userSubscription) {
|
|
13938
|
-
//TODO DON'T SUPPORT THE WEIRD WAY OF PASSING FEATURES
|
|
13939
13940
|
const featuresConverted = userSubscription.features?.map(f => {
|
|
13940
13941
|
if (typeof f === "string") {
|
|
13941
13942
|
return { id: f, name: f };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trackunit/react-core-contexts-test",
|
|
3
|
-
"version": "1.12.
|
|
3
|
+
"version": "1.12.42-alpha-57a40ea11fa.0",
|
|
4
4
|
"repository": "https://github.com/Trackunit/manager",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE.txt",
|
|
6
6
|
"engines": {
|
|
@@ -10,11 +10,11 @@
|
|
|
10
10
|
"@apollo/client": "3.13.8",
|
|
11
11
|
"react": "19.0.0",
|
|
12
12
|
"@tanstack/react-router": "1.114.29",
|
|
13
|
-
"@trackunit/shared-utils": "1.13.
|
|
13
|
+
"@trackunit/shared-utils": "1.13.58-alpha-57a40ea11fa.0",
|
|
14
14
|
"graphql": "^16.10.0",
|
|
15
15
|
"@tanstack/router-core": "1.114.29",
|
|
16
|
-
"@trackunit/iris-app-runtime-core-api": "1.12.
|
|
17
|
-
"@trackunit/react-core-contexts-api": "1.13.
|
|
16
|
+
"@trackunit/iris-app-runtime-core-api": "1.12.40-alpha-57a40ea11fa.0",
|
|
17
|
+
"@trackunit/react-core-contexts-api": "1.13.40-alpha-57a40ea11fa.0",
|
|
18
18
|
"es-toolkit": "^1.39.10"
|
|
19
19
|
},
|
|
20
20
|
"module": "./index.esm.js",
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { MockedResponse } from "@apollo/client/testing";
|
|
2
2
|
import { AnyRoute, RegisteredRouter } from "@tanstack/react-router";
|
|
3
3
|
import { RenderResult } from "@testing-library/react";
|
|
4
|
-
import { AnalyticsRuntimeApiSync, AssetSortingState, ConfirmationDialogRuntimeApi, CurrentUserPreferenceState, CurrentUserState, EnvironmentState, ErrorHandlingContextValue, FilterBarContext,
|
|
4
|
+
import { AnalyticsRuntimeApiSync, AssetSortingState, ConfirmationDialogRuntimeApi, CurrentUserPreferenceState, CurrentUserState, EnvironmentState, ErrorHandlingContextValue, FilterBarContext, ModalDialogRuntimeApi, NavigationRuntimeApi, OemBrandingRuntimeApi, TimeRangeContext, TokenContext, UserSubscription, WidgetConfigContext } from "@trackunit/iris-app-runtime-core-api";
|
|
5
5
|
import { ExportDataContextState, ToastContextValue } from "@trackunit/react-core-contexts-api";
|
|
6
6
|
import { ReactElement, ReactNode } from "react";
|
|
7
7
|
import { MemoryRouterProps } from "./utils/routingUtils";
|
|
@@ -1,7 +1,12 @@
|
|
|
1
|
-
import { ReactNode } from "react";
|
|
1
|
+
import { type ReactNode } from "react";
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
3
|
+
* Subscribes to RerenderContext so this subtree re-renders when the counter changes,
|
|
4
|
+
* even when nested inside React.memo boundaries (like TanStack Router's Match/MatchInner).
|
|
5
|
+
*
|
|
6
|
+
* Consuming the context alone is not enough: React will bail out of re-rendering children
|
|
7
|
+
* if the element references haven't changed. createElement produces new element instances
|
|
8
|
+
* with a changed prop, which forces React to reconcile and re-render the test component.
|
|
4
9
|
*/
|
|
5
10
|
export declare const RerenderComponent: ({ children }: {
|
|
6
11
|
children: ReactNode;
|
|
7
|
-
}) =>
|
|
12
|
+
}) => ReactNode;
|
|
@@ -1,15 +1,19 @@
|
|
|
1
1
|
import { ReactNode } from "react";
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
3
|
+
* Provides a rerender signal via context to force re-renders in tests.
|
|
4
|
+
* TanStack Router wraps Match/MatchInner in React.memo, which blocks RTL's rerender() from
|
|
5
|
+
* propagating to the hook under test. React context changes bypass React.memo boundaries,
|
|
6
|
+
* so changing the context value triggers a re-render in any descendant consuming RerenderContext.
|
|
7
|
+
*
|
|
8
|
+
* The value is intentionally wrapped in a new object on every render. This ensures the context
|
|
9
|
+
* identity always changes -- even when the external counter prop hasn't changed (e.g. during
|
|
10
|
+
* HookRenderer's automatic rerender) -- so consumers are always notified.
|
|
4
11
|
*/
|
|
5
12
|
export declare const RerenderProvider: ({ children, counter }: {
|
|
6
13
|
children: ReactNode;
|
|
7
14
|
counter: number;
|
|
8
|
-
}) =>
|
|
15
|
+
}) => ReactNode;
|
|
9
16
|
/**
|
|
10
|
-
*
|
|
17
|
+
* Returns the current rerender counter from context.
|
|
11
18
|
*/
|
|
12
|
-
export declare const useRerenderCounter: () =>
|
|
13
|
-
rerenderCounter: number;
|
|
14
|
-
setRerenderCounter: (value: number) => void;
|
|
15
|
-
};
|
|
19
|
+
export declare const useRerenderCounter: () => number;
|