tsdf 17.0.0-beta.2 → 17.0.0-beta.4
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/main.js +291 -78
- package/package.json +1 -1
package/dist/main.js
CHANGED
|
@@ -7427,9 +7427,7 @@ var RequestScheduler = class {
|
|
|
7427
7427
|
if (existing) clearTimeout(existing.timeoutId);
|
|
7428
7428
|
this.#state.pending.rtuDelayed.set(requestId, {
|
|
7429
7429
|
timeoutId: setTimeout(() => {
|
|
7430
|
-
this.#
|
|
7431
|
-
this.#onEvent?.("scheduled-rt-fetch-started");
|
|
7432
|
-
this.#scheduleRequest(requestId, "highPriority", payload, void 0, remoteStartCancelable);
|
|
7430
|
+
this.#executeDelayedRTUFetch(requestId);
|
|
7433
7431
|
}, delay),
|
|
7434
7432
|
requestId,
|
|
7435
7433
|
payload,
|
|
@@ -7441,6 +7439,16 @@ var RequestScheduler = class {
|
|
|
7441
7439
|
this.#onEvent?.("rt-fetch-scheduled", { delayMs: delay });
|
|
7442
7440
|
return true;
|
|
7443
7441
|
}
|
|
7442
|
+
/** Executes from the current delayed entry, not from the args captured when
|
|
7443
|
+
* the timeout was created — realtime updates arriving during the delay
|
|
7444
|
+
* coalesce their payloads into the entry. */
|
|
7445
|
+
#executeDelayedRTUFetch(requestId) {
|
|
7446
|
+
const delayedRequest = this.#state.pending.rtuDelayed.get(requestId);
|
|
7447
|
+
if (!delayedRequest) return;
|
|
7448
|
+
this.#state.pending.rtuDelayed.delete(requestId);
|
|
7449
|
+
this.#onEvent?.("scheduled-rt-fetch-started");
|
|
7450
|
+
this.#scheduleRequest(requestId, "highPriority", delayedRequest.payload, void 0, delayedRequest.remoteStartCancelable);
|
|
7451
|
+
}
|
|
7444
7452
|
#handleMediumPriority(requestId, payload, startTime, customDelayMs, remoteStartCancelable) {
|
|
7445
7453
|
const delayMs = customDelayMs ?? this.#mediumPriorityDelayMs;
|
|
7446
7454
|
if (delayMs === void 0) throw new Error("[tsdf] mediumPriorityDelayMs must be configured to use mediumPriority fetch type");
|
|
@@ -11966,6 +11974,24 @@ function getFallbackMissingRequestedFields(fallbackItemState, requestedFields, i
|
|
|
11966
11974
|
return missingLoadedFields.filter((field) => !inferredFields.includes(field));
|
|
11967
11975
|
}
|
|
11968
11976
|
/**
|
|
11977
|
+
* Fields from `requestedFields` that are genuinely absent from the snapshot —
|
|
11978
|
+
* not tracked as loaded, not vouched by `inferFields`, and not merely stale
|
|
11979
|
+
* (awaiting an invalidation re-fetch). Stale fields were loaded when their
|
|
11980
|
+
* invalidation was recorded, so their stale data is still present and may stay
|
|
11981
|
+
* visible while the re-fetch runs; only genuinely absent fields have no data
|
|
11982
|
+
* to show. Staleness is proven either by the field being in the unresolved
|
|
11983
|
+
* pending invalidation list, or — for an item with data still present — by the
|
|
11984
|
+
* unresolved full ('*') invalidation marker, which means the snapshot was
|
|
11985
|
+
* complete when invalidated.
|
|
11986
|
+
*/
|
|
11987
|
+
function getGenuinelyMissingRequestedFields(itemKey, fallbackItemState, requestedFields, inferFields, itemsPendingFullInvalidation, unresolvedPendingInvalidationFields) {
|
|
11988
|
+
const fallbackMissingFields = getFallbackMissingRequestedFields(fallbackItemState, requestedFields, inferFields);
|
|
11989
|
+
if (fallbackMissingFields.length === 0) return fallbackMissingFields;
|
|
11990
|
+
if (itemsPendingFullInvalidation.has(itemKey) && fallbackItemState?.item) return [];
|
|
11991
|
+
if (unresolvedPendingInvalidationFields.length === 0) return fallbackMissingFields;
|
|
11992
|
+
return fallbackMissingFields.filter((field) => !unresolvedPendingInvalidationFields.includes(field));
|
|
11993
|
+
}
|
|
11994
|
+
/**
|
|
11969
11995
|
* Returns the fields from `requestedFields` that are not yet present in
|
|
11970
11996
|
* `loadedFields`. When either argument is `undefined` or empty, returns `[]`.
|
|
11971
11997
|
*/
|
|
@@ -13059,7 +13085,7 @@ const GET_ALL = () => true;
|
|
|
13059
13085
|
//#endregion
|
|
13060
13086
|
//#region src/listQueryStore/createMutationApi.ts
|
|
13061
13087
|
/** @internal */
|
|
13062
|
-
function createMutationApi(store, fetchItemFn, partialResources, optimisticListUpdates, onInvalidateQuery, onInvalidateItem, onMutationError, errorNormalizer, getItemKey, getQueriesKeyArray, getQueriesRelatedToItem, getItemsKeyArray, getOrCreateItemScheduler, getOrCreateQueryScheduler, deleteItemFetchResources, emitInvalidateQuery, emitInvalidateItem, blockWindowClose, offlineController, runWithBroadcastConsistency, publishQuerySnapshot, publishItemSnapshot, onOfflineTimelineEvent, itemPendingInvalidationFields, itemsPendingFullInvalidation) {
|
|
13088
|
+
function createMutationApi(store, fetchItemFn, partialResources, optimisticListUpdates, onInvalidateQuery, onInvalidateItem, onMutationError, errorNormalizer, getItemKey, getQueriesKeyArray, getQueriesRelatedToItem, getItemsKeyArray, getOrCreateItemScheduler, getOrCreateQueryScheduler, deleteItemFetchResources, emitInvalidateQuery, emitInvalidateItem, blockWindowClose, offlineController, runWithBroadcastConsistency, publishQuerySnapshot, publishItemSnapshot, onOfflineTimelineEvent, itemPendingInvalidationFields, itemsPendingFullInvalidation, itemDroppedFieldInvalidations) {
|
|
13063
13089
|
const storeEvents = evtmitter();
|
|
13064
13090
|
const deferredOptimisticQueryInvalidationsStack = [];
|
|
13065
13091
|
const optimisticMutationQueryContextStack = [];
|
|
@@ -13119,6 +13145,25 @@ function createMutationApi(store, fetchItemFn, partialResources, optimisticListU
|
|
|
13119
13145
|
const queryInvalidationWasTriggered = /* @__PURE__ */ new Set();
|
|
13120
13146
|
const itemInvalidationWasTriggered = /* @__PURE__ */ new Set();
|
|
13121
13147
|
const itemFieldInvalidationPriorities = /* @__PURE__ */ new Map();
|
|
13148
|
+
/**
|
|
13149
|
+
* The staleness baseline for invalidations: a field is invalidatable
|
|
13150
|
+
* exactly when it is displayable, and hooks display the UNION of the
|
|
13151
|
+
* tracked `itemLoadedFields` metadata and whatever `inferFields` currently
|
|
13152
|
+
* vouches for (e.g. fields a mutation wrote beyond the tracked metadata).
|
|
13153
|
+
* Collapses to '*' when either side is '*' — the displayable set is then
|
|
13154
|
+
* not enumerable.
|
|
13155
|
+
*/
|
|
13156
|
+
function getInvalidationBaselineFields(itemKey) {
|
|
13157
|
+
const trackedLoadedFields = store.state.itemLoadedFields[itemKey];
|
|
13158
|
+
if (trackedLoadedFields === "*") return "*";
|
|
13159
|
+
if (!partialResources) return trackedLoadedFields;
|
|
13160
|
+
const itemState = store.state.items[itemKey];
|
|
13161
|
+
if (!itemState) return trackedLoadedFields;
|
|
13162
|
+
const inferredFields = partialResources.inferFields(itemState);
|
|
13163
|
+
if (inferredFields === "*") return "*";
|
|
13164
|
+
if (!trackedLoadedFields || trackedLoadedFields.length === 0) return inferredFields;
|
|
13165
|
+
return Array.from(new Set([...trackedLoadedFields, ...inferredFields]));
|
|
13166
|
+
}
|
|
13122
13167
|
function invalidateQueryAndItems(args) {
|
|
13123
13168
|
const itemPayload = args.all ? GET_ALL : args.itemPayload;
|
|
13124
13169
|
const queryPayload = args.all ? GET_ALL : args.queryPayload;
|
|
@@ -13146,29 +13191,49 @@ function createMutationApi(store, fetchItemFn, partialResources, optimisticListU
|
|
|
13146
13191
|
const itemsKey = getItemsKeyArray(itemPayload);
|
|
13147
13192
|
const nextInvalidationPriorityByItemKey = /* @__PURE__ */ new Map();
|
|
13148
13193
|
const nextPendingInvalidationFieldsByItemKey = /* @__PURE__ */ new Map();
|
|
13194
|
+
const staleInvalidateFieldsByItemKey = /* @__PURE__ */ new Map();
|
|
13149
13195
|
for (const { itemKey } of itemsKey) {
|
|
13196
|
+
const effectiveLoadedFields = getInvalidationBaselineFields(itemKey);
|
|
13197
|
+
const staleInvalidateFields = effectiveLoadedFields === "*" ? invalidateFields : invalidateFields.filter((field) => effectiveLoadedFields?.includes(field) ?? false);
|
|
13198
|
+
if (staleInvalidateFields.length < invalidateFields.length) {
|
|
13199
|
+
let droppedForItem = itemDroppedFieldInvalidations.get(itemKey);
|
|
13200
|
+
for (const field of invalidateFields) {
|
|
13201
|
+
if (staleInvalidateFields.includes(field)) continue;
|
|
13202
|
+
if (!droppedForItem) {
|
|
13203
|
+
droppedForItem = /* @__PURE__ */ new Map();
|
|
13204
|
+
itemDroppedFieldInvalidations.set(itemKey, droppedForItem);
|
|
13205
|
+
}
|
|
13206
|
+
const existingDropped = droppedForItem.get(field);
|
|
13207
|
+
droppedForItem.set(field, {
|
|
13208
|
+
invalidatedAt: Date.now(),
|
|
13209
|
+
priority: existingDropped && fetchTypePriority[existingDropped.priority] > fetchTypePriority[priority] ? existingDropped.priority : priority
|
|
13210
|
+
});
|
|
13211
|
+
}
|
|
13212
|
+
}
|
|
13213
|
+
if (staleInvalidateFields.length === 0) continue;
|
|
13214
|
+
staleInvalidateFieldsByItemKey.set(itemKey, staleInvalidateFields);
|
|
13150
13215
|
const existingPriority = itemFieldInvalidationPriorities.get(itemKey);
|
|
13151
13216
|
const existingPendingFields = itemPendingInvalidationFields.get(itemKey) ?? [];
|
|
13152
|
-
nextPendingInvalidationFieldsByItemKey.set(itemKey, Array.from(new Set([...existingPendingFields, ...
|
|
13217
|
+
nextPendingInvalidationFieldsByItemKey.set(itemKey, Array.from(new Set([...existingPendingFields, ...staleInvalidateFields])).sort());
|
|
13153
13218
|
nextInvalidationPriorityByItemKey.set(itemKey, existingPriority && fetchTypePriority[existingPriority] > fetchTypePriority[priority] ? existingPriority : priority);
|
|
13154
13219
|
}
|
|
13155
13220
|
for (const [itemKey, itemPriority] of nextInvalidationPriorityByItemKey) itemFieldInvalidationPriorities.set(itemKey, itemPriority);
|
|
13156
13221
|
for (const [itemKey, invalidationFields] of nextPendingInvalidationFieldsByItemKey) itemPendingInvalidationFields.set(itemKey, invalidationFields);
|
|
13157
13222
|
store.produceState((draft) => {
|
|
13158
|
-
for (const
|
|
13223
|
+
for (const [itemKey, staleInvalidateFields] of staleInvalidateFieldsByItemKey) {
|
|
13159
13224
|
const loadedFields = draft.itemLoadedFields[itemKey];
|
|
13160
13225
|
if (!loadedFields) continue;
|
|
13161
|
-
if (loadedFields !== "*") draft.itemLoadedFields[itemKey] = loadedFields.filter((f) => !
|
|
13226
|
+
if (loadedFields !== "*") draft.itemLoadedFields[itemKey] = loadedFields.filter((f) => !staleInvalidateFields.includes(f));
|
|
13162
13227
|
const existingInvalidationFields = draft.itemFieldInvalidationFields[itemKey] ?? [];
|
|
13163
|
-
draft.itemFieldInvalidationFields[itemKey] = Array.from(new Set([...existingInvalidationFields, ...
|
|
13228
|
+
draft.itemFieldInvalidationFields[itemKey] = Array.from(new Set([...existingInvalidationFields, ...staleInvalidateFields])).sort();
|
|
13164
13229
|
}
|
|
13165
13230
|
}, { action: "invalidate-item-fields" });
|
|
13166
|
-
for (const
|
|
13231
|
+
for (const [itemKey, staleInvalidateFields] of staleInvalidateFieldsByItemKey) {
|
|
13167
13232
|
itemInvalidationWasTriggered.delete(itemKey);
|
|
13168
13233
|
emitInvalidateItem({
|
|
13169
13234
|
priority: nextInvalidationPriorityByItemKey.get(itemKey) ?? priority,
|
|
13170
13235
|
itemKey,
|
|
13171
|
-
invalidateFields
|
|
13236
|
+
invalidateFields: staleInvalidateFields
|
|
13172
13237
|
});
|
|
13173
13238
|
}
|
|
13174
13239
|
} else invalidateItem(itemPayload, priority);
|
|
@@ -13179,11 +13244,7 @@ function createMutationApi(store, fetchItemFn, partialResources, optimisticListU
|
|
|
13179
13244
|
for (const { itemKey, payload } of itemsKey) {
|
|
13180
13245
|
const item = store.state.itemQueries[itemKey];
|
|
13181
13246
|
if (!item) continue;
|
|
13182
|
-
|
|
13183
|
-
if (partialResources && effectiveLoadedFields === void 0) {
|
|
13184
|
-
const itemState = store.state.items[itemKey];
|
|
13185
|
-
if (itemState) effectiveLoadedFields = partialResources.inferFields(itemState);
|
|
13186
|
-
}
|
|
13247
|
+
const effectiveLoadedFields = getInvalidationBaselineFields(itemKey);
|
|
13187
13248
|
const itemWasFullyLoaded = partialResources && effectiveLoadedFields === "*";
|
|
13188
13249
|
const trackedInvalidationFields = partialResources && !itemWasFullyLoaded ? Array.from(new Set([...effectiveLoadedFields === "*" ? [] : effectiveLoadedFields ?? [], ...itemPendingInvalidationFields.get(itemKey) ?? []])).sort() : [];
|
|
13189
13250
|
const trackedInvalidationPriority = trackedInvalidationFields.length > 0 || itemsPendingFullInvalidation.has(itemKey) ? itemFieldInvalidationPriorities.get(itemKey) : void 0;
|
|
@@ -13224,6 +13285,55 @@ function createMutationApi(store, fetchItemFn, partialResources, optimisticListU
|
|
|
13224
13285
|
}
|
|
13225
13286
|
}
|
|
13226
13287
|
}
|
|
13288
|
+
/**
|
|
13289
|
+
* Called when a fetch settles for `itemKeys` (item fetches and list fetches
|
|
13290
|
+
* that committed the items). Per-field invalidations of never-loaded fields
|
|
13291
|
+
* are dropped at invalidation time (see `invalidateQueryAndItems`) — but a
|
|
13292
|
+
* fetch that STARTED BEFORE such an invalidation commits a response
|
|
13293
|
+
* produced before it, so the just-loaded value may already be stale.
|
|
13294
|
+
* Re-announce those invalidations as a regular per-field invalidation (the
|
|
13295
|
+
* field now has a displayable value). Fields loaded by a fetch started
|
|
13296
|
+
* after the invalidation are fresh relative to it — their record is simply
|
|
13297
|
+
* discarded.
|
|
13298
|
+
*/
|
|
13299
|
+
function reannounceInvalidationsDroppedDuringFetch(itemKeys, fetchStartedAt) {
|
|
13300
|
+
for (const itemKey of itemKeys) {
|
|
13301
|
+
const droppedForItem = itemDroppedFieldInvalidations.get(itemKey);
|
|
13302
|
+
if (!droppedForItem) continue;
|
|
13303
|
+
const loadedFields = store.state.itemLoadedFields[itemKey];
|
|
13304
|
+
let staleFields;
|
|
13305
|
+
let stalePriority;
|
|
13306
|
+
for (const [field, dropped] of droppedForItem) {
|
|
13307
|
+
if (!(loadedFields === "*" || (loadedFields?.includes(field) ?? false))) continue;
|
|
13308
|
+
droppedForItem.delete(field);
|
|
13309
|
+
if (dropped.invalidatedAt > fetchStartedAt) {
|
|
13310
|
+
(staleFields ??= []).push(field);
|
|
13311
|
+
if (!stalePriority || fetchTypePriority[dropped.priority] > fetchTypePriority[stalePriority]) stalePriority = dropped.priority;
|
|
13312
|
+
}
|
|
13313
|
+
}
|
|
13314
|
+
if (droppedForItem.size === 0) itemDroppedFieldInvalidations.delete(itemKey);
|
|
13315
|
+
if (!staleFields || !stalePriority) continue;
|
|
13316
|
+
const existingPriority = itemFieldInvalidationPriorities.get(itemKey);
|
|
13317
|
+
const mergedPriority = existingPriority && fetchTypePriority[existingPriority] > fetchTypePriority[stalePriority] ? existingPriority : stalePriority;
|
|
13318
|
+
const existingPendingFields = itemPendingInvalidationFields.get(itemKey) ?? [];
|
|
13319
|
+
itemPendingInvalidationFields.set(itemKey, Array.from(new Set([...existingPendingFields, ...staleFields])).sort());
|
|
13320
|
+
itemFieldInvalidationPriorities.set(itemKey, mergedPriority);
|
|
13321
|
+
const staleFieldsToApply = staleFields;
|
|
13322
|
+
store.produceState((draft) => {
|
|
13323
|
+
const draftLoadedFields = draft.itemLoadedFields[itemKey];
|
|
13324
|
+
if (!draftLoadedFields) return;
|
|
13325
|
+
if (draftLoadedFields !== "*") draft.itemLoadedFields[itemKey] = draftLoadedFields.filter((f) => !staleFieldsToApply.includes(f));
|
|
13326
|
+
const existingInvalidationFields = draft.itemFieldInvalidationFields[itemKey] ?? [];
|
|
13327
|
+
draft.itemFieldInvalidationFields[itemKey] = Array.from(new Set([...existingInvalidationFields, ...staleFieldsToApply])).sort();
|
|
13328
|
+
}, { action: "invalidate-item-fields" });
|
|
13329
|
+
itemInvalidationWasTriggered.delete(itemKey);
|
|
13330
|
+
emitInvalidateItem({
|
|
13331
|
+
priority: mergedPriority,
|
|
13332
|
+
itemKey,
|
|
13333
|
+
invalidateFields: staleFields
|
|
13334
|
+
});
|
|
13335
|
+
}
|
|
13336
|
+
}
|
|
13227
13337
|
function startItemMutation(itemId) {
|
|
13228
13338
|
const itemsKey = getItemsKeyArray(itemId);
|
|
13229
13339
|
const endMutations = [];
|
|
@@ -13428,6 +13538,7 @@ function createMutationApi(store, fetchItemFn, partialResources, optimisticListU
|
|
|
13428
13538
|
itemFieldInvalidationPriorities.delete(itemKey);
|
|
13429
13539
|
itemPendingInvalidationFields.delete(itemKey);
|
|
13430
13540
|
itemsPendingFullInvalidation.delete(itemKey);
|
|
13541
|
+
itemDroppedFieldInvalidations.delete(itemKey);
|
|
13431
13542
|
itemInvalidationWasTriggered.delete(itemKey);
|
|
13432
13543
|
publishItemSnapshot(itemKey);
|
|
13433
13544
|
}
|
|
@@ -13440,6 +13551,7 @@ function createMutationApi(store, fetchItemFn, partialResources, optimisticListU
|
|
|
13440
13551
|
itemFieldInvalidationPriorities.clear();
|
|
13441
13552
|
itemPendingInvalidationFields.clear();
|
|
13442
13553
|
itemsPendingFullInvalidation.clear();
|
|
13554
|
+
itemDroppedFieldInvalidations.clear();
|
|
13443
13555
|
}
|
|
13444
13556
|
async function performMutation(payload, { optimisticUpdate, mutation, silentErrors, revalidateOnSuccess, onSuccess, onError, debounce, offline, upload }) {
|
|
13445
13557
|
const payloadToUse = payload === null ? [] : payload;
|
|
@@ -13521,6 +13633,7 @@ function createMutationApi(store, fetchItemFn, partialResources, optimisticListU
|
|
|
13521
13633
|
itemFieldInvalidationPriorities,
|
|
13522
13634
|
invalidateQueryAndItems,
|
|
13523
13635
|
invalidateItem,
|
|
13636
|
+
reannounceInvalidationsDroppedDuringFetch,
|
|
13524
13637
|
startItemMutation,
|
|
13525
13638
|
updateItemState,
|
|
13526
13639
|
addItemToState,
|
|
@@ -13922,10 +14035,10 @@ function useMultipleItems(items, { selector, loadFromStateOnly, returnIdleStatus
|
|
|
13922
14035
|
const fetchQueriesWithId = shouldDebounceFetchQueries ? debouncedFetchQueriesWithId : queriesWithId;
|
|
13923
14036
|
const offlineEntitiesByKey = useMemo(() => createOfflineEntityLookup(offlineEntities), [offlineEntities]);
|
|
13924
14037
|
const activeOfflineOverlays = useMemo(() => filterActiveOfflineOverlays(offlineEntitiesByKey, offlineOverlays), [offlineEntitiesByKey, offlineOverlays]);
|
|
13925
|
-
const getUnresolvedPendingInvalidationFields = useCallback((itemKey) => {
|
|
13926
|
-
const stateInvalidationFields = store.state.itemFieldInvalidationFields[itemKey];
|
|
14038
|
+
const getUnresolvedPendingInvalidationFields = useCallback((itemKey, state) => {
|
|
14039
|
+
const stateInvalidationFields = (state ? state.itemFieldInvalidationFields : store.state.itemFieldInvalidationFields)[itemKey];
|
|
13927
14040
|
if (stateInvalidationFields && stateInvalidationFields.length > 0) return stateInvalidationFields;
|
|
13928
|
-
return excludeLoadedFields(store.state.itemLoadedFields[itemKey], itemPendingInvalidationFields.get(itemKey));
|
|
14041
|
+
return excludeLoadedFields((state ? state.itemLoadedFields : store.state.itemLoadedFields)[itemKey], itemPendingInvalidationFields.get(itemKey));
|
|
13929
14042
|
}, [itemPendingInvalidationFields, store]);
|
|
13930
14043
|
const resultSelector = useCallback((state) => {
|
|
13931
14044
|
return queriesWithId.map(({ itemKey, payload, fields, returnIdleStatus, returnRefetchingStatus, showPartialAsRefetching, queryMetadata }) => {
|
|
@@ -13988,10 +14101,10 @@ function useMultipleItems(items, { selector, loadFromStateOnly, returnIdleStatus
|
|
|
13988
14101
|
let status = itemQuery.status;
|
|
13989
14102
|
const itemFieldInvalidationFields = state.itemFieldInvalidationFields[itemKey];
|
|
13990
14103
|
if (partialResources && Array.isArray(fields) && fields.length > 0 && (status === "success" || status === "refetching")) {
|
|
13991
|
-
if (
|
|
14104
|
+
if (getGenuinelyMissingRequestedFields(itemKey, {
|
|
13992
14105
|
item: rawItemState,
|
|
13993
14106
|
loadedFields
|
|
13994
|
-
}, fields, partialResources.inferFields).length > 0) status = hasCachedDataInState && showPartialAsRefetching ? "refetching" : "loading";
|
|
14107
|
+
}, fields, partialResources.inferFields, itemsPendingFullInvalidation, getUnresolvedPendingInvalidationFields(itemKey, state)).length > 0) status = hasCachedDataInState && showPartialAsRefetching ? "refetching" : "loading";
|
|
13995
14108
|
} else if (partialResources && fields === "*" && (status === "success" || status === "refetching")) {
|
|
13996
14109
|
const isIncomplete = !snapshotIsFullyLoaded(loadedFields, rawItemState, partialResources.inferFields) && !(itemsPendingFullInvalidation.has(itemKey) && hasCachedDataInState);
|
|
13997
14110
|
const isStale = !isIncomplete && !snapshotIsFullyLoadedAndFresh(itemKey, loadedFields, rawItemState, partialResources.inferFields, itemsPendingFullInvalidation);
|
|
@@ -14000,7 +14113,7 @@ function useMultipleItems(items, { selector, loadFromStateOnly, returnIdleStatus
|
|
|
14000
14113
|
}
|
|
14001
14114
|
if (partialResources && showPartialAsRefetching) {
|
|
14002
14115
|
if (Array.isArray(fields) && fields.length > 0) {
|
|
14003
|
-
const pendingRequestedFields = getStaleOrMissingRequestedFields(itemKey, loadedFields, rawItemState, fields, partialResources.inferFields, itemsPendingFullInvalidation, getUnresolvedPendingInvalidationFields(itemKey));
|
|
14116
|
+
const pendingRequestedFields = getStaleOrMissingRequestedFields(itemKey, loadedFields, rawItemState, fields, partialResources.inferFields, itemsPendingFullInvalidation, getUnresolvedPendingInvalidationFields(itemKey, state));
|
|
14004
14117
|
if (pendingRequestedFields.length > 0) loadingFields = pendingRequestedFields;
|
|
14005
14118
|
} else if (fields === "*") {
|
|
14006
14119
|
if (hasFullyLoadedFields(loadedFields) && itemFieldInvalidationFields && itemFieldInvalidationFields.length > 0) loadingFields = itemFieldInvalidationFields;
|
|
@@ -14035,7 +14148,7 @@ function useMultipleItems(items, { selector, loadFromStateOnly, returnIdleStatus
|
|
|
14035
14148
|
return queriesWithId.map(({ itemKey, fields }) => {
|
|
14036
14149
|
const itemQuery = state.itemQueries[itemKey];
|
|
14037
14150
|
const loadedFields = state.itemLoadedFields[itemKey] ?? [];
|
|
14038
|
-
const missingRequestedFields = partialResources && Array.isArray(fields) && fields.length > 0 ? getStaleOrMissingRequestedFields(itemKey, state.itemLoadedFields[itemKey], state.items[itemKey], fields, partialResources.inferFields, itemsPendingFullInvalidation, getUnresolvedPendingInvalidationFields(itemKey)).sort() : [];
|
|
14151
|
+
const missingRequestedFields = partialResources && Array.isArray(fields) && fields.length > 0 ? getStaleOrMissingRequestedFields(itemKey, state.itemLoadedFields[itemKey], state.items[itemKey], fields, partialResources.inferFields, itemsPendingFullInvalidation, getUnresolvedPendingInvalidationFields(itemKey, state)).sort() : [];
|
|
14039
14152
|
const needsFullFetch = partialResources && fields === "*" ? !snapshotIsFullyLoaded(loadedFields, state.items[itemKey], partialResources.inferFields) || itemsPendingFullInvalidation.has(itemKey) && !hasFullyLoadedFields(loadedFields) : false;
|
|
14040
14153
|
return {
|
|
14041
14154
|
status: itemQuery?.status ?? null,
|
|
@@ -14123,23 +14236,42 @@ function useMultipleItems(items, { selector, loadFromStateOnly, returnIdleStatus
|
|
|
14123
14236
|
store,
|
|
14124
14237
|
visibleStoreState
|
|
14125
14238
|
]);
|
|
14239
|
+
const ignoreItemsInRefetchOnMount = useConst(() => /* @__PURE__ */ new Set());
|
|
14126
14240
|
useOnEvtmitterEvent(events, "invalidateItem", ({ payload: event }) => {
|
|
14127
14241
|
if (loadFromStateOnly || !fetchItemFn) return;
|
|
14128
|
-
const
|
|
14242
|
+
const queriesForItem = fetchQueriesWithId.filter(({ itemKey }) => itemKey === event.itemKey);
|
|
14243
|
+
let fieldsToFetch;
|
|
14244
|
+
if (event.invalidateFields && event.invalidateFields.length > 0) fieldsToFetch = Array.from(new Set(event.invalidateFields)).sort();
|
|
14245
|
+
const hasUnresolvedFullInvalidation = itemsPendingFullInvalidation.has(event.itemKey);
|
|
14246
|
+
const loadedFields = store.state.itemLoadedFields[event.itemKey];
|
|
14247
|
+
const owedStaleFields = new Set([...store.state.itemFieldInvalidationFields[event.itemKey] ?? [], ...excludeLoadedFields(loadedFields, itemPendingInvalidationFields.get(event.itemKey))]);
|
|
14248
|
+
const affectedQueries = fieldsToFetch ? queriesForItem.filter(({ fields }) => {
|
|
14249
|
+
if (fields === "*") return true;
|
|
14250
|
+
if (!fields || fields.length === 0) return true;
|
|
14251
|
+
if (fields.some((field) => event.invalidateFields?.includes(field))) return true;
|
|
14252
|
+
return hasUnresolvedFullInvalidation ? excludeLoadedFields(loadedFields, fields).length > 0 : fields.some((field) => owedStaleFields.has(field));
|
|
14253
|
+
}) : queriesForItem;
|
|
14254
|
+
if (affectedQueries.length === 0) return;
|
|
14255
|
+
ignoreItemsInRefetchOnMount.delete(event.itemKey);
|
|
14256
|
+
const matchingQueries = affectedQueries.filter(({ isOffScreen }) => !isOffScreen);
|
|
14129
14257
|
if (matchingQueries.length === 0) return;
|
|
14130
|
-
if (itemInvalidationWasTriggered.has(event.itemKey)) return;
|
|
14131
14258
|
if (matchingQueries.every((q) => q.disableRefetches) && store.state.itemQueries[event.itemKey]?.wasLoaded) return;
|
|
14132
|
-
let fieldsToFetch;
|
|
14133
|
-
if (event.invalidateFields && event.invalidateFields.length > 0) {
|
|
14134
|
-
fieldsToFetch = Array.from(new Set(event.invalidateFields)).sort();
|
|
14135
|
-
if (!matchingQueries.some(({ fields }) => {
|
|
14136
|
-
if (fields === "*") return true;
|
|
14137
|
-
if (!fields || fields.length === 0) return true;
|
|
14138
|
-
return fields.some((field) => event.invalidateFields?.includes(field));
|
|
14139
|
-
})) return;
|
|
14140
|
-
}
|
|
14141
14259
|
const firstQuery = matchingQueries[0];
|
|
14142
14260
|
if (!firstQuery) return;
|
|
14261
|
+
const hookFields = firstQuery.fields;
|
|
14262
|
+
const isUnboundedHook = !hookFields || hookFields === "*" || hookFields.length === 0;
|
|
14263
|
+
if (itemInvalidationWasTriggered.has(event.itemKey)) {
|
|
14264
|
+
if (!fieldsToFetch) return;
|
|
14265
|
+
const contributionFields = hasUnresolvedFullInvalidation ? isUnboundedHook ? void 0 : excludeLoadedFields(loadedFields, hookFields) : isUnboundedHook ? Array.from(owedStaleFields) : hookFields.filter((field) => owedStaleFields.has(field));
|
|
14266
|
+
if (contributionFields && contributionFields.length === 0) return;
|
|
14267
|
+
scheduleAutomaticItemFetch(event.priority, firstQuery.payload, { fields: contributionFields });
|
|
14268
|
+
return;
|
|
14269
|
+
}
|
|
14270
|
+
if (fieldsToFetch) if (hasUnresolvedFullInvalidation) fieldsToFetch = isUnboundedHook ? void 0 : Array.from(new Set([...fieldsToFetch, ...excludeLoadedFields(loadedFields, hookFields)])).sort();
|
|
14271
|
+
else {
|
|
14272
|
+
const rideAlongFields = isUnboundedHook ? Array.from(owedStaleFields) : hookFields.filter((field) => owedStaleFields.has(field));
|
|
14273
|
+
fieldsToFetch = Array.from(new Set([...fieldsToFetch, ...rideAlongFields])).sort();
|
|
14274
|
+
}
|
|
14143
14275
|
store.produceState((draft) => {
|
|
14144
14276
|
const query = draft.itemQueries[event.itemKey];
|
|
14145
14277
|
if (!query?.refetchOnMount) return;
|
|
@@ -14148,7 +14280,6 @@ function useMultipleItems(items, { selector, loadFromStateOnly, returnIdleStatus
|
|
|
14148
14280
|
scheduleAutomaticItemFetch(event.priority, firstQuery.payload, { fields: fieldsToFetch ?? firstQuery.fields });
|
|
14149
14281
|
itemInvalidationWasTriggered.add(event.itemKey);
|
|
14150
14282
|
});
|
|
14151
|
-
const ignoreItemsInRefetchOnMount = useConst(() => /* @__PURE__ */ new Set());
|
|
14152
14283
|
useLayoutEffect(() => {
|
|
14153
14284
|
if (loadFromStateOnly || !preloadItemsBeforePaint || !preloadItems || fetchQueriesWithId.length < 1) return;
|
|
14154
14285
|
preloadItems(fetchQueriesWithId.map(({ payload }) => payload));
|
|
@@ -14185,28 +14316,32 @@ function useMultipleItems(items, { selector, loadFromStateOnly, returnIdleStatus
|
|
|
14185
14316
|
const hasUnresolvedFullInvalidation = itemsPendingFullInvalidation.has(itemKey) && !hasFullyLoadedFields(loadedFields);
|
|
14186
14317
|
const invalidationPriority = unresolvedPendingInvalidationFields.length > 0 || hasUnresolvedFullInvalidation ? itemFieldInvalidationPriorities.get(itemKey) : void 0;
|
|
14187
14318
|
if (Array.isArray(fields) && fields.length > 0) {
|
|
14188
|
-
const affectedInvalidationFields = fields.filter((field) => unresolvedPendingInvalidationFields.includes(field));
|
|
14189
14319
|
const staleOrMissingFields = getStaleOrMissingRequestedFields(itemKey, loadedFields, item, fields, partialResources.inferFields, itemsPendingFullInvalidation, unresolvedPendingInvalidationFields);
|
|
14190
|
-
const missingFields =
|
|
14320
|
+
const missingFields = getGenuinelyMissingRequestedFields(itemKey, {
|
|
14321
|
+
item,
|
|
14322
|
+
loadedFields
|
|
14323
|
+
}, fields, partialResources.inferFields, itemsPendingFullInvalidation, unresolvedPendingInvalidationFields);
|
|
14324
|
+
const staleInvalidatedFields = staleOrMissingFields.filter((field) => !missingFields.includes(field));
|
|
14191
14325
|
const hasMissingFields = missingFields.length > 0;
|
|
14192
|
-
const
|
|
14193
|
-
const shouldFetchForInvalidation =
|
|
14326
|
+
const hasStaleInvalidatedFields = staleInvalidatedFields.length > 0;
|
|
14327
|
+
const shouldFetchForInvalidation = hasStaleInvalidatedFields && (!invalidationPriority || !ignoreItemsInRefetchOnMount.has(itemKey));
|
|
14194
14328
|
if ((hasMissingFields || shouldFetchForInvalidation) && !itemFetchIsActive) {
|
|
14195
14329
|
shouldFetch = true;
|
|
14196
14330
|
requiredFetch = true;
|
|
14197
|
-
fieldsToFetch = Array.from(new Set([...missingFields, ...
|
|
14198
|
-
if (fetchType === "lowPriority") fetchType = "highPriority";
|
|
14331
|
+
fieldsToFetch = Array.from(new Set([...missingFields, ...staleInvalidatedFields]));
|
|
14332
|
+
if ((hasMissingFields || !invalidationPriority) && fetchType === "lowPriority") fetchType = "highPriority";
|
|
14199
14333
|
}
|
|
14200
|
-
if (
|
|
14334
|
+
if (hasStaleInvalidatedFields && !hasMissingFields && invalidationPriority && fetchTypePriority[invalidationPriority] > fetchTypePriority[fetchType]) fetchType = invalidationPriority;
|
|
14201
14335
|
} else if (fields === "*") {
|
|
14202
|
-
const
|
|
14203
|
-
const
|
|
14336
|
+
const hasStaleFullInvalidation = hasUnresolvedFullInvalidation && !!item;
|
|
14337
|
+
const missingFullItem = !hasStaleFullInvalidation && (!snapshotIsFullyLoaded(loadedFields, item, partialResources.inferFields) || hasUnresolvedFullInvalidation);
|
|
14338
|
+
const shouldFetchForInvalidation = !missingFullItem && (unresolvedPendingInvalidationFields.length > 0 || hasStaleFullInvalidation) && (!invalidationPriority || !ignoreItemsInRefetchOnMount.has(itemKey));
|
|
14204
14339
|
if ((missingFullItem || shouldFetchForInvalidation) && !itemFetchIsActive) {
|
|
14205
14340
|
shouldFetch = true;
|
|
14206
14341
|
requiredFetch = true;
|
|
14207
|
-
fieldsToFetch = missingFullItem ? "*" : unresolvedPendingInvalidationFields;
|
|
14208
|
-
if (fetchType === "lowPriority") fetchType = "highPriority";
|
|
14209
|
-
if (invalidationPriority && fetchTypePriority[invalidationPriority] > fetchTypePriority[fetchType]) fetchType = invalidationPriority;
|
|
14342
|
+
fieldsToFetch = missingFullItem || hasStaleFullInvalidation ? "*" : unresolvedPendingInvalidationFields;
|
|
14343
|
+
if ((missingFullItem || !invalidationPriority) && fetchType === "lowPriority") fetchType = "highPriority";
|
|
14344
|
+
if (!missingFullItem && invalidationPriority && fetchTypePriority[invalidationPriority] > fetchTypePriority[fetchType]) fetchType = invalidationPriority;
|
|
14210
14345
|
}
|
|
14211
14346
|
}
|
|
14212
14347
|
}
|
|
@@ -14357,14 +14492,20 @@ function useMultipleListQueries(queries, { itemSelector, returnIdleStatus: allIt
|
|
|
14357
14492
|
let highestPriority;
|
|
14358
14493
|
for (const itemKey of itemKeys) {
|
|
14359
14494
|
const unresolvedInvalidationFields = getUnresolvedPendingInvalidationFields(itemKey);
|
|
14360
|
-
|
|
14361
|
-
if (
|
|
14495
|
+
const hasUnresolvedFullInvalidation = itemsPendingFullInvalidation.has(itemKey) && !hasFullyLoadedFields(store.state.itemLoadedFields[itemKey]);
|
|
14496
|
+
if (unresolvedInvalidationFields.length === 0 && !hasUnresolvedFullInvalidation) continue;
|
|
14497
|
+
if (!hasUnresolvedFullInvalidation && requestedFields && !requestedFields.some((field) => unresolvedInvalidationFields.includes(field))) continue;
|
|
14362
14498
|
const itemPriority = itemFieldInvalidationPriorities.get(itemKey);
|
|
14363
14499
|
if (!itemPriority) continue;
|
|
14364
14500
|
if (!highestPriority || fetchTypePriority[itemPriority] > fetchTypePriority[highestPriority]) highestPriority = itemPriority;
|
|
14365
14501
|
}
|
|
14366
14502
|
return highestPriority;
|
|
14367
|
-
}, [
|
|
14503
|
+
}, [
|
|
14504
|
+
getUnresolvedPendingInvalidationFields,
|
|
14505
|
+
itemFieldInvalidationPriorities,
|
|
14506
|
+
itemsPendingFullInvalidation,
|
|
14507
|
+
store
|
|
14508
|
+
]);
|
|
14368
14509
|
const getVisibleQueryItemKeys = useCallback((queryKey, itemKeys) => {
|
|
14369
14510
|
const missingOverlayItems = overlayItemsByQueryKey.get(queryKey);
|
|
14370
14511
|
const hasDeletions = deletedOverlayItemKeys.size > 0;
|
|
@@ -14513,10 +14654,10 @@ function useMultipleListQueries(queries, { itemSelector, returnIdleStatus: allIt
|
|
|
14513
14654
|
}
|
|
14514
14655
|
}
|
|
14515
14656
|
if (partialResources && Array.isArray(fields) && statusCanBeOverridden && staleOrMissingRequestedFields && staleOrMissingRequestedFields.size > 0) {
|
|
14516
|
-
const someItemMissingFieldDataInState = effectiveQuery.query.items.some((itemKey) =>
|
|
14657
|
+
const someItemMissingFieldDataInState = effectiveQuery.query.items.some((itemKey) => getGenuinelyMissingRequestedFields(itemKey, {
|
|
14517
14658
|
item: state.items[itemKey],
|
|
14518
14659
|
loadedFields: state.itemLoadedFields[itemKey]
|
|
14519
|
-
}, fields, partialResources.inferFields).length > 0);
|
|
14660
|
+
}, fields, partialResources.inferFields, itemsPendingFullInvalidation, getUnresolvedPendingInvalidationFields(itemKey, state)).length > 0);
|
|
14520
14661
|
if (!hasCachedItemsInState) status = "loading";
|
|
14521
14662
|
else if (someItemMissingFieldDataInState) status = showPartialAsRefetching ? "refetching" : "loading";
|
|
14522
14663
|
else status = "refetching";
|
|
@@ -14686,9 +14827,9 @@ function useMultipleListQueries(queries, { itemSelector, returnIdleStatus: allIt
|
|
|
14686
14827
|
store,
|
|
14687
14828
|
visibleStoreState
|
|
14688
14829
|
]);
|
|
14830
|
+
const pendingOffScreenQueryInvalidations = useConst(() => /* @__PURE__ */ new Map());
|
|
14689
14831
|
useOnEvtmitterEvent(events, "invalidateQuery", ({ payload: event }) => {
|
|
14690
14832
|
for (const { key, payload, fields, loadSize, isOffScreen, disableRefetches } of fetchQueriesWithId) {
|
|
14691
|
-
if (isOffScreen) continue;
|
|
14692
14833
|
if (key !== event.queryKey) continue;
|
|
14693
14834
|
const resolvedQuery = resolveEffectiveQuery(store.state, {
|
|
14694
14835
|
key,
|
|
@@ -14696,6 +14837,11 @@ function useMultipleListQueries(queries, { itemSelector, returnIdleStatus: allIt
|
|
|
14696
14837
|
fields
|
|
14697
14838
|
});
|
|
14698
14839
|
if (disableRefetches && resolvedQuery?.query.wasLoaded) continue;
|
|
14840
|
+
if (isOffScreen) {
|
|
14841
|
+
const existingPriority = pendingOffScreenQueryInvalidations.get(key);
|
|
14842
|
+
if (!existingPriority || fetchTypePriority[event.priority] > fetchTypePriority[existingPriority]) pendingOffScreenQueryInvalidations.set(key, event.priority);
|
|
14843
|
+
continue;
|
|
14844
|
+
}
|
|
14699
14845
|
if (!queryInvalidationWasTriggered.has(key)) {
|
|
14700
14846
|
stickyDerivedQueryKeys.delete(key);
|
|
14701
14847
|
store.produceState((draft) => {
|
|
@@ -14703,9 +14849,9 @@ function useMultipleListQueries(queries, { itemSelector, returnIdleStatus: allIt
|
|
|
14703
14849
|
if (!query?.refetchOnMount) return;
|
|
14704
14850
|
query.refetchOnMount = false;
|
|
14705
14851
|
});
|
|
14706
|
-
scheduleAutomaticListQueryFetch(event.priority, payload, loadSize, { fields });
|
|
14707
14852
|
queryInvalidationWasTriggered.add(key);
|
|
14708
14853
|
}
|
|
14854
|
+
scheduleAutomaticListQueryFetch(event.priority, payload, loadSize, { fields });
|
|
14709
14855
|
}
|
|
14710
14856
|
});
|
|
14711
14857
|
const ignoreQueriesInRefetchOnMount = useConst(() => /* @__PURE__ */ new Set());
|
|
@@ -14754,35 +14900,59 @@ function useMultipleListQueries(queries, { itemSelector, returnIdleStatus: allIt
|
|
|
14754
14900
|
if (partialResources && !shouldFetch && effectiveQueryState) {
|
|
14755
14901
|
const isQueryFetchInFlight = effectiveQueryState.status === "loading" || effectiveQueryState.status === "refetching" || effectiveQueryState.status === "loadingMore";
|
|
14756
14902
|
if (Array.isArray(fields) && fields.length > 0) {
|
|
14757
|
-
|
|
14758
|
-
|
|
14759
|
-
|
|
14760
|
-
|
|
14761
|
-
if (
|
|
14903
|
+
let hasStaleOrMissingRequestedFields = false;
|
|
14904
|
+
let hasGenuinelyMissingFields = false;
|
|
14905
|
+
for (const itemKey of effectiveQueryState.items) {
|
|
14906
|
+
const unresolvedInvalidationFields = getUnresolvedPendingInvalidationFields(itemKey);
|
|
14907
|
+
if (getStaleOrMissingRequestedFields(itemKey, store.state.itemLoadedFields[itemKey], store.state.items[itemKey], fields, partialResources.inferFields, itemsPendingFullInvalidation, unresolvedInvalidationFields).length === 0) continue;
|
|
14908
|
+
hasStaleOrMissingRequestedFields = true;
|
|
14909
|
+
if (getGenuinelyMissingRequestedFields(itemKey, {
|
|
14910
|
+
item: store.state.items[itemKey],
|
|
14911
|
+
loadedFields: store.state.itemLoadedFields[itemKey]
|
|
14912
|
+
}, fields, partialResources.inferFields, itemsPendingFullInvalidation, unresolvedInvalidationFields).length > 0) {
|
|
14913
|
+
hasGenuinelyMissingFields = true;
|
|
14914
|
+
break;
|
|
14915
|
+
}
|
|
14762
14916
|
}
|
|
14763
|
-
if (
|
|
14764
|
-
const itemFieldInvalidationFields = getUnresolvedPendingInvalidationFields(itemKey);
|
|
14765
|
-
return itemFieldInvalidationFields.length > 0 && fields.some((f) => itemFieldInvalidationFields.includes(f));
|
|
14766
|
-
}) && !isQueryFetchInFlight) {
|
|
14917
|
+
if (hasStaleOrMissingRequestedFields && !isQueryFetchInFlight) {
|
|
14767
14918
|
shouldFetch = true;
|
|
14768
14919
|
requiredFetch = true;
|
|
14769
14920
|
fieldsToFetch = fields;
|
|
14770
|
-
const invalidationPriority = getHighestPendingInvalidationPriority(effectiveQueryState.items, fields);
|
|
14771
|
-
if (invalidationPriority
|
|
14921
|
+
const invalidationPriority = hasGenuinelyMissingFields ? void 0 : getHighestPendingInvalidationPriority(effectiveQueryState.items, fields);
|
|
14922
|
+
if (!invalidationPriority) {
|
|
14923
|
+
if (fetchType === "lowPriority") fetchType = "highPriority";
|
|
14924
|
+
} else if (fetchTypePriority[invalidationPriority] > fetchTypePriority[fetchType]) fetchType = invalidationPriority;
|
|
14772
14925
|
}
|
|
14773
14926
|
} else if (fields === "*") {
|
|
14774
|
-
|
|
14775
|
-
|
|
14776
|
-
|
|
14777
|
-
|
|
14778
|
-
|
|
14927
|
+
let hasStaleItemData = false;
|
|
14928
|
+
let hasGenuinelyMissingItemData = false;
|
|
14929
|
+
for (const itemKey of effectiveQueryState.items) {
|
|
14930
|
+
const item = store.state.items[itemKey];
|
|
14931
|
+
const loadedFields = store.state.itemLoadedFields[itemKey];
|
|
14932
|
+
const hasUnresolvedFullInvalidation = itemsPendingFullInvalidation.has(itemKey) && !hasFullyLoadedFields(loadedFields);
|
|
14933
|
+
const hasStaleFullInvalidation = hasUnresolvedFullInvalidation && !!item;
|
|
14934
|
+
if (!hasStaleFullInvalidation && (!snapshotIsFullyLoaded(loadedFields, item, partialResources.inferFields) || hasUnresolvedFullInvalidation)) {
|
|
14935
|
+
hasGenuinelyMissingItemData = true;
|
|
14936
|
+
break;
|
|
14937
|
+
}
|
|
14938
|
+
if (hasStaleFullInvalidation || getUnresolvedPendingInvalidationFields(itemKey).length > 0) hasStaleItemData = true;
|
|
14939
|
+
}
|
|
14940
|
+
if ((hasGenuinelyMissingItemData || hasStaleItemData) && !isQueryFetchInFlight) {
|
|
14779
14941
|
shouldFetch = true;
|
|
14780
14942
|
requiredFetch = true;
|
|
14781
|
-
const invalidationPriority = getHighestPendingInvalidationPriority(effectiveQueryState.items, void 0);
|
|
14782
|
-
if (invalidationPriority
|
|
14943
|
+
const invalidationPriority = hasGenuinelyMissingItemData ? void 0 : getHighestPendingInvalidationPriority(effectiveQueryState.items, void 0);
|
|
14944
|
+
if (!invalidationPriority) {
|
|
14945
|
+
if (fetchType === "lowPriority") fetchType = "highPriority";
|
|
14946
|
+
} else if (fetchTypePriority[invalidationPriority] > fetchTypePriority[fetchType]) fetchType = invalidationPriority;
|
|
14783
14947
|
}
|
|
14784
14948
|
}
|
|
14785
14949
|
}
|
|
14950
|
+
const offScreenInvalidationPriority = pendingOffScreenQueryInvalidations.get(queryId);
|
|
14951
|
+
if (offScreenInvalidationPriority !== void 0) {
|
|
14952
|
+
pendingOffScreenQueryInvalidations.delete(queryId);
|
|
14953
|
+
shouldFetch = true;
|
|
14954
|
+
if (fetchTypePriority[offScreenInvalidationPriority] > fetchTypePriority[fetchType]) fetchType = offScreenInvalidationPriority;
|
|
14955
|
+
}
|
|
14786
14956
|
if (!shouldFetch && ignoreQueriesInRefetchOnMount.has(queryId)) continue;
|
|
14787
14957
|
ignoreQueriesInRefetchOnMount.add(queryId);
|
|
14788
14958
|
if (shouldScheduleAutomaticFetch(effectiveQueryState?.wasLoaded, shouldFetch, disableRefetches, disableRefetchOnMount, !!partialResources) && tryClaimAutomaticFetchSlot(automaticRetryState, retrySignature, effectiveQueryState?.status)) {
|
|
@@ -14799,6 +14969,7 @@ function useMultipleListQueries(queries, { itemSelector, returnIdleStatus: allIt
|
|
|
14799
14969
|
getQueryState,
|
|
14800
14970
|
getDerivedPreloadPayloads,
|
|
14801
14971
|
ignoreQueriesInRefetchOnMount,
|
|
14972
|
+
pendingOffScreenQueryInvalidations,
|
|
14802
14973
|
preloadDerivedQueryItems,
|
|
14803
14974
|
preloadQueries,
|
|
14804
14975
|
preloadQueriesBeforePaint,
|
|
@@ -15221,6 +15392,7 @@ function createListQueryStore(storeOptions) {
|
|
|
15221
15392
|
}
|
|
15222
15393
|
const itemPendingInvalidationFields = /* @__PURE__ */ new Map();
|
|
15223
15394
|
const itemsPendingFullInvalidation = /* @__PURE__ */ new Set();
|
|
15395
|
+
const itemDroppedFieldInvalidations = /* @__PURE__ */ new Map();
|
|
15224
15396
|
const { getQueryState, getQueriesKeyArray, getQueriesState, getQueriesRelatedToItem, getItemsKeyArray, getItemState, scheduleListQueryFetch, loadMore, awaitListQueryFetch, getQueryFromStateOrFetch, scheduleItemFetch, awaitItemFetch, getItemFromStateOrFetch, getOrCreateQueryScheduler, getOrCreateItemScheduler, getKnownQueryScheduler, getKnownItemScheduler, syncRemoteFetchStart, syncRemoteFetchSuccess, deleteQueryFetchResources, deleteItemFetchResources, resetSchedulers, reevaluateDelayedRTUs } = createFetchApi(store, normalizedFetchListFn, offsetPagination, fetchItemFn, batchFetchItemFn, getItemsBatchKey, errorNormalizer, partialResources, lowPriorityThrottleMs, getCoalescingWindowMs, mediumPriorityDelayMs, wrappedDynamicRealtimeThrottleMs, onSchedulerEvent, usesRealTimeUpdates, defaultQuerySize, maxItemBatchSize, getQueryKey, getItemKey, normalizeFieldsOption, !!persistence && !persistence.hasAsyncPreload, persistence ? (queryKeys) => persistence.preloadQueries(queryKeys) : void 0, persistence ? (itemKeys) => persistence.preloadItems(itemKeys) : void 0, persistence, testOptions?.initialLastFetchStartTime, (requests, startedAt) => {
|
|
15225
15397
|
const queryKey = requests[0]?.requestId;
|
|
15226
15398
|
if (!queryKey) return;
|
|
@@ -15234,8 +15406,10 @@ function createListQueryStore(storeOptions) {
|
|
|
15234
15406
|
pruneItemInvalidationTracking();
|
|
15235
15407
|
const successfulQueryKeys = requests.filter(({ requestId }) => results.get(requestId) === true).map(({ requestId }) => requestId);
|
|
15236
15408
|
if (successfulQueryKeys.length > 0) {
|
|
15409
|
+
const committedItemKeys = successfulQueryKeys.flatMap((queryKey) => store.state.queries[queryKey]?.items ?? []);
|
|
15237
15410
|
touchQueries(successfulQueryKeys);
|
|
15238
|
-
touchItems(
|
|
15411
|
+
touchItems(committedItemKeys);
|
|
15412
|
+
reannounceInvalidationsDroppedDuringFetch(committedItemKeys, startedAt);
|
|
15239
15413
|
if (shouldScheduleCacheLimitEnforcement()) scheduleCacheLimitEnforcement();
|
|
15240
15414
|
}
|
|
15241
15415
|
const firstQueryKey = successfulQueryKeys[0];
|
|
@@ -15265,7 +15439,9 @@ function createListQueryStore(storeOptions) {
|
|
|
15265
15439
|
pruneItemInvalidationTracking();
|
|
15266
15440
|
const successfulItems = requests.filter(({ requestId }) => results.get(requestId) === true).map((request) => ({ itemKey: request.requestId }));
|
|
15267
15441
|
if (successfulItems.length > 0) {
|
|
15268
|
-
|
|
15442
|
+
const committedItemKeys = successfulItems.map(({ itemKey }) => itemKey);
|
|
15443
|
+
touchItems(committedItemKeys);
|
|
15444
|
+
reannounceInvalidationsDroppedDuringFetch(committedItemKeys, startedAt);
|
|
15269
15445
|
if (shouldScheduleCacheLimitEnforcement()) scheduleCacheLimitEnforcement();
|
|
15270
15446
|
}
|
|
15271
15447
|
const firstSuccessfulItem = successfulItems[0];
|
|
@@ -15283,11 +15459,11 @@ function createListQueryStore(storeOptions) {
|
|
|
15283
15459
|
for (const { itemKey } of successfulItems) publishItemSnapshot(itemKey, "confirmed");
|
|
15284
15460
|
}
|
|
15285
15461
|
}, offlineFetchController, itemPendingInvalidationFields, itemsPendingFullInvalidation);
|
|
15286
|
-
const { storeEvents, queryInvalidationWasTriggered, itemInvalidationWasTriggered, itemFieldInvalidationPriorities, invalidateQueryAndItems, invalidateItem, startItemMutation, updateItemState: updateItemStateBase, addItemToState: addItemToStateBase, deleteItemState: deleteItemStateBase, resetInvalidationTracking, performMutation: performMutationBase } = createMutationApi(store, fetchItemFn, partialResources, optimisticListUpdates, onInvalidateQuery, onInvalidateItem, resolvedOnMutationError, errorNormalizer, getItemKey, getQueriesKeyArray, getQueriesRelatedToItem, getItemsKeyArray, getOrCreateItemScheduler, getOrCreateQueryScheduler, deleteItemFetchResources, (event) => {
|
|
15462
|
+
const { storeEvents, queryInvalidationWasTriggered, itemInvalidationWasTriggered, itemFieldInvalidationPriorities, invalidateQueryAndItems, invalidateItem, reannounceInvalidationsDroppedDuringFetch, startItemMutation, updateItemState: updateItemStateBase, addItemToState: addItemToStateBase, deleteItemState: deleteItemStateBase, resetInvalidationTracking, performMutation: performMutationBase } = createMutationApi(store, fetchItemFn, partialResources, optimisticListUpdates, onInvalidateQuery, onInvalidateItem, resolvedOnMutationError, errorNormalizer, getItemKey, getQueriesKeyArray, getQueriesRelatedToItem, getItemsKeyArray, getOrCreateItemScheduler, getOrCreateQueryScheduler, deleteItemFetchResources, (event) => {
|
|
15287
15463
|
events.emit("invalidateQuery", event);
|
|
15288
15464
|
}, (event) => {
|
|
15289
15465
|
events.emit("invalidateItem", event);
|
|
15290
|
-
}, blockWindowClose, resolvedOfflineConfig ? offlineMutationController : null, runWithBroadcastConsistency, publishQuerySnapshot, publishItemSnapshot, void 0, itemPendingInvalidationFields, itemsPendingFullInvalidation);
|
|
15466
|
+
}, blockWindowClose, resolvedOfflineConfig ? offlineMutationController : null, runWithBroadcastConsistency, publishQuerySnapshot, publishItemSnapshot, void 0, itemPendingInvalidationFields, itemsPendingFullInvalidation, itemDroppedFieldInvalidations);
|
|
15291
15467
|
if (resolvedPersistentStorageConfig && resolvedOfflineConfig) offlineController = createOfflineStoreController(id, "listQuery", getSessionKeyForRuntime, resolvedPersistentStorageConfig.onPersistentStorageError, import.meta.env.DEV ? storeManager.debugLogger : void 0, resolvedPersistentStorageConfig.adapter, {
|
|
15292
15468
|
normalizeEntityRefs: (entityRefs) => entityRefs.map((ref) => {
|
|
15293
15469
|
const normalizedRef = offlineItemEntityRefSchema.parse(ref).unwrapOrNull();
|
|
@@ -15370,6 +15546,37 @@ function createListQueryStore(storeOptions) {
|
|
|
15370
15546
|
if (remainingFields.length > 0) draft.itemFieldInvalidationFields[itemKey] = remainingFields;
|
|
15371
15547
|
else delete draft.itemFieldInvalidationFields[itemKey];
|
|
15372
15548
|
}
|
|
15549
|
+
/**
|
|
15550
|
+
* A confirmed remote snapshot cancels the pending local fetches it
|
|
15551
|
+
* satisfies, but the sender may have refetched only a subset of the
|
|
15552
|
+
* invalidated fields (it fetches only its own hooks' fields). Any fields
|
|
15553
|
+
* still owed after applying the snapshot are re-announced so mounted hooks
|
|
15554
|
+
* re-schedule refetches of their own remaining stale fields — without
|
|
15555
|
+
* this, the cancelled local refetch would leave them stale forever.
|
|
15556
|
+
*
|
|
15557
|
+
* Only called when the snapshot actually cancelled a pending local fetch:
|
|
15558
|
+
* that cancellation is the refetch obligation being destroyed, and gating
|
|
15559
|
+
* on it also guarantees the cross-tab re-announce ping-pong terminates —
|
|
15560
|
+
* a repeat cycle requires a new pending fetch at snapshot arrival.
|
|
15561
|
+
*/
|
|
15562
|
+
function emitRemainingInvalidationFieldsAfterSnapshot(itemKey) {
|
|
15563
|
+
const priority = itemFieldInvalidationPriorities.get(itemKey) ?? "highPriority";
|
|
15564
|
+
if (itemsPendingFullInvalidation.has(itemKey)) {
|
|
15565
|
+
events.emit("invalidateItem", {
|
|
15566
|
+
priority,
|
|
15567
|
+
itemKey
|
|
15568
|
+
});
|
|
15569
|
+
return;
|
|
15570
|
+
}
|
|
15571
|
+
const stateInvalidationFields = store.state.itemFieldInvalidationFields[itemKey];
|
|
15572
|
+
const remainingFields = stateInvalidationFields && stateInvalidationFields.length > 0 ? stateInvalidationFields : excludeLoadedFields(store.state.itemLoadedFields[itemKey], itemPendingInvalidationFields.get(itemKey));
|
|
15573
|
+
if (remainingFields.length === 0) return;
|
|
15574
|
+
events.emit("invalidateItem", {
|
|
15575
|
+
priority,
|
|
15576
|
+
itemKey,
|
|
15577
|
+
invalidateFields: remainingFields
|
|
15578
|
+
});
|
|
15579
|
+
}
|
|
15373
15580
|
function pruneItemInvalidationTracking() {
|
|
15374
15581
|
for (const [itemKey, pendingFields] of itemPendingInvalidationFields) {
|
|
15375
15582
|
const remainingFields = excludeLoadedFields(store.state.itemLoadedFields[itemKey], pendingFields);
|
|
@@ -15394,6 +15601,7 @@ function createListQueryStore(storeOptions) {
|
|
|
15394
15601
|
itemFieldInvalidationPriorities.delete(itemKey);
|
|
15395
15602
|
itemPendingInvalidationFields.delete(itemKey);
|
|
15396
15603
|
itemsPendingFullInvalidation.delete(itemKey);
|
|
15604
|
+
itemDroppedFieldInvalidations.delete(itemKey);
|
|
15397
15605
|
itemInvalidationWasTriggered.delete(itemKey);
|
|
15398
15606
|
itemCacheRuntime.clear(itemKey);
|
|
15399
15607
|
}
|
|
@@ -15490,10 +15698,12 @@ function createListQueryStore(storeOptions) {
|
|
|
15490
15698
|
}
|
|
15491
15699
|
}, { action: "browser-tabs-list-item-snapshot" });
|
|
15492
15700
|
});
|
|
15493
|
-
|
|
15701
|
+
let cancelledPendingItemFetch = false;
|
|
15702
|
+
if (message.consistency === "confirmed" && itemScheduler) cancelledPendingItemFetch = itemScheduler.cancelPendingRequests([message.itemKey], ({ payload }) => itemSnapshotSatisfiesRequestedFields(message.item, message.loadedFields, payload.fields));
|
|
15494
15703
|
itemInvalidationWasTriggered.delete(message.itemKey);
|
|
15495
15704
|
if (message.item === null && message.itemQuery === null) cleanupItemStateMetadata(message.itemKey);
|
|
15496
15705
|
pruneItemInvalidationTracking();
|
|
15706
|
+
if (cancelledPendingItemFetch) emitRemainingInvalidationFieldsAfterSnapshot(message.itemKey);
|
|
15497
15707
|
if (message.item === null && message.itemQuery === null) {
|
|
15498
15708
|
if (payloadToCleanup) deleteItemFetchResources([{
|
|
15499
15709
|
itemKey: message.itemKey,
|
|
@@ -15505,10 +15715,12 @@ function createListQueryStore(storeOptions) {
|
|
|
15505
15715
|
}
|
|
15506
15716
|
}
|
|
15507
15717
|
function applyRemoteQuerySnapshot(message) {
|
|
15718
|
+
let cancelledPendingQueryFetch = false;
|
|
15719
|
+
const itemKeysWithCancelledFetch = /* @__PURE__ */ new Set();
|
|
15508
15720
|
if (message.consistency === "confirmed") {
|
|
15509
15721
|
const snapshotItemsByKey = new Map(message.items.map((item) => [item.itemKey, item]));
|
|
15510
|
-
getOrCreateQueryScheduler(message.queryKey).cancelPendingRequests([message.queryKey], (request) => querySnapshotSatisfiesPendingQueryFetch(message, snapshotItemsByKey, request));
|
|
15511
|
-
for (const item of message.items) getKnownItemScheduler(item.itemKey)?.cancelPendingRequests([item.itemKey], ({ payload }) => itemSnapshotSatisfiesRequestedFields(item.item, item.loadedFields, payload.fields));
|
|
15722
|
+
cancelledPendingQueryFetch = getOrCreateQueryScheduler(message.queryKey).cancelPendingRequests([message.queryKey], (request) => querySnapshotSatisfiesPendingQueryFetch(message, snapshotItemsByKey, request));
|
|
15723
|
+
for (const item of message.items) if (getKnownItemScheduler(item.itemKey)?.cancelPendingRequests([item.itemKey], ({ payload }) => itemSnapshotSatisfiesRequestedFields(item.item, item.loadedFields, payload.fields))) itemKeysWithCancelledFetch.add(item.itemKey);
|
|
15512
15724
|
}
|
|
15513
15725
|
runWithoutBroadcast(() => {
|
|
15514
15726
|
store.produceState((draft) => {
|
|
@@ -15536,6 +15748,7 @@ function createListQueryStore(storeOptions) {
|
|
|
15536
15748
|
for (const item of message.items) {
|
|
15537
15749
|
itemInvalidationWasTriggered.delete(item.itemKey);
|
|
15538
15750
|
lastItemSyncVersions.set(item.itemKey, toBrowserTabsSyncVersion(message, message.consistency));
|
|
15751
|
+
if (cancelledPendingQueryFetch || itemKeysWithCancelledFetch.has(item.itemKey)) emitRemainingInvalidationFieldsAfterSnapshot(item.itemKey);
|
|
15539
15752
|
}
|
|
15540
15753
|
touchQueries([message.queryKey]);
|
|
15541
15754
|
touchItems(message.items.map(({ itemKey }) => itemKey));
|