inertiax-core 11.0.19 → 11.0.22

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
@@ -419,53 +419,37 @@ var History = class {
419
419
  decryptPageData(pageData) {
420
420
  return pageData instanceof ArrayBuffer ? decryptHistory(pageData) : Promise.resolve(pageData);
421
421
  }
422
- saveScrollPositions(scrollRegions, frameId = DEFAULT_FRAME_ID) {
423
- queue.add(() => {
424
- return Promise.resolve().then(() => {
425
- const frameState = this.getFrameState(frameId);
426
- if (!frameState?.page) {
427
- return;
428
- }
429
- if (isEqual(this.getScrollRegions(frameId), scrollRegions)) {
430
- return;
431
- }
432
- return this.doReplaceState(
433
- {
434
- page: frameState.page,
435
- scrollRegions
436
- },
437
- void 0,
438
- frameId
439
- );
440
- });
441
- });
422
+ saveScrollPositions(scrollRegions) {
423
+ if (isEqual(this.getScrollRegions(), scrollRegions)) {
424
+ return;
425
+ }
426
+ const nextState = {
427
+ ...window.history.state,
428
+ scrollRegions
429
+ };
430
+ try {
431
+ window.history.replaceState(nextState, "");
432
+ } catch (e) {
433
+ if (!(e instanceof Error && e.name === "QuotaExceededError")) {
434
+ console.error("[Inertia] Failed to save scroll positions:", e);
435
+ }
436
+ }
442
437
  }
443
- saveDocumentScrollPosition(scrollRegion, frameId = DEFAULT_FRAME_ID) {
444
- queue.add(() => {
445
- return Promise.resolve().then(() => {
446
- const frameState = this.getFrameState(frameId);
447
- if (!frameState?.page) {
448
- return;
449
- }
450
- if (isEqual(this.getDocumentScrollPosition(frameId), scrollRegion)) {
451
- return;
452
- }
453
- return this.doReplaceState(
454
- {
455
- page: frameState.page,
456
- documentScrollPosition: scrollRegion
457
- },
458
- void 0,
459
- frameId
460
- );
461
- });
462
- });
438
+ saveDocumentScrollPosition(scrollRegion) {
439
+ if (isEqual(this.getDocumentScrollPosition(), scrollRegion)) {
440
+ return;
441
+ }
442
+ const nextState = {
443
+ ...window.history.state,
444
+ documentScrollPosition: scrollRegion
445
+ };
446
+ window.history.replaceState(nextState, "");
463
447
  }
464
- getScrollRegions(frameId = DEFAULT_FRAME_ID) {
465
- return this.getFrameState(frameId)?.scrollRegions || [];
448
+ getScrollRegions() {
449
+ return this.getWindowState().scrollRegions || [];
466
450
  }
467
- getDocumentScrollPosition(frameId = DEFAULT_FRAME_ID) {
468
- return this.getFrameState(frameId)?.documentScrollPosition || { top: 0, left: 0 };
451
+ getDocumentScrollPosition() {
452
+ return this.getWindowState().documentScrollPosition || { top: 0, left: 0 };
469
453
  }
470
454
  replaceState(page2, cb = null, frameId = DEFAULT_FRAME_ID, browserUrl) {
471
455
  if (isEqual(this.getCurrent(frameId), page2)) {
@@ -515,15 +499,12 @@ var History = class {
515
499
  doReplaceState(data, url, frameId = DEFAULT_FRAME_ID) {
516
500
  return this.withThrottleProtection(() => {
517
501
  const existing = this.getWindowState();
518
- const previous = existing.frames[frameId] ?? {};
519
502
  const nextState = {
520
503
  ...window.history.state,
521
504
  frames: {
522
505
  ...existing.frames,
523
506
  [frameId]: {
524
- page: data.page,
525
- scrollRegions: data.scrollRegions ?? previous.scrollRegions ?? [],
526
- documentScrollPosition: data.documentScrollPosition ?? previous.documentScrollPosition ?? { top: 0, left: 0 }
507
+ page: data.page
527
508
  }
528
509
  }
529
510
  };
@@ -533,15 +514,12 @@ var History = class {
533
514
  doPushState(data, url, frameId = DEFAULT_FRAME_ID) {
534
515
  return this.withThrottleProtection(() => {
535
516
  const existing = this.getWindowState();
536
- const previous = existing.frames[frameId] ?? {};
537
517
  const nextState = {
538
518
  ...window.history.state,
539
519
  frames: {
540
520
  ...existing.frames,
541
521
  [frameId]: {
542
- page: data.page,
543
- scrollRegions: data.scrollRegions ?? previous.scrollRegions ?? [],
544
- documentScrollPosition: data.documentScrollPosition ?? previous.documentScrollPosition ?? { top: 0, left: 0 }
522
+ page: data.page
545
523
  }
546
524
  }
547
525
  };
@@ -1042,8 +1020,8 @@ var isServer2 = typeof window === "undefined";
1042
1020
  var isFirefox = !isServer2 && /Firefox/i.test(window.navigator.userAgent);
1043
1021
  var DEFAULT_FRAME_ID2 = "_top";
1044
1022
  var Scroll = class {
1045
- static save(frameId = "_top") {
1046
- history.saveScrollPositions(this.getScrollRegions(), frameId);
1023
+ static save() {
1024
+ history.saveScrollPositions(this.getScrollRegions());
1047
1025
  }
1048
1026
  static getScrollRegions() {
1049
1027
  return Array.from(this.regions()).map((region) => ({
@@ -1097,7 +1075,6 @@ var Scroll = class {
1097
1075
  region.scrollLeft = 0;
1098
1076
  }
1099
1077
  });
1100
- this.save(frameId);
1101
1078
  if (isTopFrame) {
1102
1079
  this.scrollToAnchor(frameId);
1103
1080
  }
@@ -1118,21 +1095,11 @@ var Scroll = class {
1118
1095
  if (isServer2) {
1119
1096
  return;
1120
1097
  }
1121
- const isTopFrame = frameId === DEFAULT_FRAME_ID2;
1122
1098
  window.requestAnimationFrame(() => {
1123
- if (isTopFrame) {
1099
+ if (frameId === DEFAULT_FRAME_ID2) {
1124
1100
  this.restoreDocument(frameId);
1125
- this.restoreScrollRegions(scrollRegions);
1126
- } else {
1127
- this.regionsForFrame(frameId).forEach((region) => {
1128
- if (typeof region.scrollTo === "function") {
1129
- region.scrollTo(0, 0);
1130
- } else {
1131
- region.scrollTop = 0;
1132
- region.scrollLeft = 0;
1133
- }
1134
- });
1135
1101
  }
1102
+ this.restoreScrollRegions(scrollRegions);
1136
1103
  });
1137
1104
  }
1138
1105
  static restoreScrollRegions(scrollRegions) {
@@ -1156,7 +1123,7 @@ var Scroll = class {
1156
1123
  if (frameId !== DEFAULT_FRAME_ID2) {
1157
1124
  return;
1158
1125
  }
1159
- const scrollPosition = history.getDocumentScrollPosition(frameId);
1126
+ const scrollPosition = history.getDocumentScrollPosition();
1160
1127
  window.scrollTo(scrollPosition.left, scrollPosition.top);
1161
1128
  }
1162
1129
  static onScroll(event) {
@@ -1165,11 +1132,11 @@ var Scroll = class {
1165
1132
  this.save();
1166
1133
  }
1167
1134
  }
1168
- static onWindowScroll(frameId = "_top") {
1135
+ static onWindowScroll() {
1169
1136
  history.saveDocumentScrollPosition({
1170
1137
  top: window.scrollY,
1171
1138
  left: window.scrollX
1172
- }, frameId);
1139
+ });
1173
1140
  }
1174
1141
  };
1175
1142
 
@@ -1455,7 +1422,7 @@ var CurrentFramePage = class {
1455
1422
  const location = !isServer3 ? window.location : new URL(page2.url);
1456
1423
  const currentFrameUrl = hrefToUrl(this.page?.url ?? page2.url);
1457
1424
  const comparisonTarget = updateBrowserUrl ? location : currentFrameUrl;
1458
- const scrollRegions = !isServer3 && preserveScroll ? Scroll.getScrollRegions() : [];
1425
+ const scrollRegions = !isServer3 ? Scroll.getScrollRegions() : [];
1459
1426
  replace = replace || isSameUrlWithoutHash(hrefToUrl(page2.url), comparisonTarget);
1460
1427
  const pageForHistory = { ...page2, flash: {} };
1461
1428
  const browserUrl = !isServer3 && !updateBrowserUrl ? window.location.href : page2.url;
@@ -1869,7 +1836,7 @@ var InitialVisit = class {
1869
1836
  if (!navigationType.isBackForward() || !history.browserHasHistoryEntry(frameId)) {
1870
1837
  return false;
1871
1838
  }
1872
- const scrollRegions = history.getScrollRegions(frameId);
1839
+ const scrollRegions = history.getScrollRegions();
1873
1840
  history.decrypt(null, frameId).then((data) => {
1874
1841
  const visitId = uid();
1875
1842
  page.set(data, { preserveScroll: true, preserveState: true, visitId }, frameId).then(() => {
@@ -1896,7 +1863,7 @@ var InitialVisit = class {
1896
1863
  history.decrypt(page.get(frameId), frameId).then(() => {
1897
1864
  const visitId = uid();
1898
1865
  const rememberedState = history.getState(history.rememberedState, {}, frameId);
1899
- const scrollRegions = history.getScrollRegions(frameId);
1866
+ const scrollRegions = history.getScrollRegions();
1900
1867
  page.remember(rememberedState, frameId);
1901
1868
  page.set(page.get(frameId), {
1902
1869
  preserveScroll: locationVisit.preserveScroll,
@@ -1920,7 +1887,7 @@ var InitialVisit = class {
1920
1887
  const visitId = uid();
1921
1888
  page.set(page.get(frameId), { preserveScroll: true, preserveState: true, visitId }, frameId).then(() => {
1922
1889
  if (navigationType.isReload()) {
1923
- Scroll.restore(history.getScrollRegions(frameId), frameId);
1890
+ Scroll.restore(history.getScrollRegions(), frameId);
1924
1891
  } else {
1925
1892
  Scroll.scrollToAnchor(frameId);
1926
1893
  }
@@ -3304,8 +3271,11 @@ var Router = class {
3304
3271
  return;
3305
3272
  }
3306
3273
  this.cancelAll({ prefetch: false });
3274
+ if (!page.isCleared(this.frameId) && isEqual4(page.getWithoutFlashData(this.frameId), data)) {
3275
+ return;
3276
+ }
3307
3277
  page.setQuietly(data, { preserveState: this.frameId === DEFAULT_FRAME_ID4 }, this.frameId).then(() => {
3308
- Scroll.restore(history.getScrollRegions(this.frameId), this.frameId);
3278
+ Scroll.restore(history.getScrollRegions(), this.frameId);
3309
3279
  fireNavigateEvent(page.get(this.frameId));
3310
3280
  const pendingDeferred = {};
3311
3281
  const pageProps = page.get(this.frameId).props;
@@ -3464,9 +3434,6 @@ var Router = class {
3464
3434
  if (options.optimistic) {
3465
3435
  this.applyOptimisticUpdate(options.optimistic, events);
3466
3436
  }
3467
- if (!page.isCleared(this.frameId) && !visit.preserveUrl) {
3468
- Scroll.save(this.frameId);
3469
- }
3470
3437
  const requestParams = {
3471
3438
  ...visit,
3472
3439
  ...events