@trackunit/react-core-contexts-test 1.24.2 → 1.25.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/HookRenderer.cjs.js
CHANGED
|
@@ -26,7 +26,7 @@ require('graphql');
|
|
|
26
26
|
* @param getMockedCompositionRoot A function that will return the mocked composition root.
|
|
27
27
|
* @returns { Promise<RenderHookResult> } The rendered hook.
|
|
28
28
|
*/
|
|
29
|
-
const reactHooksRenderHook = async (callback, getMockedCompositionRoot) => {
|
|
29
|
+
const reactHooksRenderHook = async (callback, getMockedCompositionRoot, beforeAutomaticRerender) => {
|
|
30
30
|
const wrapper = ({ children }) => {
|
|
31
31
|
return getMockedCompositionRoot(children);
|
|
32
32
|
};
|
|
@@ -40,6 +40,7 @@ const reactHooksRenderHook = async (callback, getMockedCompositionRoot) => {
|
|
|
40
40
|
await index.act(async () => {
|
|
41
41
|
await index.flushPromises();
|
|
42
42
|
// rerender to make sure that all hooks can survive the rerender - this is like strict mode from react.
|
|
43
|
+
beforeAutomaticRerender?.();
|
|
43
44
|
renderedHook.rerender();
|
|
44
45
|
await index.flushPromises();
|
|
45
46
|
});
|
package/HookRenderer.esm.js
CHANGED
|
@@ -24,7 +24,7 @@ import 'graphql';
|
|
|
24
24
|
* @param getMockedCompositionRoot A function that will return the mocked composition root.
|
|
25
25
|
* @returns { Promise<RenderHookResult> } The rendered hook.
|
|
26
26
|
*/
|
|
27
|
-
const reactHooksRenderHook = async (callback, getMockedCompositionRoot) => {
|
|
27
|
+
const reactHooksRenderHook = async (callback, getMockedCompositionRoot, beforeAutomaticRerender) => {
|
|
28
28
|
const wrapper = ({ children }) => {
|
|
29
29
|
return getMockedCompositionRoot(children);
|
|
30
30
|
};
|
|
@@ -38,6 +38,7 @@ const reactHooksRenderHook = async (callback, getMockedCompositionRoot) => {
|
|
|
38
38
|
await act(async () => {
|
|
39
39
|
await flushPromises();
|
|
40
40
|
// rerender to make sure that all hooks can survive the rerender - this is like strict mode from react.
|
|
41
|
+
beforeAutomaticRerender?.();
|
|
41
42
|
renderedHook.rerender();
|
|
42
43
|
await flushPromises();
|
|
43
44
|
});
|
package/index2.cjs.js
CHANGED
|
@@ -13685,11 +13685,12 @@ const RerenderContext = React.createContext({ counter: 0 });
|
|
|
13685
13685
|
* propagating to the hook under test. React context changes bypass React.memo boundaries,
|
|
13686
13686
|
* so changing the context value triggers a re-render in any descendant consuming RerenderContext.
|
|
13687
13687
|
*
|
|
13688
|
-
* The value is
|
|
13689
|
-
* identity always changes -- even when the external counter prop hasn't changed (e.g. during
|
|
13690
|
-
* HookRenderer's automatic rerender) -- so consumers are always notified.
|
|
13688
|
+
* The value is memoized so consumers are only notified when the rerender counter changes.
|
|
13691
13689
|
*/
|
|
13692
|
-
const RerenderProvider = ({ children, counter }) =>
|
|
13690
|
+
const RerenderProvider = ({ children, counter }) => {
|
|
13691
|
+
const value = React.useMemo(() => ({ counter }), [counter]);
|
|
13692
|
+
return jsxRuntime.jsx(RerenderContext.Provider, { value: value, children: children });
|
|
13693
|
+
};
|
|
13693
13694
|
/**
|
|
13694
13695
|
* Returns the current rerender counter from context.
|
|
13695
13696
|
*/
|
|
@@ -14439,7 +14440,9 @@ class TrackunitProvidersMockBuilder {
|
|
|
14439
14440
|
// This ensures correct act loading when using hooks and not loaded if this build is used for storybook
|
|
14440
14441
|
const hookRenderer = await Promise.resolve().then(function () { return require('./HookRenderer.cjs.js'); });
|
|
14441
14442
|
let rerenderCounter = 0;
|
|
14442
|
-
const renderedHook = await hookRenderer.reactHooksRenderHook(callback, children => this.getMockedCompositionRoot(jsxRuntime.jsx(RerenderProvider, { counter: rerenderCounter, children: jsxRuntime.jsx(RouterContainer, { addTestRootContainer: true, rootRoute: this.selectedRootRoute, selectedRouterProps: this.selectedRouterProps, children: jsxRuntime.jsx(RerenderComponent, { children: parentElement ? parentElement(children) : children }) }) })))
|
|
14443
|
+
const renderedHook = await hookRenderer.reactHooksRenderHook(callback, children => this.getMockedCompositionRoot(jsxRuntime.jsx(RerenderProvider, { counter: rerenderCounter, children: jsxRuntime.jsx(RouterContainer, { addTestRootContainer: true, rootRoute: this.selectedRootRoute, selectedRouterProps: this.selectedRouterProps, children: jsxRuntime.jsx(RerenderComponent, { children: parentElement ? parentElement(children) : children }) }) })), () => {
|
|
14444
|
+
rerenderCounter += 1;
|
|
14445
|
+
});
|
|
14443
14446
|
return {
|
|
14444
14447
|
...renderedHook,
|
|
14445
14448
|
rerender: async (props) => {
|
package/index2.esm.js
CHANGED
|
@@ -13663,11 +13663,12 @@ const RerenderContext = createContext({ counter: 0 });
|
|
|
13663
13663
|
* propagating to the hook under test. React context changes bypass React.memo boundaries,
|
|
13664
13664
|
* so changing the context value triggers a re-render in any descendant consuming RerenderContext.
|
|
13665
13665
|
*
|
|
13666
|
-
* The value is
|
|
13667
|
-
* identity always changes -- even when the external counter prop hasn't changed (e.g. during
|
|
13668
|
-
* HookRenderer's automatic rerender) -- so consumers are always notified.
|
|
13666
|
+
* The value is memoized so consumers are only notified when the rerender counter changes.
|
|
13669
13667
|
*/
|
|
13670
|
-
const RerenderProvider = ({ children, counter }) =>
|
|
13668
|
+
const RerenderProvider = ({ children, counter }) => {
|
|
13669
|
+
const value = useMemo(() => ({ counter }), [counter]);
|
|
13670
|
+
return jsx(RerenderContext.Provider, { value: value, children: children });
|
|
13671
|
+
};
|
|
13671
13672
|
/**
|
|
13672
13673
|
* Returns the current rerender counter from context.
|
|
13673
13674
|
*/
|
|
@@ -14417,7 +14418,9 @@ class TrackunitProvidersMockBuilder {
|
|
|
14417
14418
|
// This ensures correct act loading when using hooks and not loaded if this build is used for storybook
|
|
14418
14419
|
const hookRenderer = await import('./HookRenderer.esm.js');
|
|
14419
14420
|
let rerenderCounter = 0;
|
|
14420
|
-
const renderedHook = await hookRenderer.reactHooksRenderHook(callback, children => this.getMockedCompositionRoot(jsx(RerenderProvider, { counter: rerenderCounter, children: jsx(RouterContainer, { addTestRootContainer: true, rootRoute: this.selectedRootRoute, selectedRouterProps: this.selectedRouterProps, children: jsx(RerenderComponent, { children: parentElement ? parentElement(children) : children }) }) })))
|
|
14421
|
+
const renderedHook = await hookRenderer.reactHooksRenderHook(callback, children => this.getMockedCompositionRoot(jsx(RerenderProvider, { counter: rerenderCounter, children: jsx(RouterContainer, { addTestRootContainer: true, rootRoute: this.selectedRootRoute, selectedRouterProps: this.selectedRouterProps, children: jsx(RerenderComponent, { children: parentElement ? parentElement(children) : children }) }) })), () => {
|
|
14422
|
+
rerenderCounter += 1;
|
|
14423
|
+
});
|
|
14421
14424
|
return {
|
|
14422
14425
|
...renderedHook,
|
|
14423
14426
|
rerender: async (props) => {
|
package/package.json
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trackunit/react-core-contexts-test",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.25.0",
|
|
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.
|
|
10
|
+
"@trackunit/shared-utils": "1.22.0",
|
|
11
11
|
"@tanstack/router-core": "1.114.29",
|
|
12
|
-
"@trackunit/iris-app-runtime-core-api": "1.
|
|
13
|
-
"@trackunit/react-core-contexts-api": "1.
|
|
12
|
+
"@trackunit/iris-app-runtime-core-api": "1.24.0",
|
|
13
|
+
"@trackunit/react-core-contexts-api": "1.25.0",
|
|
14
14
|
"es-toolkit": "^1.52.0"
|
|
15
15
|
},
|
|
16
16
|
"peerDependencies": {
|
package/src/HookRenderer.d.ts
CHANGED
|
@@ -8,4 +8,4 @@ import { ReactElement, ReactNode } from "react";
|
|
|
8
8
|
* @param getMockedCompositionRoot A function that will return the mocked composition root.
|
|
9
9
|
* @returns { Promise<RenderHookResult> } The rendered hook.
|
|
10
10
|
*/
|
|
11
|
-
export declare const reactHooksRenderHook: <TProps, TResult>(callback: (props: TProps) => TResult, getMockedCompositionRoot: (children: ReactNode) => ReactElement) => Promise<RenderHookResult<TResult, TProps>>;
|
|
11
|
+
export declare const reactHooksRenderHook: <TProps, TResult>(callback: (props: TProps) => TResult, getMockedCompositionRoot: (children: ReactNode) => ReactElement, beforeAutomaticRerender?: () => void) => Promise<RenderHookResult<TResult, TProps>>;
|
|
@@ -5,9 +5,7 @@ import { ReactNode } from "react";
|
|
|
5
5
|
* propagating to the hook under test. React context changes bypass React.memo boundaries,
|
|
6
6
|
* so changing the context value triggers a re-render in any descendant consuming RerenderContext.
|
|
7
7
|
*
|
|
8
|
-
* The value is
|
|
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.
|
|
8
|
+
* The value is memoized so consumers are only notified when the rerender counter changes.
|
|
11
9
|
*/
|
|
12
10
|
export declare const RerenderProvider: ({ children, counter }: {
|
|
13
11
|
children: ReactNode;
|