@inertiajs/core 2.2.6 → 2.2.7

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/dist/index.js CHANGED
@@ -45,6 +45,8 @@ __export(index_exports, {
45
45
  setupProgress: () => setupProgress,
46
46
  shouldIntercept: () => shouldIntercept,
47
47
  shouldNavigate: () => shouldNavigate,
48
+ urlHasProtocol: () => urlHasProtocol,
49
+ urlToString: () => urlToString,
48
50
  urlWithoutHash: () => urlWithoutHash,
49
51
  useInfiniteScroll: () => useInfiniteScroll
50
52
  });
@@ -404,7 +406,7 @@ var transformUrlAndData = (href, data, method, forceFormData, queryStringArrayFo
404
406
  };
405
407
  function mergeDataIntoQueryString(method, href, data, qsArrayFormat = "brackets") {
406
408
  const hasDataForQueryString = method === "get" && !isFormData(data) && Object.keys(data).length > 0;
407
- const hasHost = /^[a-z][a-z0-9+.-]*:\/\//i.test(href.toString());
409
+ const hasHost = urlHasProtocol(href.toString());
408
410
  const hasAbsolutePath = hasHost || href.toString().startsWith("/") || href.toString() === "";
409
411
  const hasRelativePath = !hasAbsolutePath && !href.toString().startsWith("#") && !href.toString().startsWith("?");
410
412
  const hasRelativePathWithDotPrefix = /^[.]{1,2}([/]|$)/.test(href.toString());
@@ -448,6 +450,13 @@ var isSameUrlWithoutHash = (url1, url2) => {
448
450
  function isUrlMethodPair(href) {
449
451
  return href !== null && typeof href === "object" && href !== void 0 && "url" in href && "method" in href;
450
452
  }
453
+ function urlHasProtocol(url) {
454
+ return /^[a-z][a-z0-9+.-]*:\/\//i.test(url);
455
+ }
456
+ function urlToString(url, absolute) {
457
+ const urlObj = typeof url === "string" ? hrefToUrl(url) : url;
458
+ return absolute ? `${urlObj.protocol}//${urlObj.host}${urlObj.pathname}${urlObj.search}${urlObj.hash}` : `${urlObj.pathname}${urlObj.search}${urlObj.hash}`;
459
+ }
451
460
 
452
461
  // src/page.ts
453
462
  var CurrentPage = class {
@@ -634,15 +643,13 @@ var History = class {
634
643
  this.current = page2;
635
644
  queue.add(() => {
636
645
  return this.getPageData(page2).then((data) => {
637
- const doPush = () => {
638
- this.doPushState({ page: data }, page2.url);
639
- cb && cb();
640
- };
646
+ const doPush = () => this.doPushState({ page: data }, page2.url).then(() => cb?.());
641
647
  if (isChromeIOS) {
642
- setTimeout(doPush);
643
- } else {
644
- doPush();
648
+ return new Promise((resolve) => {
649
+ setTimeout(() => doPush().then(resolve));
650
+ });
645
651
  }
652
+ return doPush();
646
653
  });
647
654
  });
648
655
  }
@@ -680,7 +687,7 @@ var History = class {
680
687
  if (!window.history.state?.page) {
681
688
  return;
682
689
  }
683
- this.doReplaceState({
690
+ return this.doReplaceState({
684
691
  page: window.history.state.page,
685
692
  scrollRegions
686
693
  });
@@ -693,7 +700,7 @@ var History = class {
693
700
  if (!window.history.state?.page) {
694
701
  return;
695
702
  }
696
- this.doReplaceState({
703
+ return this.doReplaceState({
697
704
  page: window.history.state.page,
698
705
  documentScrollPosition: scrollRegion
699
706
  });
@@ -718,31 +725,31 @@ var History = class {
718
725
  this.current = page2;
719
726
  queue.add(() => {
720
727
  return this.getPageData(page2).then((data) => {
721
- const doReplace = () => {
722
- this.doReplaceState({ page: data }, page2.url);
723
- cb && cb();
724
- };
728
+ const doReplace = () => this.doReplaceState({ page: data }, page2.url).then(() => cb?.());
725
729
  if (isChromeIOS) {
726
- setTimeout(doReplace);
727
- } else {
728
- doReplace();
730
+ return new Promise((resolve) => {
731
+ setTimeout(() => doReplace().then(resolve));
732
+ });
729
733
  }
734
+ return doReplace();
730
735
  });
731
736
  });
732
737
  }
733
738
  doReplaceState(data, url) {
734
- window.history.replaceState(
735
- {
736
- ...data,
737
- scrollRegions: data.scrollRegions ?? window.history.state?.scrollRegions,
738
- documentScrollPosition: data.documentScrollPosition ?? window.history.state?.documentScrollPosition
739
- },
740
- "",
741
- url
739
+ return Promise.resolve().then(
740
+ () => window.history.replaceState(
741
+ {
742
+ ...data,
743
+ scrollRegions: data.scrollRegions ?? window.history.state?.scrollRegions,
744
+ documentScrollPosition: data.documentScrollPosition ?? window.history.state?.documentScrollPosition
745
+ },
746
+ "",
747
+ url
748
+ )
742
749
  );
743
750
  }
744
751
  doPushState(data, url) {
745
- window.history.pushState(data, "", url);
752
+ return Promise.resolve().then(() => window.history.pushState(data, "", url));
746
753
  }
747
754
  getState(key, defaultValue) {
748
755
  return this.current?.[key] ?? defaultValue;
@@ -2731,6 +2738,7 @@ var useInfiniteScrollElementManager = (options) => {
2731
2738
  var queue3 = new Queue();
2732
2739
  var initialUrl;
2733
2740
  var payloadUrl;
2741
+ var initialUrlWasAbsolute = null;
2734
2742
  var useInfiniteScrollQueryString = (options) => {
2735
2743
  let enabled = true;
2736
2744
  const queuePageUpdate = (page2) => {
@@ -2741,8 +2749,10 @@ var useInfiniteScrollQueryString = (options) => {
2741
2749
  return resolve();
2742
2750
  }
2743
2751
  if (!initialUrl || !payloadUrl) {
2744
- initialUrl = new URL(window.location.href);
2745
- payloadUrl = new URL(window.location.href);
2752
+ const currentPageUrl = page.get().url;
2753
+ initialUrl = hrefToUrl(currentPageUrl);
2754
+ payloadUrl = hrefToUrl(currentPageUrl);
2755
+ initialUrlWasAbsolute = urlHasProtocol(currentPageUrl);
2746
2756
  }
2747
2757
  const pageName = options.getPageName();
2748
2758
  const searchParams = payloadUrl.searchParams;
@@ -2754,14 +2764,14 @@ var useInfiniteScrollQueryString = (options) => {
2754
2764
  setTimeout(() => resolve());
2755
2765
  });
2756
2766
  }).finally(() => {
2757
- if (enabled && initialUrl && payloadUrl && initialUrl.href !== payloadUrl.href) {
2767
+ if (enabled && initialUrl && payloadUrl && initialUrl.href !== payloadUrl.href && initialUrlWasAbsolute !== null) {
2758
2768
  router.replace({
2759
- url: payloadUrl.toString(),
2769
+ url: urlToString(payloadUrl, initialUrlWasAbsolute),
2760
2770
  preserveScroll: true,
2761
2771
  preserveState: true
2762
2772
  });
2763
2773
  }
2764
- initialUrl = payloadUrl = null;
2774
+ initialUrl = payloadUrl = initialUrlWasAbsolute = null;
2765
2775
  });
2766
2776
  };
2767
2777
  const onItemIntersected = debounce((itemElement) => {