@inertiajs/core 2.3.7 → 2.3.9

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
@@ -792,7 +792,7 @@ function mergeDataIntoQueryString(method, href, data, qsArrayFormat = "brackets"
792
792
  const hasHash = href.toString().includes("#");
793
793
  const url = new URL(href.toString(), typeof window === "undefined" ? "http://localhost" : window.location.toString());
794
794
  if (hasDataForQueryString) {
795
- const hasIndices = /\[\d+\]/.test(url.search);
795
+ const hasIndices = /\[\d+\]/.test(decodeURIComponent(url.search));
796
796
  const parseOptions = { ignoreQueryPrefix: true, allowSparse: true };
797
797
  url.search = qs.stringify(
798
798
  { ...qs.parse(url.search, parseOptions), ...data },
@@ -874,6 +874,9 @@ var CurrentPage = class {
874
874
  component: page2.component,
875
875
  url: page2.url
876
876
  };
877
+ if (page2.initialDeferredProps === void 0) {
878
+ page2.initialDeferredProps = page2.deferredProps;
879
+ }
877
880
  }
878
881
  this.componentId = {};
879
882
  const componentId = this.componentId;
@@ -1334,10 +1337,21 @@ var EventHandler = class {
1334
1337
  this.onMissingHistoryItem();
1335
1338
  return;
1336
1339
  }
1337
- router.cancelAll();
1340
+ router.cancelAll({ prefetch: false });
1338
1341
  page.setQuietly(data, { preserveState: false }).then(() => {
1339
1342
  Scroll.restore(history.getScrollRegions());
1340
1343
  fireNavigateEvent(page.get());
1344
+ const pendingDeferred = {};
1345
+ const pageProps = page.get().props;
1346
+ for (const [group, props] of Object.entries(data.initialDeferredProps ?? data.deferredProps ?? {})) {
1347
+ const missing = props.filter((prop) => pageProps[prop] === void 0);
1348
+ if (missing.length > 0) {
1349
+ pendingDeferred[group] = missing;
1350
+ }
1351
+ }
1352
+ if (Object.keys(pendingDeferred).length > 0) {
1353
+ this.fireInternalEvent("loadDeferredProps", pendingDeferred);
1354
+ }
1341
1355
  });
1342
1356
  }).catch(() => {
1343
1357
  this.onMissingHistoryItem();
@@ -1444,7 +1458,7 @@ var InitialVisit = class {
1444
1458
  fireNavigateEvent(page2);
1445
1459
  const flash = page2.flash;
1446
1460
  if (Object.keys(flash).length > 0) {
1447
- fireFlashEvent(flash);
1461
+ queueMicrotask(() => fireFlashEvent(flash));
1448
1462
  }
1449
1463
  });
1450
1464
  }
@@ -1570,6 +1584,9 @@ var RequestParams = class _RequestParams {
1570
1584
  isPartial() {
1571
1585
  return this.params.only.length > 0 || this.params.except.length > 0 || this.params.reset.length > 0;
1572
1586
  }
1587
+ isPrefetch() {
1588
+ return this.params.prefetch === true;
1589
+ }
1573
1590
  isDeferredPropsRequest() {
1574
1591
  return this.params.deferredProps === true;
1575
1592
  }
@@ -2023,6 +2040,10 @@ var Response = class _Response {
2023
2040
  ...page.get().flash,
2024
2041
  ...this.requestParams.isDeferredPropsRequest() ? {} : pageResponse.flash
2025
2042
  };
2043
+ const currentOriginalDeferred = page.get().initialDeferredProps;
2044
+ if (currentOriginalDeferred && Object.keys(currentOriginalDeferred).length > 0) {
2045
+ pageResponse.initialDeferredProps = currentOriginalDeferred;
2046
+ }
2026
2047
  }
2027
2048
  mergeOrMatchItems(existingItems, newItems, matchProp, matchPropsOn, shouldAppend = true) {
2028
2049
  const items = Array.isArray(existingItems) ? existingItems : [];
@@ -2096,6 +2117,9 @@ var Request = class _Request {
2096
2117
  static create(params, page2) {
2097
2118
  return new _Request(params, page2);
2098
2119
  }
2120
+ isPrefetch() {
2121
+ return this.requestParams.isPrefetch();
2122
+ }
2099
2123
  async send() {
2100
2124
  this.requestParams.onCancelToken(() => this.cancel({ cancelled: true }));
2101
2125
  fireStartEvent(this.requestParams.all());
@@ -2212,20 +2236,17 @@ var RequestStream = class {
2212
2236
  interruptInFlight() {
2213
2237
  this.cancel({ interrupted: true }, false);
2214
2238
  }
2215
- cancelInFlight() {
2216
- this.cancel({ cancelled: true }, true);
2239
+ cancelInFlight({ prefetch = true } = {}) {
2240
+ this.requests.filter((request) => prefetch || !request.isPrefetch()).forEach((request) => request.cancel({ cancelled: true }));
2217
2241
  }
2218
- cancel({ cancelled = false, interrupted = false } = {}, force) {
2219
- if (!this.shouldCancel(force)) {
2242
+ cancel({ cancelled = false, interrupted = false } = {}, force = false) {
2243
+ if (!force && !this.shouldCancel()) {
2220
2244
  return;
2221
2245
  }
2222
2246
  const request = this.requests.shift();
2223
- request?.cancel({ interrupted, cancelled });
2247
+ request?.cancel({ cancelled, interrupted });
2224
2248
  }
2225
- shouldCancel(force) {
2226
- if (force) {
2227
- return true;
2228
- }
2249
+ shouldCancel() {
2229
2250
  return this.interruptible && this.requests.length >= this.maxConcurrent;
2230
2251
  }
2231
2252
  };
@@ -2315,11 +2336,14 @@ var Router = class {
2315
2336
  }
2316
2337
  return eventHandler.onGlobalEvent(type, callback);
2317
2338
  }
2339
+ /**
2340
+ * @deprecated Use cancelAll() instead.
2341
+ */
2318
2342
  cancel() {
2319
2343
  this.syncRequestStream.cancelInFlight();
2320
2344
  }
2321
- cancelAll() {
2322
- this.asyncRequestStream.cancelInFlight();
2345
+ cancelAll({ prefetch = true } = {}) {
2346
+ this.asyncRequestStream.cancelInFlight({ prefetch });
2323
2347
  this.syncRequestStream.cancelInFlight();
2324
2348
  }
2325
2349
  poll(interval, requestOptions = {}, options = {}) {
@@ -2337,8 +2361,12 @@ var Router = class {
2337
2361
  if (events.onBefore(visit) === false || !fireBeforeEvent(visit)) {
2338
2362
  return;
2339
2363
  }
2340
- const requestStream = visit.async ? this.asyncRequestStream : this.syncRequestStream;
2341
- requestStream.interruptInFlight();
2364
+ if (!isSameUrlWithoutHash(visit.url, hrefToUrl(page.get().url))) {
2365
+ this.asyncRequestStream.cancelInFlight({ prefetch: false });
2366
+ }
2367
+ if (!visit.async) {
2368
+ this.syncRequestStream.interruptInFlight();
2369
+ }
2342
2370
  if (!page.isCleared() && !visit.preserveUrl) {
2343
2371
  Scroll.save();
2344
2372
  }
@@ -2352,6 +2380,7 @@ var Router = class {
2352
2380
  prefetchedRequests.use(prefetched, requestParams);
2353
2381
  } else {
2354
2382
  progress.reveal(true);
2383
+ const requestStream = visit.async ? this.asyncRequestStream : this.syncRequestStream;
2355
2384
  requestStream.send(Request.create(requestParams, page.get()));
2356
2385
  }
2357
2386
  }
@@ -3084,6 +3113,7 @@ var useInfiniteScrollData = (options) => {
3084
3113
  const removeEventListener = router.on("success", (event) => {
3085
3114
  if (state.component === event.detail.page.component && getScrollPropFromCurrentPage().reset) {
3086
3115
  resetState();
3116
+ options.onReset?.();
3087
3117
  }
3088
3118
  });
3089
3119
  const getScrollPropKeyForSide = (side) => {
@@ -3500,7 +3530,8 @@ function useInfiniteScroll(options) {
3500
3530
  onCompleteNextRequest: (loadedPage) => {
3501
3531
  options.onCompleteNextRequest();
3502
3532
  requestAnimationFrame(() => elementManager.processServerLoadedElements(loadedPage), 2);
3503
- }
3533
+ },
3534
+ onReset: options.onDataReset
3504
3535
  });
3505
3536
  const addScrollPreservationCallbacks = (reloadOptions) => {
3506
3537
  const { captureScrollPosition, restoreScrollPosition } = scrollPreservation.createCallbacks();