@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.esm.js CHANGED
@@ -352,7 +352,7 @@ var transformUrlAndData = (href, data, method, forceFormData, queryStringArrayFo
352
352
  };
353
353
  function mergeDataIntoQueryString(method, href, data, qsArrayFormat = "brackets") {
354
354
  const hasDataForQueryString = method === "get" && !isFormData(data) && Object.keys(data).length > 0;
355
- const hasHost = /^[a-z][a-z0-9+.-]*:\/\//i.test(href.toString());
355
+ const hasHost = urlHasProtocol(href.toString());
356
356
  const hasAbsolutePath = hasHost || href.toString().startsWith("/") || href.toString() === "";
357
357
  const hasRelativePath = !hasAbsolutePath && !href.toString().startsWith("#") && !href.toString().startsWith("?");
358
358
  const hasRelativePathWithDotPrefix = /^[.]{1,2}([/]|$)/.test(href.toString());
@@ -396,6 +396,13 @@ var isSameUrlWithoutHash = (url1, url2) => {
396
396
  function isUrlMethodPair(href) {
397
397
  return href !== null && typeof href === "object" && href !== void 0 && "url" in href && "method" in href;
398
398
  }
399
+ function urlHasProtocol(url) {
400
+ return /^[a-z][a-z0-9+.-]*:\/\//i.test(url);
401
+ }
402
+ function urlToString(url, absolute) {
403
+ const urlObj = typeof url === "string" ? hrefToUrl(url) : url;
404
+ return absolute ? `${urlObj.protocol}//${urlObj.host}${urlObj.pathname}${urlObj.search}${urlObj.hash}` : `${urlObj.pathname}${urlObj.search}${urlObj.hash}`;
405
+ }
399
406
 
400
407
  // src/page.ts
401
408
  var CurrentPage = class {
@@ -582,15 +589,13 @@ var History = class {
582
589
  this.current = page2;
583
590
  queue.add(() => {
584
591
  return this.getPageData(page2).then((data) => {
585
- const doPush = () => {
586
- this.doPushState({ page: data }, page2.url);
587
- cb && cb();
588
- };
592
+ const doPush = () => this.doPushState({ page: data }, page2.url).then(() => cb?.());
589
593
  if (isChromeIOS) {
590
- setTimeout(doPush);
591
- } else {
592
- doPush();
594
+ return new Promise((resolve) => {
595
+ setTimeout(() => doPush().then(resolve));
596
+ });
593
597
  }
598
+ return doPush();
594
599
  });
595
600
  });
596
601
  }
@@ -628,7 +633,7 @@ var History = class {
628
633
  if (!window.history.state?.page) {
629
634
  return;
630
635
  }
631
- this.doReplaceState({
636
+ return this.doReplaceState({
632
637
  page: window.history.state.page,
633
638
  scrollRegions
634
639
  });
@@ -641,7 +646,7 @@ var History = class {
641
646
  if (!window.history.state?.page) {
642
647
  return;
643
648
  }
644
- this.doReplaceState({
649
+ return this.doReplaceState({
645
650
  page: window.history.state.page,
646
651
  documentScrollPosition: scrollRegion
647
652
  });
@@ -666,31 +671,31 @@ var History = class {
666
671
  this.current = page2;
667
672
  queue.add(() => {
668
673
  return this.getPageData(page2).then((data) => {
669
- const doReplace = () => {
670
- this.doReplaceState({ page: data }, page2.url);
671
- cb && cb();
672
- };
674
+ const doReplace = () => this.doReplaceState({ page: data }, page2.url).then(() => cb?.());
673
675
  if (isChromeIOS) {
674
- setTimeout(doReplace);
675
- } else {
676
- doReplace();
676
+ return new Promise((resolve) => {
677
+ setTimeout(() => doReplace().then(resolve));
678
+ });
677
679
  }
680
+ return doReplace();
678
681
  });
679
682
  });
680
683
  }
681
684
  doReplaceState(data, url) {
682
- window.history.replaceState(
683
- {
684
- ...data,
685
- scrollRegions: data.scrollRegions ?? window.history.state?.scrollRegions,
686
- documentScrollPosition: data.documentScrollPosition ?? window.history.state?.documentScrollPosition
687
- },
688
- "",
689
- url
685
+ return Promise.resolve().then(
686
+ () => window.history.replaceState(
687
+ {
688
+ ...data,
689
+ scrollRegions: data.scrollRegions ?? window.history.state?.scrollRegions,
690
+ documentScrollPosition: data.documentScrollPosition ?? window.history.state?.documentScrollPosition
691
+ },
692
+ "",
693
+ url
694
+ )
690
695
  );
691
696
  }
692
697
  doPushState(data, url) {
693
- window.history.pushState(data, "", url);
698
+ return Promise.resolve().then(() => window.history.pushState(data, "", url));
694
699
  }
695
700
  getState(key, defaultValue) {
696
701
  return this.current?.[key] ?? defaultValue;
@@ -2679,6 +2684,7 @@ var useInfiniteScrollElementManager = (options) => {
2679
2684
  var queue3 = new Queue();
2680
2685
  var initialUrl;
2681
2686
  var payloadUrl;
2687
+ var initialUrlWasAbsolute = null;
2682
2688
  var useInfiniteScrollQueryString = (options) => {
2683
2689
  let enabled = true;
2684
2690
  const queuePageUpdate = (page2) => {
@@ -2689,8 +2695,10 @@ var useInfiniteScrollQueryString = (options) => {
2689
2695
  return resolve();
2690
2696
  }
2691
2697
  if (!initialUrl || !payloadUrl) {
2692
- initialUrl = new URL(window.location.href);
2693
- payloadUrl = new URL(window.location.href);
2698
+ const currentPageUrl = page.get().url;
2699
+ initialUrl = hrefToUrl(currentPageUrl);
2700
+ payloadUrl = hrefToUrl(currentPageUrl);
2701
+ initialUrlWasAbsolute = urlHasProtocol(currentPageUrl);
2694
2702
  }
2695
2703
  const pageName = options.getPageName();
2696
2704
  const searchParams = payloadUrl.searchParams;
@@ -2702,14 +2710,14 @@ var useInfiniteScrollQueryString = (options) => {
2702
2710
  setTimeout(() => resolve());
2703
2711
  });
2704
2712
  }).finally(() => {
2705
- if (enabled && initialUrl && payloadUrl && initialUrl.href !== payloadUrl.href) {
2713
+ if (enabled && initialUrl && payloadUrl && initialUrl.href !== payloadUrl.href && initialUrlWasAbsolute !== null) {
2706
2714
  router.replace({
2707
- url: payloadUrl.toString(),
2715
+ url: urlToString(payloadUrl, initialUrlWasAbsolute),
2708
2716
  preserveScroll: true,
2709
2717
  preserveState: true
2710
2718
  });
2711
2719
  }
2712
- initialUrl = payloadUrl = null;
2720
+ initialUrl = payloadUrl = initialUrlWasAbsolute = null;
2713
2721
  });
2714
2722
  };
2715
2723
  const onItemIntersected = debounce((itemElement) => {
@@ -3398,6 +3406,8 @@ export {
3398
3406
  setupProgress,
3399
3407
  shouldIntercept,
3400
3408
  shouldNavigate,
3409
+ urlHasProtocol,
3410
+ urlToString,
3401
3411
  urlWithoutHash,
3402
3412
  useInfiniteScroll
3403
3413
  };