akanjs 3.0.0 → 3.0.1

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.
@@ -177,7 +177,6 @@ export class CsrRouteTable {
177
177
  : {
178
178
  renderPage: routeRender,
179
179
  pageIncludesOwnLayout: parsed.leaf === "_index",
180
- isSpecialRoute: parsed.isSpecialRoute,
181
180
  pageConfig: (page as RouteModuleWithConfig).pageConfig,
182
181
  PageConfig: (page as RouteModuleWithConfig).pageConfig,
183
182
  }),
@@ -214,7 +213,6 @@ export class CsrRouteTable {
214
213
  renderPage: route.renderPage,
215
214
  renderRootLayouts: layer.pageRenderRootLayouts,
216
215
  renderLayouts: layer.pageRenderLayouts,
217
- isSpecialRoute: route.isSpecialRoute,
218
216
  pageState: route.pageState ?? pageState,
219
217
  pageConfigChain: finalPageConfigChain,
220
218
  explicitPageConfigKeys: getExplicitPageConfigKeys(finalPageConfigChain),
@@ -599,6 +599,7 @@ export const useCsrValues = (rootRouteGuide: RouteGuide, pathRoutes: PathRoute[]
599
599
  const onBack = useRef<{ [K in TransitionType]?: () => Promise<void> }>({});
600
600
  const frameRootRef = useRef<HTMLDivElement>(null);
601
601
  const lastBroadcastSyncHref = useRef<string | null>(null);
602
+ const syncNavigationReset = useRef<ReturnType<typeof setTimeout> | null>(null);
602
603
 
603
604
  const { getLocation } = useLocation({ rootRouteGuide });
604
605
  const [initialStack] = useState(() => {
@@ -848,7 +849,8 @@ export const useCsrValues = (rootRouteGuide: RouteGuide, pathRoutes: PathRoute[]
848
849
  });
849
850
  const applyingSyncNavigation = useRef(false);
850
851
  const broadcastSyncNavigation = useCallback((kind: "push" | "replace" | "back" | "pop", href: string) => {
851
- if (applyingSyncNavigation.current) return;
852
+ if (applyingSyncNavigation.current || lastBroadcastSyncHref.current === href) return;
853
+ lastBroadcastSyncHref.current = href;
852
854
  const syncNavigation = (
853
855
  globalThis as typeof globalThis & {
854
856
  __AKAN_DEV_SYNC_NAVIGATION__?: (href: string, kind: "push" | "replace" | "back" | "pop") => void;
@@ -1063,12 +1065,13 @@ export const useCsrValues = (rootRouteGuide: RouteGuide, pathRoutes: PathRoute[]
1063
1065
  if (!targetLocation) return;
1064
1066
  const location = getCurrentLocation();
1065
1067
  debugFrame("router.back", { from: location.href, to: targetLocation.href, scrollToTop });
1068
+
1069
+ broadcastSyncNavigation("back", getSyncRouteHref(targetLocation));
1066
1070
  if (shouldPrepareFrameTransition()) await startFrameTransition();
1067
1071
  await onBack.current[location.pathRoute.pageState.transition]?.();
1068
1072
  const scrollTop = pageContentRef.current?.scrollTop ?? 0;
1069
1073
  setHistoryBack({ type: "back", location, scrollTop, scrollToTop });
1070
1074
  settle(getPrevLocation());
1071
- broadcastSyncNavigation("back", getSyncRouteHref(targetLocation));
1072
1075
  window.history.back();
1073
1076
  },
1074
1077
  };
@@ -1102,19 +1105,18 @@ export const useCsrValues = (rootRouteGuide: RouteGuide, pathRoutes: PathRoute[]
1102
1105
  broadcastSyncNavigation("pop", getSyncRouteHref(getLocation(href)));
1103
1106
  return;
1104
1107
  }
1108
+ broadcastSyncNavigation(routeType === "back" ? "back" : "pop", getSyncRouteHref(getLocation(href)));
1105
1109
  if (routeType === "forward") {
1106
1110
  if (shouldPrepareFrameTransition(href)) await startFrameTransition();
1107
1111
  const location = getCurrentLocation();
1108
1112
  setHistoryForward({ type: "popForward", location, scrollTop });
1109
1113
  settle(location);
1110
- broadcastSyncNavigation("pop", getSyncRouteHref(getLocation(href)));
1111
1114
  } else {
1112
1115
  const location = getCurrentLocation();
1113
1116
  if (shouldPrepareFrameTransition(href)) await startFrameTransition();
1114
1117
  if (!isUaAnimated) await onBack.current[location.pathRoute.pageState.transition]?.();
1115
1118
  setHistoryBack({ type: "popBack", location, scrollTop });
1116
1119
  settle(getPrevLocation());
1117
- broadcastSyncNavigation("pop", getSyncRouteHref(getLocation(href)));
1118
1120
  }
1119
1121
  };
1120
1122
  return router;
@@ -1122,13 +1124,14 @@ export const useCsrValues = (rootRouteGuide: RouteGuide, pathRoutes: PathRoute[]
1122
1124
  const router = getRouter();
1123
1125
  useEffect(() => {
1124
1126
  const syncHref = getSyncRouteHref(resolvedLocation);
1125
- if (lastBroadcastSyncHref.current === null) {
1127
+ if (
1128
+ lastBroadcastSyncHref.current === null ||
1129
+ applyingSyncNavigation.current ||
1130
+ globalThis.__AKAN_DEV_SYNC_NAVIGATION_APPLYING__
1131
+ ) {
1126
1132
  lastBroadcastSyncHref.current = syncHref;
1127
1133
  return;
1128
1134
  }
1129
- if (lastBroadcastSyncHref.current === syncHref) return;
1130
- lastBroadcastSyncHref.current = syncHref;
1131
- if (applyingSyncNavigation.current || globalThis.__AKAN_DEV_SYNC_NAVIGATION_APPLYING__) return;
1132
1135
  broadcastSyncNavigation(
1133
1136
  history.current.type === "back" ? "back" : history.current.type === "forward" ? "push" : "pop",
1134
1137
  syncHref,
@@ -1141,8 +1144,10 @@ export const useCsrValues = (rootRouteGuide: RouteGuide, pathRoutes: PathRoute[]
1141
1144
  history,
1142
1145
  ]);
1143
1146
  useEffect(() => {
1147
+
1144
1148
  const resetSyncNavigation = () => {
1145
- window.setTimeout(() => {
1149
+ if (syncNavigationReset.current) clearTimeout(syncNavigationReset.current);
1150
+ syncNavigationReset.current = setTimeout(() => {
1146
1151
  applyingSyncNavigation.current = false;
1147
1152
  globalThis.__AKAN_DEV_SYNC_NAVIGATION_APPLYING__ = false;
1148
1153
  }, 1000);
@@ -1153,10 +1158,15 @@ export const useCsrValues = (rootRouteGuide: RouteGuide, pathRoutes: PathRoute[]
1153
1158
  if (!href) return;
1154
1159
  const target = new URL(href, window.location.origin);
1155
1160
  const targetHref = `${target.pathname}${target.search}${target.hash}`;
1156
- if (targetHref === getSyncRouteHref(getCurrentLocation())) return;
1161
+
1162
+ if (targetHref === getSyncRouteHref(getCurrentLocation()) || targetHref === lastBroadcastSyncHref.current) return;
1157
1163
  applyingSyncNavigation.current = true;
1158
1164
  globalThis.__AKAN_DEV_SYNC_NAVIGATION_APPLYING__ = true;
1159
- if (kind === "replace" || kind === "back" || kind === "pop")
1165
+ const previous = getPrevLocation();
1166
+
1167
+ if (kind !== "push" && kind !== "replace" && previous && getSyncRouteHref(previous) === targetHref)
1168
+ clientRouter.back({ scrollToTop: false });
1169
+ else if (kind === "replace" || kind === "back" || kind === "pop")
1160
1170
  clientRouter.replace(targetHref, { scrollToTop: false });
1161
1171
  else clientRouter.push(targetHref, { scrollToTop: false });
1162
1172
  resetSyncNavigation();