@jsenv/navi 0.16.35 → 0.16.36

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.
@@ -10291,6 +10291,9 @@ const resolveRouteUrl = (relativeUrl) => {
10291
10291
  */
10292
10292
 
10293
10293
 
10294
+ // Flag to prevent signal-to-URL synchronization during URL-to-signal synchronization
10295
+ let isUpdatingRoutesFromUrl = false;
10296
+
10294
10297
  // Controls what happens to actions when their route stops matching:
10295
10298
  // 'abort' - Cancel the action immediately when route stops matching
10296
10299
  // 'keep-loading' - Allow action to continue running after route stops matching
@@ -10386,6 +10389,9 @@ const updateRoutes = (
10386
10389
  }
10387
10390
 
10388
10391
  // URL -> Signal synchronization (moved from individual route effects to eliminate circular dependency)
10392
+ // Prevent signal-to-URL synchronization during URL-to-signal synchronization
10393
+ isUpdatingRoutesFromUrl = true;
10394
+
10389
10395
  for (const {
10390
10396
  route,
10391
10397
  routePrivateProperties,
@@ -10539,6 +10545,9 @@ const updateRoutes = (
10539
10545
  }
10540
10546
  });
10541
10547
 
10548
+ // Reset flag after URL -> Signal synchronization is complete
10549
+ isUpdatingRoutesFromUrl = false;
10550
+
10542
10551
  // must be after paramsSignal.value update to ensure the proxy target is set
10543
10552
  // (so after the batch call)
10544
10553
  const toLoadSet = new Set();
@@ -10739,12 +10748,19 @@ const registerRoute = (routePattern) => {
10739
10748
  }
10740
10749
  // Signal -> URL sync: When signal changes, update URL to reflect meaningful state
10741
10750
  // Only sync non-default values to keep URLs clean (static fallbacks stay invisible)
10751
+ // eslint-disable-next-line no-loop-func
10742
10752
  effect(() => {
10743
10753
  const value = paramSignal.value;
10744
10754
  const params = rawParamsSignal.value;
10745
10755
  const urlParamValue = params[paramName];
10746
10756
  const matching = matchingSignal.value;
10747
10757
 
10758
+ // Signal returned to default - clean up URL by removing the parameter
10759
+ // Skip cleanup during URL-to-signal synchronization to prevent recursion
10760
+ if (isUpdatingRoutesFromUrl) {
10761
+ return;
10762
+ }
10763
+
10748
10764
  if (!matching) {
10749
10765
  // Route not matching, no URL sync needed
10750
10766
  return;
@@ -10764,6 +10780,19 @@ const registerRoute = (routePattern) => {
10764
10780
  route.replaceParams({ [paramName]: value });
10765
10781
  return;
10766
10782
  }
10783
+
10784
+ // URL parameter exists - check if we need to update or clean it up
10785
+ const defaultValue = connection.getDefaultValue();
10786
+ if (value === defaultValue) {
10787
+ if (debug) {
10788
+ console.debug(
10789
+ `[route] Signal->URL: ${paramName} cleaning URL (removing default value ${value})`,
10790
+ );
10791
+ }
10792
+ route.replaceParams({ [paramName]: undefined });
10793
+ return;
10794
+ }
10795
+
10767
10796
  if (value === urlParamValue) {
10768
10797
  // Values already match, no sync needed
10769
10798
  return;
@@ -10778,17 +10807,17 @@ const registerRoute = (routePattern) => {
10778
10807
  }
10779
10808
 
10780
10809
  route.navTo = (params) => {
10781
- if (!browserIntegration$1) {
10810
+ if (!integration) {
10782
10811
  return Promise.resolve();
10783
10812
  }
10784
10813
  const routeUrl = route.buildUrl(params);
10785
- return browserIntegration$1.navTo(routeUrl);
10814
+ return integration.navTo(routeUrl);
10786
10815
  };
10787
10816
  route.redirectTo = (params) => {
10788
- if (!browserIntegration$1) {
10817
+ if (!integration) {
10789
10818
  return Promise.resolve();
10790
10819
  }
10791
- return browserIntegration$1.navTo(route.buildUrl(params), {
10820
+ return integration.navTo(route.buildUrl(params), {
10792
10821
  replace: true,
10793
10822
  });
10794
10823
  };
@@ -10952,9 +10981,9 @@ const useRouteStatus = (route) => {
10952
10981
  };
10953
10982
  };
10954
10983
 
10955
- let browserIntegration$1;
10956
- const setBrowserIntegration = (integration) => {
10957
- browserIntegration$1 = integration;
10984
+ let integration;
10985
+ const setRouteIntegration = (integrationInterface) => {
10986
+ integration = integrationInterface;
10958
10987
  };
10959
10988
  let onRouteDefined = () => {};
10960
10989
  const setOnRouteDefined = (v) => {
@@ -11539,7 +11568,7 @@ const browserIntegration = setupBrowserIntegrationViaHistory({
11539
11568
  setOnRouteDefined(() => {
11540
11569
  browserIntegration.init();
11541
11570
  });
11542
- setBrowserIntegration(browserIntegration);
11571
+ setRouteIntegration(browserIntegration);
11543
11572
 
11544
11573
  const actionIntegratedVia = browserIntegration.integration;
11545
11574
  const navTo = (target, options) => {