@qwik.dev/router 2.0.0-beta.30 → 2.0.0-beta.32

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.
@@ -1,6 +1,6 @@
1
- import { componentQrl, inlinedQrl, useErrorBoundary, useOnWindow, _captures, _jsxSorted, Slot, useSignal, untrack, _qrlSync, useVisibleTaskQrl, isDev, _jsxSplit, _getConstProps, _getVarProps, eventQrl, isServer, useStylesQrl, useServerData, useStore, useContextProvider, useTaskQrl, isBrowser, getLocale, noSerialize, useContext, SkipRender, implicit$FirstArg, withLocale, _wrapProp, _restProps, _fnSignal, createElement } from '@qwik.dev/core';
1
+ import { componentQrl, inlinedQrl, useErrorBoundary, useOnWindow, _captures, _jsxSorted, Slot, useSignal, untrack, _qrlSync, useVisibleTaskQrl, isDev, _jsxSplit, _getConstProps, _getVarProps, eventQrl, isServer, useStylesQrl, useServerData, useStore, useContextProvider, useTaskQrl, getLocale, noSerialize, isBrowser, useContext, SkipRender, implicit$FirstArg, withLocale, _wrapProp, _restProps, _fnSignal, createElement } from '@qwik.dev/core';
2
2
  import { Fragment } from '@qwik.dev/core/jsx-runtime';
3
- import { g as getClientNavPath, s as shouldPreload, p as preloadRouteBundles, l as loadClientData, i as isSamePath, c as createLoaderSignal, a as createDocumentHead, D as DEFAULT_LOADERS_SERIALIZATION_STRATEGY, t as toUrl, b as isSameOrigin, d as clientNavigate, e as loadRoute, r as resolveHead, C as CLIENT_DATA_CACHE, Q as Q_ROUTE, f as toPath, h as QFN_KEY, j as QACTION_KEY, k as QDATA_KEY } from './chunks/routing.qwik.mjs';
3
+ import { g as getClientNavPath, s as shouldPreload, p as preloadRouteBundles, l as loadClientData, i as isSamePath, c as createLoaderSignal, a as createDocumentHead, b as loadRoute, r as resolveHead, C as CLIENT_DATA_CACHE, d as isSameOrigin, Q as Q_ROUTE, D as DEFAULT_LOADERS_SERIALIZATION_STRATEGY, t as toUrl, e as clientNavigate, f as toPath, h as QFN_KEY, j as QACTION_KEY, k as QDATA_KEY } from './chunks/routing.qwik.mjs';
4
4
  import { u as useNavigate, a as useLocation, b as useQwikRouterEnv, C as ContentContext, c as ContentInternalContext, D as DocumentHeadContext, H as HttpStatusContext, R as RouteLocationContext, d as RouteNavigateContext, e as RouteStateContext, f as RouteActionContext, g as RoutePreventNavigateContext, h as useAction, i as useDocumentHead } from './chunks/use-functions.qwik.mjs';
5
5
  export { j as useContent, k as useHttpStatus, l as usePreventNavigate$, m as usePreventNavigateQrl } from './chunks/use-functions.qwik.mjs';
6
6
  import * as qwikRouterConfig from '@qwik-router-config';
@@ -176,9 +176,27 @@ const saveScrollHistory = (scrollState) => {
176
176
  history.replaceState(state, "");
177
177
  };
178
178
 
179
+ const Q_ROUTER_POPSTATE_EVENT = "qrouterpopstate";
180
+ const createCurrentPathTracker = (initialPath) => {
181
+ let currentPath = initialPath;
182
+ return (nextPath) => {
183
+ if (currentPath !== nextPath) {
184
+ currentPath = nextPath;
185
+ return true;
186
+ }
187
+ return false;
188
+ };
189
+ };
190
+ const dispatchRouterPopstate = (document1, href) => {
191
+ document1.dispatchEvent(new CustomEvent(Q_ROUTER_POPSTATE_EVENT, {
192
+ detail: {
193
+ href
194
+ }
195
+ }));
196
+ };
179
197
  const spaInit = eventQrl(/* @__PURE__ */ inlinedQrl((_, el) => {
180
198
  if (!window._qRouterSPA && !window._qRouterInitPopstate) {
181
- const currentPath = location.pathname + location.search;
199
+ const hasPathChanged = createCurrentPathTracker(location.pathname + location.search);
182
200
  const checkAndScroll = (scrollState) => {
183
201
  if (scrollState) {
184
202
  window.scrollTo(scrollState.x, scrollState.y);
@@ -205,21 +223,8 @@ const spaInit = eventQrl(/* @__PURE__ */ inlinedQrl((_, el) => {
205
223
  }
206
224
  window._qRouterScrollEnabled = false;
207
225
  clearTimeout(window._qRouterScrollDebounce);
208
- if (currentPath !== location.pathname + location.search) {
209
- const getContainer = (el2) => el2.closest("[q\\:container]:not([q\\:container=html]):not([q\\:container=text])");
210
- const container = getContainer(el);
211
- const domContainer = container.qContainer;
212
- const hostElement = domContainer.vNodeLocate(el);
213
- const nav = domContainer?.resolveContext(hostElement, {
214
- id: "qr-n"
215
- });
216
- if (nav) {
217
- nav(location.href, {
218
- type: "popstate"
219
- });
220
- } else {
221
- location.reload();
222
- }
226
+ if (hasPathChanged(location.pathname + location.search)) {
227
+ dispatchRouterPopstate(document, location.href);
223
228
  } else {
224
229
  if (history.scrollRestoration === "manual") {
225
230
  const scrollState = history.state?._qRouterScroll;
@@ -366,6 +371,7 @@ const useQwikRouter = (props) => {
366
371
  throw new Error(`Missing Qwik URL Env Data`);
367
372
  }
368
373
  const serverHead = useServerData("documentHead");
374
+ const manifestHash = useServerData("containerAttributes")?.["q:manifest-hash"];
369
375
  if (env.ev.originalUrl.pathname !== env.ev.url.pathname && !__EXPERIMENTAL__.enableRequestRewrite) {
370
376
  throw new Error(`enableRequestRewrite is an experimental feature and is not enabled. Please enable the feature flag by adding \`experimental: ["enableRequestRewrite"]\` to your qwikVite plugin options.`);
371
377
  }
@@ -402,7 +408,7 @@ const useQwikRouter = (props) => {
402
408
  dest: url,
403
409
  scroll: true
404
410
  });
405
- const documentHead = useStore(() => createDocumentHead(serverHead));
411
+ const documentHead = useStore(() => createDocumentHead(serverHead, manifestHash));
406
412
  const content = useStore({
407
413
  headings: void 0,
408
414
  menu: void 0
@@ -560,9 +566,10 @@ const useQwikRouter = (props) => {
560
566
  useContextProvider(RouteStateContext, loaderState);
561
567
  useContextProvider(RouteActionContext, actionState);
562
568
  useContextProvider(RoutePreventNavigateContext, registerPreventNav);
563
- useTaskQrl(/* @__PURE__ */ inlinedQrl(({ track }) => {
564
- const actionState2 = _captures[0], content2 = _captures[1], contentInternal2 = _captures[2], documentHead2 = _captures[3], env2 = _captures[4], getScroller2 = _captures[5], goto2 = _captures[6], httpStatus2 = _captures[7], loaderState2 = _captures[8], loadersObject2 = _captures[9], navResolver2 = _captures[10], props2 = _captures[11], routeInternal2 = _captures[12], routeLocation2 = _captures[13], routeLocationTarget2 = _captures[14], serverHead2 = _captures[15];
565
- async function run() {
569
+ useTaskQrl(
570
+ /* @__PURE__ */ inlinedQrl(async ({ track }) => {
571
+ const actionState2 = _captures[0], content2 = _captures[1], contentInternal2 = _captures[2], documentHead2 = _captures[3], env2 = _captures[4], getScroller2 = _captures[5], goto2 = _captures[6], httpStatus2 = _captures[7], loaderState2 = _captures[8], loadersObject2 = _captures[9], navResolver2 = _captures[10], props2 = _captures[11], routeInternal2 = _captures[12], routeLocation2 = _captures[13], routeLocationTarget2 = _captures[14], serverHead2 = _captures[15];
572
+ const container2 = _getContextContainer();
566
573
  const navigation = track(routeInternal2);
567
574
  const action = track(actionState2);
568
575
  const locale = getLocale("");
@@ -571,8 +578,7 @@ const useQwikRouter = (props) => {
571
578
  const replaceState = navigation.replaceState;
572
579
  let trackUrl;
573
580
  let clientPageData;
574
- let loadedRoute = null;
575
- let container2;
581
+ let loadedRoute;
576
582
  if (isServer) {
577
583
  trackUrl = new URL(navigation.dest, routeLocation2.url);
578
584
  loadedRoute = env2.loadedRoute;
@@ -587,7 +593,6 @@ const useQwikRouter = (props) => {
587
593
  trackUrl.pathname += "/";
588
594
  }
589
595
  let loadRoutePromise = loadRoute(qwikRouterConfig.routes, qwikRouterConfig.cacheModules, trackUrl.pathname);
590
- container2 = _getContextContainer();
591
596
  const pageData = clientPageData = await loadClientData(trackUrl, {
592
597
  action,
593
598
  clearCache: true
@@ -620,271 +625,267 @@ const useQwikRouter = (props) => {
620
625
  return;
621
626
  }
622
627
  }
623
- if (loadedRoute) {
624
- const { $routeName$, $params$, $mods$, $menu$, $notFound$ } = loadedRoute;
625
- const contentModules = $mods$;
626
- if ($notFound$) {
627
- httpStatus2.value = {
628
- status: 404,
629
- message: "Not Found"
630
- };
631
- } else {
632
- httpStatus2.value = {
633
- status: clientPageData?.status ?? 200,
634
- message: clientPageData?.statusMessage ?? ""
635
- };
628
+ const { $routeName$, $params$, $mods$, $menu$, $notFound$ } = loadedRoute;
629
+ const contentModules = $mods$;
630
+ if ($notFound$) {
631
+ httpStatus2.value = {
632
+ status: 404,
633
+ message: "Not Found"
634
+ };
635
+ } else {
636
+ httpStatus2.value = {
637
+ status: clientPageData?.status ?? 200,
638
+ message: clientPageData?.statusMessage ?? ""
639
+ };
640
+ }
641
+ const pageModule = contentModules[contentModules.length - 1];
642
+ if (navigation.dest.search && !!isSamePath(trackUrl, prevUrl)) {
643
+ trackUrl.search = navigation.dest.search;
644
+ }
645
+ let shouldForcePrevUrl = false;
646
+ let shouldForceUrl = false;
647
+ let shouldForceParams = false;
648
+ if (!isSamePath(trackUrl, prevUrl)) {
649
+ if (_hasStoreEffects(routeLocation2, "prevUrl")) {
650
+ shouldForcePrevUrl = true;
636
651
  }
637
- const pageModule = contentModules[contentModules.length - 1];
638
- if (navigation.dest.search && !!isSamePath(trackUrl, prevUrl)) {
639
- trackUrl.search = navigation.dest.search;
652
+ routeLocationTarget2.prevUrl = prevUrl;
653
+ }
654
+ if (routeLocationTarget2.url !== trackUrl) {
655
+ if (_hasStoreEffects(routeLocation2, "url")) {
656
+ shouldForceUrl = true;
640
657
  }
641
- let shouldForcePrevUrl = false;
642
- let shouldForceUrl = false;
643
- let shouldForceParams = false;
644
- if (!isSamePath(trackUrl, prevUrl)) {
645
- if (_hasStoreEffects(routeLocation2, "prevUrl")) {
646
- shouldForcePrevUrl = true;
647
- }
648
- routeLocationTarget2.prevUrl = prevUrl;
658
+ routeLocationTarget2.url = trackUrl;
659
+ }
660
+ if (routeLocationTarget2.params !== $params$) {
661
+ if (_hasStoreEffects(routeLocation2, "params")) {
662
+ shouldForceParams = true;
649
663
  }
650
- if (routeLocationTarget2.url !== trackUrl) {
651
- if (_hasStoreEffects(routeLocation2, "url")) {
652
- shouldForceUrl = true;
653
- }
654
- routeLocationTarget2.url = trackUrl;
664
+ routeLocationTarget2.params = $params$;
665
+ }
666
+ routeInternal2.untrackedValue = {
667
+ type: navType,
668
+ dest: trackUrl
669
+ };
670
+ const resolvedHead = resolveHead(clientPageData, routeLocation2, contentModules, locale, serverHead2);
671
+ content2.headings = pageModule.headings;
672
+ content2.menu = $menu$;
673
+ contentInternal2.untrackedValue = noSerialize(contentModules);
674
+ documentHead2.links = resolvedHead.links;
675
+ documentHead2.meta = resolvedHead.meta;
676
+ documentHead2.styles = resolvedHead.styles;
677
+ documentHead2.scripts = resolvedHead.scripts;
678
+ documentHead2.title = resolvedHead.title;
679
+ documentHead2.frontmatter = resolvedHead.frontmatter;
680
+ if (isBrowser) {
681
+ let scrollState;
682
+ if (navType === "popstate") {
683
+ scrollState = getScrollHistory();
655
684
  }
656
- if (routeLocationTarget2.params !== $params$) {
657
- if (_hasStoreEffects(routeLocation2, "params")) {
658
- shouldForceParams = true;
659
- }
660
- routeLocationTarget2.params = $params$;
685
+ const scroller = await getScroller2();
686
+ if (navigation.scroll && (!navigation.forceReload || !isSamePath(trackUrl, prevUrl)) && (navType === "link" || navType === "popstate") || navType === "form" && !isSamePath(trackUrl, prevUrl)) {
687
+ document.__q_scroll_restore__ = () => restoreScroll(navType, trackUrl, prevUrl, scroller, scrollState);
661
688
  }
662
- routeInternal2.untrackedValue = {
663
- type: navType,
664
- dest: trackUrl
665
- };
666
- const resolvedHead = resolveHead(clientPageData, routeLocation2, contentModules, locale, serverHead2);
667
- content2.headings = pageModule.headings;
668
- content2.menu = $menu$;
669
- contentInternal2.untrackedValue = noSerialize(contentModules);
670
- documentHead2.links = resolvedHead.links;
671
- documentHead2.meta = resolvedHead.meta;
672
- documentHead2.styles = resolvedHead.styles;
673
- documentHead2.scripts = resolvedHead.scripts;
674
- documentHead2.title = resolvedHead.title;
675
- documentHead2.frontmatter = resolvedHead.frontmatter;
676
- if (isBrowser) {
677
- let scrollState;
678
- if (navType === "popstate") {
679
- scrollState = getScrollHistory();
680
- }
681
- const scroller = await getScroller2();
682
- if (navigation.scroll && (!navigation.forceReload || !isSamePath(trackUrl, prevUrl)) && (navType === "link" || navType === "popstate") || navType === "form" && !isSamePath(trackUrl, prevUrl)) {
683
- document.__q_scroll_restore__ = () => restoreScroll(navType, trackUrl, prevUrl, scroller, scrollState);
684
- }
685
- const loaders = clientPageData?.loaders;
686
- if (loaders) {
687
- const container3 = _getContextContainer();
688
- for (const [key, value] of Object.entries(loaders)) {
689
- const signal = loaderState2[key];
690
- const awaitedValue = await value;
691
- loadersObject2[key] = awaitedValue;
692
- if (!signal) {
693
- loaderState2[key] = createLoaderSignal(loadersObject2, key, trackUrl, DEFAULT_LOADERS_SERIALIZATION_STRATEGY, container3);
694
- } else {
695
- signal.invalidate();
696
- }
689
+ const loaders = clientPageData?.loaders;
690
+ if (loaders) {
691
+ for (const [key, value] of Object.entries(loaders)) {
692
+ const signal = loaderState2[key];
693
+ const awaitedValue = await value;
694
+ loadersObject2[key] = awaitedValue;
695
+ if (!signal) {
696
+ loaderState2[key] = createLoaderSignal(loadersObject2, key, trackUrl, DEFAULT_LOADERS_SERIALIZATION_STRATEGY, container2);
697
+ } else {
698
+ signal.invalidate();
697
699
  }
698
700
  }
699
- CLIENT_DATA_CACHE.clear();
700
- if (!window._qRouterSPA) {
701
- window._qRouterSPA = true;
702
- history.scrollRestoration = "manual";
703
- window.addEventListener("popstate", () => {
704
- window._qRouterScrollEnabled = false;
705
- clearTimeout(window._qRouterScrollDebounce);
706
- goto2(location.href, {
707
- type: "popstate"
708
- });
701
+ }
702
+ CLIENT_DATA_CACHE.clear();
703
+ if (!window._qRouterSPA) {
704
+ window._qRouterSPA = true;
705
+ history.scrollRestoration = "manual";
706
+ window.addEventListener("popstate", () => {
707
+ window._qRouterScrollEnabled = false;
708
+ clearTimeout(window._qRouterScrollDebounce);
709
+ goto2(location.href, {
710
+ type: "popstate"
709
711
  });
710
- window.removeEventListener("popstate", window._qRouterInitPopstate);
711
- window._qRouterInitPopstate = void 0;
712
- if (!window._qRouterHistoryPatch) {
713
- window._qRouterHistoryPatch = true;
714
- const pushState = history.pushState;
715
- const replaceState2 = history.replaceState;
716
- const prepareState = (state) => {
717
- if (state === null || typeof state === "undefined") {
718
- state = {};
719
- } else if (state?.constructor !== Object) {
720
- state = {
721
- _data: state
722
- };
723
- if (isDev) {
724
- console.warn("In a Qwik SPA context, `history.state` is used to store scroll state. Direct calls to `pushState()` and `replaceState()` must supply an actual Object type. We need to be able to automatically attach the scroll state to your state object. A new state object has been created, your data has been moved to: `history.state._data`");
725
- }
712
+ });
713
+ window.removeEventListener("popstate", window._qRouterInitPopstate);
714
+ window._qRouterInitPopstate = void 0;
715
+ if (!window._qRouterHistoryPatch) {
716
+ window._qRouterHistoryPatch = true;
717
+ const pushState = history.pushState;
718
+ const replaceState2 = history.replaceState;
719
+ const prepareState = (state) => {
720
+ if (state === null || typeof state === "undefined") {
721
+ state = {};
722
+ } else if (state?.constructor !== Object) {
723
+ state = {
724
+ _data: state
725
+ };
726
+ if (isDev) {
727
+ console.warn("In a Qwik SPA context, `history.state` is used to store scroll state. Direct calls to `pushState()` and `replaceState()` must supply an actual Object type. We need to be able to automatically attach the scroll state to your state object. A new state object has been created, your data has been moved to: `history.state._data`");
726
728
  }
727
- state._qRouterScroll = state._qRouterScroll || currentScrollState(scroller);
728
- return state;
729
- };
730
- history.pushState = (state, title, url2) => {
731
- state = prepareState(state);
732
- return pushState.call(history, state, title, url2);
733
- };
734
- history.replaceState = (state, title, url2) => {
735
- state = prepareState(state);
736
- return replaceState2.call(history, state, title, url2);
737
- };
738
- }
739
- document.addEventListener("click", (event) => {
740
- if (event.defaultPrevented) {
741
- return;
742
729
  }
743
- const target = event.target.closest("a[href]");
744
- if (target && !target.hasAttribute("preventdefault:click")) {
745
- const href = target.getAttribute("href");
746
- const prev = new URL(location.href);
747
- const dest = new URL(href, prev);
748
- if (isSameOrigin(dest, prev) && isSamePath(dest, prev)) {
749
- event.preventDefault();
750
- if (!dest.hash && !dest.href.endsWith("#")) {
751
- if (dest.href !== prev.href) {
752
- history.pushState(null, "", dest);
753
- }
754
- window._qRouterScrollEnabled = false;
755
- clearTimeout(window._qRouterScrollDebounce);
756
- saveScrollHistory({
757
- ...currentScrollState(scroller),
758
- x: 0,
759
- y: 0
760
- });
761
- location.reload();
762
- return;
730
+ state._qRouterScroll = state._qRouterScroll || currentScrollState(scroller);
731
+ return state;
732
+ };
733
+ history.pushState = (state, title, url2) => {
734
+ state = prepareState(state);
735
+ return pushState.call(history, state, title, url2);
736
+ };
737
+ history.replaceState = (state, title, url2) => {
738
+ state = prepareState(state);
739
+ return replaceState2.call(history, state, title, url2);
740
+ };
741
+ }
742
+ document.addEventListener("click", (event) => {
743
+ if (event.defaultPrevented) {
744
+ return;
745
+ }
746
+ const target = event.target.closest("a[href]");
747
+ if (target && !target.hasAttribute("preventdefault:click")) {
748
+ const href = target.getAttribute("href");
749
+ const prev = new URL(location.href);
750
+ const dest = new URL(href, prev);
751
+ if (isSameOrigin(dest, prev) && isSamePath(dest, prev)) {
752
+ event.preventDefault();
753
+ if (!dest.hash && !dest.href.endsWith("#")) {
754
+ if (dest.href !== prev.href) {
755
+ history.pushState(null, "", dest);
763
756
  }
764
- goto2(target.getAttribute("href"));
757
+ window._qRouterScrollEnabled = false;
758
+ clearTimeout(window._qRouterScrollDebounce);
759
+ saveScrollHistory({
760
+ ...currentScrollState(scroller),
761
+ x: 0,
762
+ y: 0
763
+ });
764
+ location.reload();
765
+ return;
765
766
  }
767
+ goto2(target.getAttribute("href"));
766
768
  }
767
- });
768
- document.removeEventListener("click", window._qRouterInitAnchors);
769
- window._qRouterInitAnchors = void 0;
770
- if (!window.navigation) {
771
- document.addEventListener("visibilitychange", () => {
772
- if ((window._qRouterScrollEnabled || window._qCityScrollEnabled) && document.visibilityState === "hidden") {
773
- if (window._qCityScrollEnabled) {
774
- console.warn('"_qCityScrollEnabled" is deprecated. Use "_qRouterScrollEnabled" instead.');
775
- }
776
- const scrollState2 = currentScrollState(scroller);
777
- saveScrollHistory(scrollState2);
778
- }
779
- }, {
780
- passive: true
781
- });
782
- document.removeEventListener("visibilitychange", window._qRouterInitVisibility);
783
- window._qRouterInitVisibility = void 0;
784
769
  }
785
- window.addEventListener("scroll", () => {
786
- if (!window._qRouterScrollEnabled && !window._qCityScrollEnabled) {
787
- return;
788
- }
789
- clearTimeout(window._qRouterScrollDebounce);
790
- window._qRouterScrollDebounce = setTimeout(() => {
770
+ });
771
+ document.removeEventListener("click", window._qRouterInitAnchors);
772
+ window._qRouterInitAnchors = void 0;
773
+ if (!window.navigation) {
774
+ document.addEventListener("visibilitychange", () => {
775
+ if ((window._qRouterScrollEnabled || window._qCityScrollEnabled) && document.visibilityState === "hidden") {
776
+ if (window._qCityScrollEnabled) {
777
+ console.warn('"_qCityScrollEnabled" is deprecated. Use "_qRouterScrollEnabled" instead.');
778
+ }
791
779
  const scrollState2 = currentScrollState(scroller);
792
780
  saveScrollHistory(scrollState2);
793
- window._qRouterScrollDebounce = void 0;
794
- }, 200);
781
+ }
795
782
  }, {
796
783
  passive: true
797
784
  });
798
- removeEventListener("scroll", window._qRouterInitScroll);
799
- window._qRouterInitScroll = void 0;
800
- spaInit.resolve();
785
+ document.removeEventListener("visibilitychange", window._qRouterInitVisibility);
786
+ window._qRouterInitVisibility = void 0;
801
787
  }
802
- if (navType !== "popstate") {
803
- window._qRouterScrollEnabled = false;
788
+ window.addEventListener("scroll", () => {
789
+ if (!window._qRouterScrollEnabled && !window._qCityScrollEnabled) {
790
+ return;
791
+ }
804
792
  clearTimeout(window._qRouterScrollDebounce);
805
- if (!navigation.historyUpdated) {
793
+ window._qRouterScrollDebounce = setTimeout(() => {
806
794
  const scrollState2 = currentScrollState(scroller);
807
795
  saveScrollHistory(scrollState2);
808
- }
809
- }
810
- const navigate = () => {
811
- if (navigation.historyUpdated) {
812
- const currentPath = location.pathname + location.search + location.hash;
813
- const nextPath = toPath(trackUrl);
814
- if (currentPath !== nextPath) {
815
- history.replaceState(history.state, "", nextPath);
816
- }
817
- } else {
818
- clientNavigate(window, navType, prevUrl, trackUrl, replaceState);
819
- }
820
- contentInternal2.trigger();
821
- return _waitUntilRendered(container2);
822
- };
823
- const _waitNextPage = () => {
824
- if (isServer || props2?.viewTransition === false) {
825
- return navigate();
826
- } else {
827
- const viewTransition = startViewTransition({
828
- update: navigate,
829
- types: [
830
- "qwik-navigation"
831
- ]
832
- });
833
- if (!viewTransition) {
834
- return Promise.resolve();
835
- }
836
- return viewTransition.ready;
837
- }
838
- };
839
- _waitNextPage().catch((err) => {
840
- navigate();
841
- throw err;
842
- }).finally(() => {
843
- container2.element.setAttribute?.(Q_ROUTE, $routeName$);
796
+ window._qRouterScrollDebounce = void 0;
797
+ }, 200);
798
+ }, {
799
+ passive: true
800
+ });
801
+ removeEventListener("scroll", window._qRouterInitScroll);
802
+ window._qRouterInitScroll = void 0;
803
+ spaInit.resolve();
804
+ }
805
+ if (navType !== "popstate") {
806
+ window._qRouterScrollEnabled = false;
807
+ clearTimeout(window._qRouterScrollDebounce);
808
+ if (!navigation.historyUpdated) {
844
809
  const scrollState2 = currentScrollState(scroller);
845
810
  saveScrollHistory(scrollState2);
846
- window._qRouterScrollEnabled = true;
847
- if (isBrowser) {
848
- callRestoreScrollOnDocument();
849
- }
850
- if (shouldForcePrevUrl) {
851
- forceStoreEffects(routeLocation2, "prevUrl");
852
- }
853
- if (shouldForceUrl) {
854
- forceStoreEffects(routeLocation2, "url");
811
+ }
812
+ }
813
+ const navigate = () => {
814
+ if (navigation.historyUpdated) {
815
+ const currentPath = location.pathname + location.search + location.hash;
816
+ const nextPath = toPath(trackUrl);
817
+ if (currentPath !== nextPath) {
818
+ history.replaceState(history.state, "", nextPath);
855
819
  }
856
- if (shouldForceParams) {
857
- forceStoreEffects(routeLocation2, "params");
820
+ } else {
821
+ clientNavigate(window, navType, prevUrl, trackUrl, replaceState);
822
+ }
823
+ contentInternal2.trigger();
824
+ return _waitUntilRendered(container2);
825
+ };
826
+ const _waitNextPage = () => {
827
+ if (isServer || props2?.viewTransition === false) {
828
+ return navigate();
829
+ } else {
830
+ const viewTransition = startViewTransition({
831
+ update: navigate,
832
+ types: [
833
+ "qwik-navigation"
834
+ ]
835
+ });
836
+ if (!viewTransition) {
837
+ return Promise.resolve();
858
838
  }
859
- routeLocation2.isNavigating = false;
860
- navResolver2.r?.();
861
- });
862
- }
839
+ return viewTransition.ready;
840
+ }
841
+ };
842
+ _waitNextPage().catch((err) => {
843
+ navigate();
844
+ throw err;
845
+ }).finally(() => {
846
+ container2.element.setAttribute?.(Q_ROUTE, $routeName$);
847
+ const scrollState2 = currentScrollState(scroller);
848
+ saveScrollHistory(scrollState2);
849
+ window._qRouterScrollEnabled = true;
850
+ if (isBrowser) {
851
+ callRestoreScrollOnDocument();
852
+ }
853
+ if (shouldForcePrevUrl) {
854
+ forceStoreEffects(routeLocation2, "prevUrl");
855
+ }
856
+ if (shouldForceUrl) {
857
+ forceStoreEffects(routeLocation2, "url");
858
+ }
859
+ if (shouldForceParams) {
860
+ forceStoreEffects(routeLocation2, "params");
861
+ }
862
+ routeLocation2.isNavigating = false;
863
+ navResolver2.r?.();
864
+ });
863
865
  }
866
+ }, "useQwikRouter_useTask_XpalYii770E", [
867
+ actionState,
868
+ content,
869
+ contentInternal,
870
+ documentHead,
871
+ env,
872
+ getScroller,
873
+ goto,
874
+ httpStatus,
875
+ loaderState,
876
+ loadersObject,
877
+ navResolver,
878
+ props,
879
+ routeInternal,
880
+ routeLocation,
881
+ routeLocationTarget,
882
+ serverHead
883
+ ]),
884
+ // We should only wait for navigation to complete on the server
885
+ {
886
+ deferUpdates: isServer
864
887
  }
865
- if (isServer) {
866
- return run();
867
- } else {
868
- run();
869
- }
870
- }, "useQwikRouter_useTask_XpalYii770E", [
871
- actionState,
872
- content,
873
- contentInternal,
874
- documentHead,
875
- env,
876
- getScroller,
877
- goto,
878
- httpStatus,
879
- loaderState,
880
- loadersObject,
881
- navResolver,
882
- props,
883
- routeInternal,
884
- routeLocation,
885
- routeLocationTarget,
886
- serverHead
887
- ]));
888
+ );
888
889
  };
889
890
  const QwikRouterProvider = /* @__PURE__ */ componentQrl(/* @__PURE__ */ inlinedQrl((props) => {
890
891
  useQwikRouter(props);
@@ -961,12 +962,21 @@ const QwikRouterMockProvider = /* @__PURE__ */ componentQrl(/* @__PURE__ */ inli
961
962
  }, "QwikRouterMockProvider_component_IN4dVpT0x74"));
962
963
  const QwikCityMockProvider = QwikRouterMockProvider;
963
964
 
965
+ const handleRouterPopstate = (nav, event) => {
966
+ const href = event.detail?.href;
967
+ if (href) {
968
+ return nav(href, {
969
+ type: "popstate"
970
+ });
971
+ }
972
+ };
964
973
  const RouterOutlet = /* @__PURE__ */ componentQrl(/* @__PURE__ */ inlinedQrl(() => {
965
974
  const serverData = useServerData("containerAttributes");
966
975
  if (!serverData) {
967
976
  throw new Error("PrefetchServiceWorker component must be rendered on the server.");
968
977
  }
969
978
  const internalContext = useContext(ContentInternalContext);
979
+ const nav = useNavigate();
970
980
  const contents = internalContext.value;
971
981
  if (contents && contents.length > 0) {
972
982
  const contentsLen = contents.length;
@@ -981,19 +991,22 @@ const RouterOutlet = /* @__PURE__ */ componentQrl(/* @__PURE__ */ inlinedQrl(()
981
991
  !__EXPERIMENTAL__.noSPA && /* @__PURE__ */ _jsxSorted("script", {
982
992
  "q-d:qinit": _qrlSync(() => {
983
993
  ((w, h) => {
984
- if (!w._qcs && h.scrollRestoration === "manual") {
994
+ if (!w._qcs) {
985
995
  w._qcs = true;
986
996
  const s = h.state?._qRouterScroll;
987
997
  if (s) {
998
+ h.scrollRestoration = "manual";
988
999
  w.scrollTo(s.x, s.y);
989
1000
  }
990
1001
  document.dispatchEvent(new Event("qcinit"));
991
1002
  }
992
1003
  })(window, history);
993
- }, '()=>{((w,h)=>{if(!w._qcs&&h.scrollRestoration==="manual"){w._qcs=!0;const s=h.state?._qRouterScroll;if(s){w.scrollTo(s.x,s.y);}document.dispatchEvent(new Event("qcinit"));}})(window,history);}')
1004
+ }, '()=>{((w,h)=>{if(!w._qcs){w._qcs=!0;const s=h.state?._qRouterScroll;if(s){h.scrollRestoration="manual";w.scrollTo(s.x,s.y);}document.dispatchEvent(new Event("qcinit"));}})(window,history);}'),
1005
+ "q-d:qrouterpopstate": /* @__PURE__ */ inlinedQrl((event, _1, nav2) => handleRouterPopstate(nav2, event), "RouterOutlet_component_Fragment_script_q_d_qrouterpopstate_aRL6GvFyews"),
1006
+ "q:p": nav
994
1007
  }, {
995
1008
  "q-d:qcinit": spaInit
996
- }, null, 2, "Fn_1")
1009
+ }, null, 6, "Fn_1")
997
1010
  ], 1, "Fn_2");
998
1011
  }
999
1012
  return SkipRender;