@inertiajs/core 2.3.4 → 2.3.6
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 +53 -18
- package/dist/index.esm.js.map +2 -2
- package/dist/index.js +53 -18
- package/dist/index.js.map +2 -2
- package/package.json +2 -2
- package/types/history.d.ts +8 -1
- package/types/page.d.ts +1 -0
- package/types/types.d.ts +1 -1
package/dist/index.esm.js
CHANGED
|
@@ -735,12 +735,13 @@ function mergeDataIntoQueryString(method, href, data, qsArrayFormat = "brackets"
|
|
|
735
735
|
const hasHash = href.toString().includes("#");
|
|
736
736
|
const url = new URL(href.toString(), typeof window === "undefined" ? "http://localhost" : window.location.toString());
|
|
737
737
|
if (hasDataForQueryString) {
|
|
738
|
-
const
|
|
738
|
+
const hasIndices = /\[\d+\]/.test(url.search);
|
|
739
|
+
const parseOptions = { ignoreQueryPrefix: true, allowSparse: true };
|
|
739
740
|
url.search = qs.stringify(
|
|
740
741
|
{ ...qs.parse(url.search, parseOptions), ...data },
|
|
741
742
|
{
|
|
742
743
|
encodeValuesOnly: true,
|
|
743
|
-
arrayFormat: qsArrayFormat
|
|
744
|
+
arrayFormat: hasIndices ? "indices" : qsArrayFormat
|
|
744
745
|
}
|
|
745
746
|
);
|
|
746
747
|
}
|
|
@@ -787,6 +788,7 @@ var CurrentPage = class {
|
|
|
787
788
|
this.isFirstPageLoad = true;
|
|
788
789
|
this.cleared = false;
|
|
789
790
|
this.pendingDeferredProps = null;
|
|
791
|
+
this.historyQuotaExceeded = false;
|
|
790
792
|
}
|
|
791
793
|
init({
|
|
792
794
|
initialPage,
|
|
@@ -798,6 +800,9 @@ var CurrentPage = class {
|
|
|
798
800
|
this.swapComponent = swapComponent;
|
|
799
801
|
this.resolveComponent = resolveComponent;
|
|
800
802
|
this.onFlashCallback = onFlash;
|
|
803
|
+
eventHandler.on("historyQuotaExceeded", () => {
|
|
804
|
+
this.historyQuotaExceeded = true;
|
|
805
|
+
});
|
|
801
806
|
return this;
|
|
802
807
|
}
|
|
803
808
|
set(page2, {
|
|
@@ -847,6 +852,10 @@ var CurrentPage = class {
|
|
|
847
852
|
this.fireEventsFor("firstLoad");
|
|
848
853
|
}
|
|
849
854
|
this.isFirstPageLoad = false;
|
|
855
|
+
if (this.historyQuotaExceeded) {
|
|
856
|
+
this.historyQuotaExceeded = false;
|
|
857
|
+
return;
|
|
858
|
+
}
|
|
850
859
|
return this.swap({
|
|
851
860
|
component,
|
|
852
861
|
page: page2,
|
|
@@ -1128,9 +1137,27 @@ var History = class {
|
|
|
1128
1137
|
});
|
|
1129
1138
|
});
|
|
1130
1139
|
}
|
|
1140
|
+
isHistoryThrottleError(error) {
|
|
1141
|
+
return error instanceof Error && error.name === "SecurityError" && (error.message.includes("history.pushState") || error.message.includes("history.replaceState"));
|
|
1142
|
+
}
|
|
1143
|
+
isQuotaExceededError(error) {
|
|
1144
|
+
return error instanceof Error && error.name === "QuotaExceededError";
|
|
1145
|
+
}
|
|
1146
|
+
withThrottleProtection(cb) {
|
|
1147
|
+
return Promise.resolve().then(() => {
|
|
1148
|
+
try {
|
|
1149
|
+
return cb();
|
|
1150
|
+
} catch (error) {
|
|
1151
|
+
if (!this.isHistoryThrottleError(error)) {
|
|
1152
|
+
throw error;
|
|
1153
|
+
}
|
|
1154
|
+
console.error(error.message);
|
|
1155
|
+
}
|
|
1156
|
+
});
|
|
1157
|
+
}
|
|
1131
1158
|
doReplaceState(data, url) {
|
|
1132
|
-
return
|
|
1133
|
-
|
|
1159
|
+
return this.withThrottleProtection(() => {
|
|
1160
|
+
window.history.replaceState(
|
|
1134
1161
|
{
|
|
1135
1162
|
...data,
|
|
1136
1163
|
scrollRegions: data.scrollRegions ?? window.history.state?.scrollRegions,
|
|
@@ -1138,11 +1165,20 @@ var History = class {
|
|
|
1138
1165
|
},
|
|
1139
1166
|
"",
|
|
1140
1167
|
url
|
|
1141
|
-
)
|
|
1142
|
-
);
|
|
1168
|
+
);
|
|
1169
|
+
});
|
|
1143
1170
|
}
|
|
1144
1171
|
doPushState(data, url) {
|
|
1145
|
-
return
|
|
1172
|
+
return this.withThrottleProtection(() => {
|
|
1173
|
+
try {
|
|
1174
|
+
window.history.pushState(data, "", url);
|
|
1175
|
+
} catch (error) {
|
|
1176
|
+
if (!this.isQuotaExceededError(error)) {
|
|
1177
|
+
throw error;
|
|
1178
|
+
}
|
|
1179
|
+
eventHandler.fireInternalEvent("historyQuotaExceeded", url);
|
|
1180
|
+
}
|
|
1181
|
+
});
|
|
1146
1182
|
}
|
|
1147
1183
|
getState(key, defaultValue) {
|
|
1148
1184
|
return this.current?.[key] ?? defaultValue;
|
|
@@ -1158,8 +1194,8 @@ var History = class {
|
|
|
1158
1194
|
delete this.initialState[key];
|
|
1159
1195
|
}
|
|
1160
1196
|
}
|
|
1161
|
-
|
|
1162
|
-
return !!
|
|
1197
|
+
browserHasHistoryEntry() {
|
|
1198
|
+
return !isServer && !!window.history.state?.page;
|
|
1163
1199
|
}
|
|
1164
1200
|
clear() {
|
|
1165
1201
|
SessionStorage.remove(historySessionStorageKeys.key);
|
|
@@ -1289,7 +1325,7 @@ var InitialVisit = class {
|
|
|
1289
1325
|
}
|
|
1290
1326
|
}
|
|
1291
1327
|
static handleBackForward() {
|
|
1292
|
-
if (!navigationType.isBackForward() || !history.
|
|
1328
|
+
if (!navigationType.isBackForward() || !history.browserHasHistoryEntry()) {
|
|
1293
1329
|
return false;
|
|
1294
1330
|
}
|
|
1295
1331
|
const scrollRegions = history.getScrollRegions();
|
|
@@ -2168,6 +2204,9 @@ var Router = class {
|
|
|
2168
2204
|
eventHandler.on("loadDeferredProps", (deferredProps) => {
|
|
2169
2205
|
this.loadDeferredProps(deferredProps);
|
|
2170
2206
|
});
|
|
2207
|
+
eventHandler.on("historyQuotaExceeded", (url) => {
|
|
2208
|
+
window.location.href = url;
|
|
2209
|
+
});
|
|
2171
2210
|
}
|
|
2172
2211
|
get(url, data = {}, options = {}) {
|
|
2173
2212
|
return this.visit(url, { ...options, method: "get", data });
|
|
@@ -3395,17 +3434,11 @@ function useInfiniteScroll(options) {
|
|
|
3395
3434
|
// After successful request, tag new server content
|
|
3396
3435
|
onCompletePreviousRequest: (loadedPage) => {
|
|
3397
3436
|
options.onCompletePreviousRequest();
|
|
3398
|
-
requestAnimationFrame(() =>
|
|
3399
|
-
elementManager.processServerLoadedElements(loadedPage);
|
|
3400
|
-
elementManager.refreshTriggers();
|
|
3401
|
-
}, 2);
|
|
3437
|
+
requestAnimationFrame(() => elementManager.processServerLoadedElements(loadedPage), 2);
|
|
3402
3438
|
},
|
|
3403
3439
|
onCompleteNextRequest: (loadedPage) => {
|
|
3404
3440
|
options.onCompleteNextRequest();
|
|
3405
|
-
requestAnimationFrame(() =>
|
|
3406
|
-
elementManager.processServerLoadedElements(loadedPage);
|
|
3407
|
-
elementManager.refreshTriggers();
|
|
3408
|
-
}, 2);
|
|
3441
|
+
requestAnimationFrame(() => elementManager.processServerLoadedElements(loadedPage), 2);
|
|
3409
3442
|
}
|
|
3410
3443
|
});
|
|
3411
3444
|
const addScrollPreservationCallbacks = (reloadOptions) => {
|
|
@@ -3438,10 +3471,12 @@ function useInfiniteScroll(options) {
|
|
|
3438
3471
|
}
|
|
3439
3472
|
originalFetchPrevious(reloadOptions);
|
|
3440
3473
|
};
|
|
3474
|
+
const removeEventListener = router.on("success", () => requestAnimationFrame(elementManager.refreshTriggers, 2));
|
|
3441
3475
|
return {
|
|
3442
3476
|
dataManager,
|
|
3443
3477
|
elementManager,
|
|
3444
3478
|
flush: () => {
|
|
3479
|
+
removeEventListener();
|
|
3445
3480
|
dataManager.removeEventListener();
|
|
3446
3481
|
elementManager.flushAll();
|
|
3447
3482
|
queryStringManager.cancel();
|