@trackunit/react-core-contexts-test 1.3.163 → 1.3.166

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.
Files changed (3) hide show
  1. package/index.cjs.js +18 -10
  2. package/index.esm.js +18 -10
  3. package/package.json +4 -4
package/index.cjs.js CHANGED
@@ -312,7 +312,19 @@ const RouterContainer = ({ addTestRootContainer, selectedRouterProps, rootRoute,
312
312
  initialEntries: selectedRouterProps?.initialEntries?.reverse().map(entry => entry.path + "#") ?? ["/#"],
313
313
  initialIndex: 0,
314
314
  }));
315
+ const addTestRootContainerRef = React.useRef(addTestRootContainer);
316
+ React.useEffect(() => {
317
+ addTestRootContainerRef.current = addTestRootContainer;
318
+ }, [addTestRootContainer]);
315
319
  const getChildren = React.useCallback(() => children, [children]);
320
+ const childrenRef = React.useRef(() => getChildren());
321
+ React.useEffect(() => {
322
+ childrenRef.current = () => getChildren();
323
+ }, [getChildren]);
324
+ const initialEntriesRef = React.useRef(selectedRouterProps?.initialEntries);
325
+ React.useEffect(() => {
326
+ initialEntriesRef.current = selectedRouterProps?.initialEntries;
327
+ }, [selectedRouterProps?.initialEntries]);
316
328
  const router = React.useMemo(() => {
317
329
  let localRootRoute = rootRoute;
318
330
  if (!localRootRoute) {
@@ -321,7 +333,7 @@ const RouterContainer = ({ addTestRootContainer, selectedRouterProps, rootRoute,
321
333
  path: "/",
322
334
  getParentRoute: () => route,
323
335
  component: () => {
324
- return jsxRuntime.jsx(TestRenderChildren, { addTestRootContainer: addTestRootContainer, children: getChildren() });
336
+ return (jsxRuntime.jsx(TestRenderChildren, { addTestRootContainer: addTestRootContainerRef.current, children: childrenRef.current() }));
325
337
  },
326
338
  });
327
339
  route.addChildren([childRoute]);
@@ -342,8 +354,8 @@ const RouterContainer = ({ addTestRootContainer, selectedRouterProps, rootRoute,
342
354
  // This ensures / is not redirecting to default home route
343
355
  pathsToRoute["/"].options.beforeLoad = () => { };
344
356
  }
345
- if ((selectedRouterProps?.initialEntries?.length || 0) > 0) {
346
- selectedRouterProps?.initialEntries?.forEach(entry => {
357
+ if ((initialEntriesRef.current?.length || 0) > 0) {
358
+ initialEntriesRef.current?.forEach(entry => {
347
359
  const route = pathsToRoute[entry.route];
348
360
  if (route) {
349
361
  if (entry.beforeLoad) {
@@ -355,7 +367,7 @@ const RouterContainer = ({ addTestRootContainer, selectedRouterProps, rootRoute,
355
367
  else {
356
368
  route.update({
357
369
  component: () => {
358
- return (jsxRuntime.jsx(TestRenderChildren, { addTestRootContainer: addTestRootContainer, children: getChildren() }));
370
+ return (jsxRuntime.jsx(TestRenderChildren, { addTestRootContainer: addTestRootContainerRef.current, children: childrenRef.current() }));
359
371
  },
360
372
  });
361
373
  }
@@ -365,14 +377,14 @@ const RouterContainer = ({ addTestRootContainer, selectedRouterProps, rootRoute,
365
377
  else {
366
378
  const slashRoute = pathsToRoute["/"];
367
379
  if (slashRoute) {
368
- slashRoute.options.component = () => (jsxRuntime.jsx(TestRenderChildren, { addTestRootContainer: addTestRootContainer, children: getChildren() }));
380
+ slashRoute.options.component = () => (jsxRuntime.jsx(TestRenderChildren, { addTestRootContainer: addTestRootContainerRef.current, children: childrenRef.current() }));
369
381
  }
370
382
  else {
371
383
  const childRoute = reactRouter.createRoute({
372
384
  path: "/",
373
385
  getParentRoute: () => localRootRoute,
374
386
  component: () => {
375
- return (jsxRuntime.jsx(TestRenderChildren, { addTestRootContainer: addTestRootContainer, children: getChildren() }));
387
+ return (jsxRuntime.jsx(TestRenderChildren, { addTestRootContainer: addTestRootContainerRef.current, children: childrenRef.current() }));
376
388
  },
377
389
  });
378
390
  localRootRoute.addChildren([childRoute]);
@@ -396,10 +408,6 @@ const RouterContainer = ({ addTestRootContainer, selectedRouterProps, rootRoute,
396
408
  isAuthenticated: true,
397
409
  },
398
410
  });
399
- // Skipping this rule for now.
400
- // Explicit calls to rerender() will create a new router as `children` is changed.
401
- // This causes unexpected state updates in Tanstack router which make the test fail
402
- // eslint-disable-next-line react-hooks/react-compiler, react-hooks/exhaustive-deps
403
411
  }, [rootRoute]);
404
412
  const context = React.useMemo(() => ({
405
413
  hasAccessTo: async () => true,
package/index.esm.js CHANGED
@@ -310,7 +310,19 @@ const RouterContainer = ({ addTestRootContainer, selectedRouterProps, rootRoute,
310
310
  initialEntries: selectedRouterProps?.initialEntries?.reverse().map(entry => entry.path + "#") ?? ["/#"],
311
311
  initialIndex: 0,
312
312
  }));
313
+ const addTestRootContainerRef = useRef(addTestRootContainer);
314
+ useEffect(() => {
315
+ addTestRootContainerRef.current = addTestRootContainer;
316
+ }, [addTestRootContainer]);
313
317
  const getChildren = useCallback(() => children, [children]);
318
+ const childrenRef = useRef(() => getChildren());
319
+ useEffect(() => {
320
+ childrenRef.current = () => getChildren();
321
+ }, [getChildren]);
322
+ const initialEntriesRef = useRef(selectedRouterProps?.initialEntries);
323
+ useEffect(() => {
324
+ initialEntriesRef.current = selectedRouterProps?.initialEntries;
325
+ }, [selectedRouterProps?.initialEntries]);
314
326
  const router = useMemo(() => {
315
327
  let localRootRoute = rootRoute;
316
328
  if (!localRootRoute) {
@@ -319,7 +331,7 @@ const RouterContainer = ({ addTestRootContainer, selectedRouterProps, rootRoute,
319
331
  path: "/",
320
332
  getParentRoute: () => route,
321
333
  component: () => {
322
- return jsx(TestRenderChildren, { addTestRootContainer: addTestRootContainer, children: getChildren() });
334
+ return (jsx(TestRenderChildren, { addTestRootContainer: addTestRootContainerRef.current, children: childrenRef.current() }));
323
335
  },
324
336
  });
325
337
  route.addChildren([childRoute]);
@@ -340,8 +352,8 @@ const RouterContainer = ({ addTestRootContainer, selectedRouterProps, rootRoute,
340
352
  // This ensures / is not redirecting to default home route
341
353
  pathsToRoute["/"].options.beforeLoad = () => { };
342
354
  }
343
- if ((selectedRouterProps?.initialEntries?.length || 0) > 0) {
344
- selectedRouterProps?.initialEntries?.forEach(entry => {
355
+ if ((initialEntriesRef.current?.length || 0) > 0) {
356
+ initialEntriesRef.current?.forEach(entry => {
345
357
  const route = pathsToRoute[entry.route];
346
358
  if (route) {
347
359
  if (entry.beforeLoad) {
@@ -353,7 +365,7 @@ const RouterContainer = ({ addTestRootContainer, selectedRouterProps, rootRoute,
353
365
  else {
354
366
  route.update({
355
367
  component: () => {
356
- return (jsx(TestRenderChildren, { addTestRootContainer: addTestRootContainer, children: getChildren() }));
368
+ return (jsx(TestRenderChildren, { addTestRootContainer: addTestRootContainerRef.current, children: childrenRef.current() }));
357
369
  },
358
370
  });
359
371
  }
@@ -363,14 +375,14 @@ const RouterContainer = ({ addTestRootContainer, selectedRouterProps, rootRoute,
363
375
  else {
364
376
  const slashRoute = pathsToRoute["/"];
365
377
  if (slashRoute) {
366
- slashRoute.options.component = () => (jsx(TestRenderChildren, { addTestRootContainer: addTestRootContainer, children: getChildren() }));
378
+ slashRoute.options.component = () => (jsx(TestRenderChildren, { addTestRootContainer: addTestRootContainerRef.current, children: childrenRef.current() }));
367
379
  }
368
380
  else {
369
381
  const childRoute = createRoute({
370
382
  path: "/",
371
383
  getParentRoute: () => localRootRoute,
372
384
  component: () => {
373
- return (jsx(TestRenderChildren, { addTestRootContainer: addTestRootContainer, children: getChildren() }));
385
+ return (jsx(TestRenderChildren, { addTestRootContainer: addTestRootContainerRef.current, children: childrenRef.current() }));
374
386
  },
375
387
  });
376
388
  localRootRoute.addChildren([childRoute]);
@@ -394,10 +406,6 @@ const RouterContainer = ({ addTestRootContainer, selectedRouterProps, rootRoute,
394
406
  isAuthenticated: true,
395
407
  },
396
408
  });
397
- // Skipping this rule for now.
398
- // Explicit calls to rerender() will create a new router as `children` is changed.
399
- // This causes unexpected state updates in Tanstack router which make the test fail
400
- // eslint-disable-next-line react-hooks/react-compiler, react-hooks/exhaustive-deps
401
409
  }, [rootRoute]);
402
410
  const context = useMemo(() => ({
403
411
  hasAccessTo: async () => true,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trackunit/react-core-contexts-test",
3
- "version": "1.3.163",
3
+ "version": "1.3.166",
4
4
  "repository": "https://github.com/Trackunit/manager",
5
5
  "license": "SEE LICENSE IN LICENSE.txt",
6
6
  "engines": {
@@ -14,9 +14,9 @@
14
14
  "graphql": "^16.10.0",
15
15
  "@tanstack/react-router": "1.114.29",
16
16
  "@tanstack/router-core": "1.114.29",
17
- "@trackunit/react-core-contexts-api": "1.4.156",
18
- "@trackunit/react-core-hooks": "1.3.162",
19
- "@trackunit/shared-utils": "1.5.148"
17
+ "@trackunit/react-core-contexts-api": "1.4.158",
18
+ "@trackunit/react-core-hooks": "1.3.164",
19
+ "@trackunit/shared-utils": "1.5.150"
20
20
  },
21
21
  "module": "./index.esm.js",
22
22
  "main": "./index.cjs.js",