@inertiajs/core 2.3.8 → 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.esm.js CHANGED
@@ -817,6 +817,9 @@ var CurrentPage = class {
817
817
  component: page2.component,
818
818
  url: page2.url
819
819
  };
820
+ if (page2.initialDeferredProps === void 0) {
821
+ page2.initialDeferredProps = page2.deferredProps;
822
+ }
820
823
  }
821
824
  this.componentId = {};
822
825
  const componentId = this.componentId;
@@ -1277,10 +1280,21 @@ var EventHandler = class {
1277
1280
  this.onMissingHistoryItem();
1278
1281
  return;
1279
1282
  }
1280
- router.cancelAll();
1283
+ router.cancelAll({ prefetch: false });
1281
1284
  page.setQuietly(data, { preserveState: false }).then(() => {
1282
1285
  Scroll.restore(history.getScrollRegions());
1283
1286
  fireNavigateEvent(page.get());
1287
+ const pendingDeferred = {};
1288
+ const pageProps = page.get().props;
1289
+ for (const [group, props] of Object.entries(data.initialDeferredProps ?? data.deferredProps ?? {})) {
1290
+ const missing = props.filter((prop) => pageProps[prop] === void 0);
1291
+ if (missing.length > 0) {
1292
+ pendingDeferred[group] = missing;
1293
+ }
1294
+ }
1295
+ if (Object.keys(pendingDeferred).length > 0) {
1296
+ this.fireInternalEvent("loadDeferredProps", pendingDeferred);
1297
+ }
1284
1298
  });
1285
1299
  }).catch(() => {
1286
1300
  this.onMissingHistoryItem();
@@ -1513,6 +1527,9 @@ var RequestParams = class _RequestParams {
1513
1527
  isPartial() {
1514
1528
  return this.params.only.length > 0 || this.params.except.length > 0 || this.params.reset.length > 0;
1515
1529
  }
1530
+ isPrefetch() {
1531
+ return this.params.prefetch === true;
1532
+ }
1516
1533
  isDeferredPropsRequest() {
1517
1534
  return this.params.deferredProps === true;
1518
1535
  }
@@ -1966,6 +1983,10 @@ var Response = class _Response {
1966
1983
  ...page.get().flash,
1967
1984
  ...this.requestParams.isDeferredPropsRequest() ? {} : pageResponse.flash
1968
1985
  };
1986
+ const currentOriginalDeferred = page.get().initialDeferredProps;
1987
+ if (currentOriginalDeferred && Object.keys(currentOriginalDeferred).length > 0) {
1988
+ pageResponse.initialDeferredProps = currentOriginalDeferred;
1989
+ }
1969
1990
  }
1970
1991
  mergeOrMatchItems(existingItems, newItems, matchProp, matchPropsOn, shouldAppend = true) {
1971
1992
  const items = Array.isArray(existingItems) ? existingItems : [];
@@ -2039,6 +2060,9 @@ var Request = class _Request {
2039
2060
  static create(params, page2) {
2040
2061
  return new _Request(params, page2);
2041
2062
  }
2063
+ isPrefetch() {
2064
+ return this.requestParams.isPrefetch();
2065
+ }
2042
2066
  async send() {
2043
2067
  this.requestParams.onCancelToken(() => this.cancel({ cancelled: true }));
2044
2068
  fireStartEvent(this.requestParams.all());
@@ -2155,20 +2179,17 @@ var RequestStream = class {
2155
2179
  interruptInFlight() {
2156
2180
  this.cancel({ interrupted: true }, false);
2157
2181
  }
2158
- cancelInFlight() {
2159
- this.cancel({ cancelled: true }, true);
2182
+ cancelInFlight({ prefetch = true } = {}) {
2183
+ this.requests.filter((request) => prefetch || !request.isPrefetch()).forEach((request) => request.cancel({ cancelled: true }));
2160
2184
  }
2161
- cancel({ cancelled = false, interrupted = false } = {}, force) {
2162
- if (!this.shouldCancel(force)) {
2185
+ cancel({ cancelled = false, interrupted = false } = {}, force = false) {
2186
+ if (!force && !this.shouldCancel()) {
2163
2187
  return;
2164
2188
  }
2165
2189
  const request = this.requests.shift();
2166
- request?.cancel({ interrupted, cancelled });
2190
+ request?.cancel({ cancelled, interrupted });
2167
2191
  }
2168
- shouldCancel(force) {
2169
- if (force) {
2170
- return true;
2171
- }
2192
+ shouldCancel() {
2172
2193
  return this.interruptible && this.requests.length >= this.maxConcurrent;
2173
2194
  }
2174
2195
  };
@@ -2258,11 +2279,14 @@ var Router = class {
2258
2279
  }
2259
2280
  return eventHandler.onGlobalEvent(type, callback);
2260
2281
  }
2282
+ /**
2283
+ * @deprecated Use cancelAll() instead.
2284
+ */
2261
2285
  cancel() {
2262
2286
  this.syncRequestStream.cancelInFlight();
2263
2287
  }
2264
- cancelAll() {
2265
- this.asyncRequestStream.cancelInFlight();
2288
+ cancelAll({ prefetch = true } = {}) {
2289
+ this.asyncRequestStream.cancelInFlight({ prefetch });
2266
2290
  this.syncRequestStream.cancelInFlight();
2267
2291
  }
2268
2292
  poll(interval, requestOptions = {}, options = {}) {
@@ -2280,8 +2304,12 @@ var Router = class {
2280
2304
  if (events.onBefore(visit) === false || !fireBeforeEvent(visit)) {
2281
2305
  return;
2282
2306
  }
2283
- const requestStream = visit.async ? this.asyncRequestStream : this.syncRequestStream;
2284
- requestStream.interruptInFlight();
2307
+ if (!isSameUrlWithoutHash(visit.url, hrefToUrl(page.get().url))) {
2308
+ this.asyncRequestStream.cancelInFlight({ prefetch: false });
2309
+ }
2310
+ if (!visit.async) {
2311
+ this.syncRequestStream.interruptInFlight();
2312
+ }
2285
2313
  if (!page.isCleared() && !visit.preserveUrl) {
2286
2314
  Scroll.save();
2287
2315
  }
@@ -2295,6 +2323,7 @@ var Router = class {
2295
2323
  prefetchedRequests.use(prefetched, requestParams);
2296
2324
  } else {
2297
2325
  progress.reveal(true);
2326
+ const requestStream = visit.async ? this.asyncRequestStream : this.syncRequestStream;
2298
2327
  requestStream.send(Request.create(requestParams, page.get()));
2299
2328
  }
2300
2329
  }