react-relay 13.1.0 → 14.0.0
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/ReactRelayContext.js +1 -1
- package/ReactRelayFragmentContainer.js.flow +7 -4
- package/ReactRelayLocalQueryRenderer.js.flow +1 -1
- package/ReactRelayPaginationContainer.js.flow +13 -8
- package/ReactRelayQueryFetcher.js.flow +1 -0
- package/ReactRelayQueryRenderer.js.flow +7 -6
- package/ReactRelayRefetchContainer.js.flow +10 -3
- package/__flowtests__/__generated__/ReactRelayFragmentContainerFlowtest_viewer.graphql.js.flow +2 -2
- package/__flowtests__/__generated__/ReactRelayFragmentContainerFlowtest_viewer2.graphql.js.flow +2 -2
- package/__flowtests__/__generated__/ReactRelayPaginationContainerFlowtestQuery.graphql.js.flow +3 -3
- package/__flowtests__/__generated__/ReactRelayPaginationContainerFlowtest_viewer.graphql.js.flow +3 -3
- package/__flowtests__/__generated__/ReactRelayRefetchContainerFlowtestQuery.graphql.js.flow +3 -3
- package/__flowtests__/__generated__/ReactRelayRefetchContainerFlowtest_viewer.graphql.js.flow +3 -3
- package/__flowtests__/__generated__/RelayModernFlowtest_badref.graphql.js.flow +2 -2
- package/__flowtests__/__generated__/RelayModernFlowtest_notref.graphql.js.flow +2 -2
- package/__flowtests__/__generated__/RelayModernFlowtest_user.graphql.js.flow +2 -2
- package/__flowtests__/__generated__/RelayModernFlowtest_users.graphql.js.flow +2 -2
- package/buildReactRelayContainer.js.flow +2 -2
- package/hooks.js +1 -1
- package/index.js +1 -1
- package/jest-react/internalAct.js.flow +25 -9
- package/legacy.js +1 -1
- package/lib/ReactRelayQueryFetcher.js +1 -0
- package/lib/ReactRelayQueryRenderer.js +1 -2
- package/lib/jest-react/internalAct.js +24 -4
- package/lib/readContext.js +2 -1
- package/lib/relay-hooks/FragmentResource.js +62 -23
- package/lib/relay-hooks/HooksImplementation.js +29 -0
- package/lib/relay-hooks/MatchContainer.js +1 -0
- package/lib/relay-hooks/QueryResource.js +4 -166
- package/lib/relay-hooks/preloadQuery_DEPRECATED.js +7 -11
- package/lib/relay-hooks/react-cache/RelayReactCache.js +37 -0
- package/lib/relay-hooks/react-cache/getQueryResultOrFetchQuery_REACT_CACHE.js +344 -0
- package/lib/relay-hooks/react-cache/useFragmentInternal_REACT_CACHE.js +540 -0
- package/lib/relay-hooks/react-cache/useFragment_REACT_CACHE.js +51 -0
- package/lib/relay-hooks/react-cache/useLazyLoadQuery_REACT_CACHE.js +56 -0
- package/lib/relay-hooks/react-cache/usePreloadedQuery_REACT_CACHE.js +125 -0
- package/lib/relay-hooks/useFragment.js +15 -1
- package/lib/relay-hooks/useLazyLoadQuery.js +18 -2
- package/lib/relay-hooks/useMutation.js +4 -5
- package/lib/relay-hooks/usePreloadedQuery.js +18 -2
- package/package.json +3 -3
- package/react-relay-hooks.js +2 -2
- package/react-relay-hooks.min.js +2 -2
- package/react-relay-legacy.js +2 -2
- package/react-relay-legacy.min.js +2 -2
- package/react-relay.js +2 -2
- package/react-relay.min.js +2 -2
- package/readContext.js.flow +1 -0
- package/relay-hooks/FragmentResource.js.flow +72 -27
- package/relay-hooks/HooksImplementation.js.flow +45 -0
- package/relay-hooks/MatchContainer.js.flow +8 -1
- package/relay-hooks/QueryResource.js.flow +8 -203
- package/relay-hooks/__flowtests__/__generated__/useFragmentFlowtest_user.graphql.js.flow +2 -2
- package/relay-hooks/__flowtests__/__generated__/useFragmentFlowtest_users.graphql.js.flow +2 -2
- package/relay-hooks/loadQuery.js.flow +2 -1
- package/relay-hooks/preloadQuery_DEPRECATED.js.flow +7 -14
- package/relay-hooks/react-cache/RelayReactCache.js.flow +42 -0
- package/relay-hooks/react-cache/getQueryResultOrFetchQuery_REACT_CACHE.js.flow +424 -0
- package/relay-hooks/react-cache/useFragmentInternal_REACT_CACHE.js.flow +559 -0
- package/relay-hooks/react-cache/useFragment_REACT_CACHE.js.flow +74 -0
- package/relay-hooks/react-cache/useLazyLoadQuery_REACT_CACHE.js.flow +72 -0
- package/relay-hooks/react-cache/usePreloadedQuery_REACT_CACHE.js.flow +153 -0
- package/relay-hooks/useFragment.js.flow +17 -10
- package/relay-hooks/useLazyLoadQuery.js.flow +38 -3
- package/relay-hooks/useMutation.js.flow +3 -3
- package/relay-hooks/usePreloadedQuery.js.flow +30 -2
- package/relay-hooks/useRefetchableFragmentNode.js.flow +26 -11
- package/relay-hooks/useSubscription.js.flow +14 -8
@@ -38,9 +38,9 @@ var _require2 = require('relay-runtime'),
|
|
38
38
|
getPendingOperationsForFragment = _require2.getPendingOperationsForFragment,
|
39
39
|
getSelector = _require2.getSelector,
|
40
40
|
getVariablesFromFragment = _require2.getVariablesFromFragment,
|
41
|
+
handlePotentialSnapshotErrors = _require2.handlePotentialSnapshotErrors,
|
41
42
|
isPromise = _require2.isPromise,
|
42
|
-
recycleNodesInto = _require2.recycleNodesInto
|
43
|
-
reportMissingRequiredFields = _require2.reportMissingRequiredFields;
|
43
|
+
recycleNodesInto = _require2.recycleNodesInto;
|
44
44
|
|
45
45
|
var WEAKMAP_SUPPORTED = typeof WeakMap === 'function';
|
46
46
|
// TODO: Fix to not rely on LRU. If the number of active fragments exceeds this
|
@@ -74,6 +74,16 @@ function hasMissingClientEdges(snapshot) {
|
|
74
74
|
return ((_snapshot$missingClie = (_snapshot$missingClie2 = snapshot.missingClientEdges) === null || _snapshot$missingClie2 === void 0 ? void 0 : _snapshot$missingClie2.length) !== null && _snapshot$missingClie !== void 0 ? _snapshot$missingClie : 0) > 0;
|
75
75
|
}
|
76
76
|
|
77
|
+
function missingLiveResolverFields(snapshot) {
|
78
|
+
if (Array.isArray(snapshot)) {
|
79
|
+
return snapshot.map(function (s) {
|
80
|
+
return s.missingLiveResolverFields;
|
81
|
+
}).filter(Boolean).flat();
|
82
|
+
}
|
83
|
+
|
84
|
+
return snapshot.missingLiveResolverFields;
|
85
|
+
}
|
86
|
+
|
77
87
|
function singularOrPluralForEach(snapshot, f) {
|
78
88
|
if (Array.isArray(snapshot)) {
|
79
89
|
snapshot.forEach(f);
|
@@ -210,7 +220,7 @@ var FragmentResourceImpl = /*#__PURE__*/function () {
|
|
210
220
|
_proto2.readWithIdentifier = function readWithIdentifier(fragmentNode, fragmentRef, fragmentIdentifier, componentDisplayName, fragmentKey) {
|
211
221
|
var _this3 = this;
|
212
222
|
|
213
|
-
var _fragmentNode$metadat,
|
223
|
+
var _fragmentNode$metadat, _fragmentNode$metadat2, _missingLiveResolverF2, _missingLiveResolverF3;
|
214
224
|
|
215
225
|
var environment = this._environment; // If fragmentRef is null or undefined, pass it directly through.
|
216
226
|
// This is a convenience when consuming fragments via a HOC API, when the
|
@@ -248,6 +258,8 @@ var FragmentResourceImpl = /*#__PURE__*/function () {
|
|
248
258
|
var cachedValue = this._cache.get(fragmentIdentifier);
|
249
259
|
|
250
260
|
if (cachedValue != null) {
|
261
|
+
var _missingLiveResolverF;
|
262
|
+
|
251
263
|
if (cachedValue.kind === 'pending' && isPromise(cachedValue.promise)) {
|
252
264
|
environment.__log({
|
253
265
|
name: 'suspense.fragment',
|
@@ -262,8 +274,8 @@ var FragmentResourceImpl = /*#__PURE__*/function () {
|
|
262
274
|
throw cachedValue.promise;
|
263
275
|
}
|
264
276
|
|
265
|
-
if (cachedValue.kind === 'done' && cachedValue.result.snapshot) {
|
266
|
-
this.
|
277
|
+
if (cachedValue.kind === 'done' && cachedValue.result.snapshot && !((_missingLiveResolverF = missingLiveResolverFields(cachedValue.result.snapshot)) === null || _missingLiveResolverF === void 0 ? void 0 : _missingLiveResolverF.length)) {
|
278
|
+
this._handlePotentialSnapshotErrorsInSnapshot(cachedValue.result.snapshot);
|
267
279
|
|
268
280
|
return cachedValue.result;
|
269
281
|
}
|
@@ -279,7 +291,7 @@ var FragmentResourceImpl = /*#__PURE__*/function () {
|
|
279
291
|
var fragmentResult = getFragmentResult(fragmentIdentifier, snapshot, storeEpoch);
|
280
292
|
|
281
293
|
if (!fragmentResult.isMissingData) {
|
282
|
-
this.
|
294
|
+
this._handlePotentialSnapshotErrorsInSnapshot(snapshot);
|
283
295
|
|
284
296
|
this._cache.set(fragmentIdentifier, {
|
285
297
|
kind: 'done',
|
@@ -300,7 +312,7 @@ var FragmentResourceImpl = /*#__PURE__*/function () {
|
|
300
312
|
|
301
313
|
var clientEdgeRequests = null;
|
302
314
|
|
303
|
-
if (RelayFeatureFlags.ENABLE_CLIENT_EDGES && hasMissingClientEdges(snapshot)) {
|
315
|
+
if (RelayFeatureFlags.ENABLE_CLIENT_EDGES && ((_fragmentNode$metadat2 = fragmentNode.metadata) === null || _fragmentNode$metadat2 === void 0 ? void 0 : _fragmentNode$metadat2.hasClientEdges) === true && hasMissingClientEdges(snapshot)) {
|
304
316
|
clientEdgeRequests = [];
|
305
317
|
var queryResource = getQueryResourceForEnvironment(this._environment);
|
306
318
|
var queryResults = [];
|
@@ -328,14 +340,12 @@ var FragmentResourceImpl = /*#__PURE__*/function () {
|
|
328
340
|
this._clientEdgeQueryResultsCache.recordQueryResults(fragmentIdentifier, queryResults);
|
329
341
|
}
|
330
342
|
|
331
|
-
var clientEdgePromises =
|
343
|
+
var clientEdgePromises = [];
|
332
344
|
|
333
345
|
if (RelayFeatureFlags.ENABLE_CLIENT_EDGES && clientEdgeRequests) {
|
334
346
|
clientEdgePromises = clientEdgeRequests.map(function (request) {
|
335
347
|
return getPromiseForActiveRequest(_this3._environment, request);
|
336
|
-
}).filter(
|
337
|
-
return p != null;
|
338
|
-
});
|
348
|
+
}).filter(Boolean);
|
339
349
|
} // Finally look for operations in flight for our parent query:
|
340
350
|
|
341
351
|
|
@@ -345,8 +355,15 @@ var FragmentResourceImpl = /*#__PURE__*/function () {
|
|
345
355
|
|
346
356
|
var parentQueryPromiseResultPromise = parentQueryPromiseResult === null || parentQueryPromiseResult === void 0 ? void 0 : parentQueryPromiseResult.promise; // for refinement
|
347
357
|
|
348
|
-
|
349
|
-
var
|
358
|
+
var missingResolverFieldPromises = (_missingLiveResolverF2 = (_missingLiveResolverF3 = missingLiveResolverFields(snapshot)) === null || _missingLiveResolverF3 === void 0 ? void 0 : _missingLiveResolverF3.map(function (_ref2) {
|
359
|
+
var liveStateID = _ref2.liveStateID;
|
360
|
+
var store = environment.getStore(); // $FlowFixMe[prop-missing] This is expected to be a LiveResolverStore
|
361
|
+
|
362
|
+
return store.getLiveResolverPromise(liveStateID);
|
363
|
+
})) !== null && _missingLiveResolverF2 !== void 0 ? _missingLiveResolverF2 : [];
|
364
|
+
|
365
|
+
if (clientEdgePromises.length || missingResolverFieldPromises.length || isPromise(parentQueryPromiseResultPromise)) {
|
366
|
+
var _parentQueryPromiseRe, _clientEdgeRequests2;
|
350
367
|
|
351
368
|
environment.__log({
|
352
369
|
name: 'suspense.fragment',
|
@@ -355,13 +372,37 @@ var FragmentResourceImpl = /*#__PURE__*/function () {
|
|
355
372
|
isRelayHooks: true,
|
356
373
|
isPromiseCached: false,
|
357
374
|
isMissingData: fragmentResult.isMissingData,
|
375
|
+
// TODO! Attach information here about missing live resolver fields
|
358
376
|
pendingOperations: [].concat((0, _toConsumableArray2["default"])((_parentQueryPromiseRe = parentQueryPromiseResult === null || parentQueryPromiseResult === void 0 ? void 0 : parentQueryPromiseResult.pendingOperations) !== null && _parentQueryPromiseRe !== void 0 ? _parentQueryPromiseRe : []), (0, _toConsumableArray2["default"])((_clientEdgeRequests2 = clientEdgeRequests) !== null && _clientEdgeRequests2 !== void 0 ? _clientEdgeRequests2 : []))
|
359
377
|
});
|
360
378
|
|
361
|
-
|
379
|
+
var promises = [];
|
380
|
+
|
381
|
+
if (clientEdgePromises.length > 0) {
|
382
|
+
promises = promises.concat(clientEdgePromises);
|
383
|
+
}
|
384
|
+
|
385
|
+
if (missingResolverFieldPromises.length > 0) {
|
386
|
+
promises = promises.concat(missingResolverFieldPromises);
|
387
|
+
}
|
388
|
+
|
389
|
+
if (promises.length > 0) {
|
390
|
+
if (parentQueryPromiseResultPromise) {
|
391
|
+
promises.push(parentQueryPromiseResultPromise);
|
392
|
+
}
|
393
|
+
|
394
|
+
throw Promise.all(promises);
|
395
|
+
} // Note: we are re-throwing the `parentQueryPromiseResultPromise` here,
|
396
|
+
// because some of our suspense-related code is relying on the instance equality
|
397
|
+
// of thrown promises. See FragmentResource-test.js
|
398
|
+
|
399
|
+
|
400
|
+
if (parentQueryPromiseResultPromise) {
|
401
|
+
throw parentQueryPromiseResultPromise;
|
402
|
+
}
|
362
403
|
}
|
363
404
|
|
364
|
-
this.
|
405
|
+
this._handlePotentialSnapshotErrorsInSnapshot(snapshot);
|
365
406
|
|
366
407
|
return getFragmentResult(fragmentIdentifier, snapshot, storeEpoch);
|
367
408
|
};
|
@@ -383,19 +424,15 @@ var FragmentResourceImpl = /*#__PURE__*/function () {
|
|
383
424
|
};
|
384
425
|
};
|
385
426
|
|
386
|
-
_proto2.
|
427
|
+
_proto2._handlePotentialSnapshotErrorsInSnapshot = function _handlePotentialSnapshotErrorsInSnapshot(snapshot) {
|
387
428
|
var _this4 = this;
|
388
429
|
|
389
430
|
if (Array.isArray(snapshot)) {
|
390
431
|
snapshot.forEach(function (s) {
|
391
|
-
|
392
|
-
reportMissingRequiredFields(_this4._environment, s.missingRequiredFields);
|
393
|
-
}
|
432
|
+
handlePotentialSnapshotErrors(_this4._environment, s.missingRequiredFields, s.relayResolverErrors);
|
394
433
|
});
|
395
434
|
} else {
|
396
|
-
|
397
|
-
reportMissingRequiredFields(this._environment, snapshot.missingRequiredFields);
|
398
|
-
}
|
435
|
+
handlePotentialSnapshotErrors(this._environment, snapshot.missingRequiredFields, snapshot.relayResolverErrors);
|
399
436
|
}
|
400
437
|
};
|
401
438
|
|
@@ -557,9 +594,11 @@ var FragmentResourceImpl = /*#__PURE__*/function () {
|
|
557
594
|
data: updatedData,
|
558
595
|
isMissingData: currentSnapshot.isMissingData,
|
559
596
|
missingClientEdges: currentSnapshot.missingClientEdges,
|
597
|
+
missingLiveResolverFields: currentSnapshot.missingLiveResolverFields,
|
560
598
|
seenRecords: currentSnapshot.seenRecords,
|
561
599
|
selector: currentSnapshot.selector,
|
562
|
-
missingRequiredFields: currentSnapshot.missingRequiredFields
|
600
|
+
missingRequiredFields: currentSnapshot.missingRequiredFields,
|
601
|
+
relayResolverErrors: currentSnapshot.relayResolverErrors
|
563
602
|
};
|
564
603
|
|
565
604
|
if (updatedData !== renderData) {
|
@@ -0,0 +1,29 @@
|
|
1
|
+
/**
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
3
|
+
*
|
4
|
+
* This source code is licensed under the MIT license found in the
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
6
|
+
*
|
7
|
+
* @emails oncall+relay
|
8
|
+
*
|
9
|
+
* @format
|
10
|
+
*/
|
11
|
+
'use strict'; // flowlint ambiguous-object-type:error
|
12
|
+
|
13
|
+
var warning = require("fbjs/lib/warning");
|
14
|
+
|
15
|
+
var implementation = null;
|
16
|
+
|
17
|
+
function inject(impl) {
|
18
|
+
process.env.NODE_ENV !== "production" ? warning(implementation !== null, 'Relay HooksImplementation was injected twice.') : void 0;
|
19
|
+
implementation = impl;
|
20
|
+
}
|
21
|
+
|
22
|
+
function get() {
|
23
|
+
return implementation;
|
24
|
+
}
|
25
|
+
|
26
|
+
module.exports = {
|
27
|
+
inject: inject,
|
28
|
+
get: get
|
29
|
+
};
|
@@ -137,6 +137,7 @@ function MatchContainer(_ref2) {
|
|
137
137
|
|
138
138
|
if (LoadedContainer != null && fragmentProps != null) {
|
139
139
|
// $FlowFixMe[incompatible-type]
|
140
|
+
// $FlowFixMe[cannot-spread-indexer]
|
140
141
|
return /*#__PURE__*/React.createElement(LoadedContainer, (0, _extends2["default"])({}, props, fragmentProps));
|
141
142
|
} else {
|
142
143
|
return fallback !== null && fallback !== void 0 ? fallback : null;
|
@@ -24,7 +24,6 @@ var SuspenseResource = require('./SuspenseResource');
|
|
24
24
|
var invariant = require('invariant');
|
25
25
|
|
26
26
|
var _require = require('relay-runtime'),
|
27
|
-
RelayFeatureFlags = _require.RelayFeatureFlags,
|
28
27
|
isPromise = _require.isPromise;
|
29
28
|
|
30
29
|
var warning = require("fbjs/lib/warning");
|
@@ -66,18 +65,6 @@ function getQueryResult(operation, cacheIdentifier) {
|
|
66
65
|
var nextID = 200000;
|
67
66
|
|
68
67
|
function createCacheEntry(cacheIdentifier, operation, operationAvailability, value, networkSubscription, onDispose) {
|
69
|
-
// There should be no behavior difference between createCacheEntry_new and
|
70
|
-
// createCacheEntry_old, and it doesn't directly relate to Client Edges.
|
71
|
-
// It was just a refactoring that was needed for Client Edges but that
|
72
|
-
// is behind the feature flag just in case there is any accidental breakage.
|
73
|
-
if (RelayFeatureFlags.REFACTOR_SUSPENSE_RESOURCE) {
|
74
|
-
return createCacheEntry_new(cacheIdentifier, operation, operationAvailability, value, networkSubscription, onDispose);
|
75
|
-
} else {
|
76
|
-
return createCacheEntry_old(cacheIdentifier, operation, operationAvailability, value, networkSubscription, onDispose);
|
77
|
-
}
|
78
|
-
}
|
79
|
-
|
80
|
-
function createCacheEntry_new(cacheIdentifier, operation, operationAvailability, value, networkSubscription, onDispose) {
|
81
68
|
var isLiveQuery = operationIsLiveQuery(operation);
|
82
69
|
var currentValue = value;
|
83
70
|
var currentNetworkSubscription = networkSubscription;
|
@@ -108,12 +95,6 @@ function createCacheEntry_new(cacheIdentifier, operation, operationAvailability,
|
|
108
95
|
setValue: function setValue(val) {
|
109
96
|
currentValue = val;
|
110
97
|
},
|
111
|
-
getRetainCount: function getRetainCount() {
|
112
|
-
return suspenseResource.getRetainCount();
|
113
|
-
},
|
114
|
-
getNetworkSubscription: function getNetworkSubscription() {
|
115
|
-
return currentNetworkSubscription;
|
116
|
-
},
|
117
98
|
setNetworkSubscription: function setNetworkSubscription(subscription) {
|
118
99
|
if (isLiveQuery && currentNetworkSubscription != null) {
|
119
100
|
currentNetworkSubscription.unsubscribe();
|
@@ -134,156 +115,12 @@ function createCacheEntry_new(cacheIdentifier, operation, operationAvailability,
|
|
134
115
|
return cacheEntry;
|
135
116
|
}
|
136
117
|
|
137
|
-
var DATA_RETENTION_TIMEOUT = 5 * 60 * 1000;
|
138
|
-
|
139
|
-
function createCacheEntry_old(cacheIdentifier, operation, operationAvailability, value, networkSubscription, onDispose) {
|
140
|
-
var isLiveQuery = operationIsLiveQuery(operation);
|
141
|
-
var currentValue = value;
|
142
|
-
var retainCount = 0;
|
143
|
-
var retainDisposable = null;
|
144
|
-
var _releaseTemporaryRetain = null;
|
145
|
-
var currentNetworkSubscription = networkSubscription;
|
146
|
-
|
147
|
-
var retain = function retain(environment) {
|
148
|
-
retainCount++;
|
149
|
-
|
150
|
-
if (retainCount === 1) {
|
151
|
-
retainDisposable = environment.retain(operation);
|
152
|
-
}
|
153
|
-
|
154
|
-
return {
|
155
|
-
dispose: function dispose() {
|
156
|
-
retainCount = Math.max(0, retainCount - 1);
|
157
|
-
|
158
|
-
if (retainCount === 0) {
|
159
|
-
!(retainDisposable != null) ? process.env.NODE_ENV !== "production" ? invariant(false, 'Relay: Expected disposable to release query to be defined.' + "If you're seeing this, this is likely a bug in Relay.") : invariant(false) : void 0;
|
160
|
-
retainDisposable.dispose();
|
161
|
-
retainDisposable = null;
|
162
|
-
}
|
163
|
-
|
164
|
-
onDispose(cacheEntry);
|
165
|
-
}
|
166
|
-
};
|
167
|
-
};
|
168
|
-
|
169
|
-
var cacheEntry = {
|
170
|
-
cacheIdentifier: cacheIdentifier,
|
171
|
-
id: nextID++,
|
172
|
-
processedPayloadsCount: 0,
|
173
|
-
operationAvailability: operationAvailability,
|
174
|
-
getValue: function getValue() {
|
175
|
-
return currentValue;
|
176
|
-
},
|
177
|
-
setValue: function setValue(val) {
|
178
|
-
currentValue = val;
|
179
|
-
},
|
180
|
-
getRetainCount: function getRetainCount() {
|
181
|
-
return retainCount;
|
182
|
-
},
|
183
|
-
getNetworkSubscription: function getNetworkSubscription() {
|
184
|
-
return currentNetworkSubscription;
|
185
|
-
},
|
186
|
-
setNetworkSubscription: function setNetworkSubscription(subscription) {
|
187
|
-
if (isLiveQuery && currentNetworkSubscription != null) {
|
188
|
-
currentNetworkSubscription.unsubscribe();
|
189
|
-
}
|
190
|
-
|
191
|
-
currentNetworkSubscription = subscription;
|
192
|
-
},
|
193
|
-
temporaryRetain: function temporaryRetain(environment) {
|
194
|
-
// NOTE: If we're executing in a server environment, there's no need
|
195
|
-
// to create temporary retains, since the component will never commit.
|
196
|
-
if (environment.isServer()) {
|
197
|
-
return {
|
198
|
-
dispose: function dispose() {}
|
199
|
-
};
|
200
|
-
} // NOTE: temporaryRetain is called during the render phase. However,
|
201
|
-
// given that we can't tell if this render will eventually commit or not,
|
202
|
-
// we create a timer to autodispose of this retain in case the associated
|
203
|
-
// component never commits.
|
204
|
-
// If the component /does/ commit, permanentRetain will clear this timeout
|
205
|
-
// and permanently retain the data.
|
206
|
-
|
207
|
-
|
208
|
-
var disposable = retain(environment);
|
209
|
-
var releaseQueryTimeout = null;
|
210
|
-
|
211
|
-
var localReleaseTemporaryRetain = function localReleaseTemporaryRetain() {
|
212
|
-
clearTimeout(releaseQueryTimeout);
|
213
|
-
releaseQueryTimeout = null;
|
214
|
-
_releaseTemporaryRetain = null;
|
215
|
-
disposable.dispose(); // Normally if this entry never commits, the request would've ended by the
|
216
|
-
// time this timeout expires and the temporary retain is released. However,
|
217
|
-
// we need to do this for live queries which remain open indefinitely.
|
218
|
-
|
219
|
-
if (isLiveQuery && retainCount <= 0 && currentNetworkSubscription != null) {
|
220
|
-
currentNetworkSubscription.unsubscribe();
|
221
|
-
}
|
222
|
-
};
|
223
|
-
|
224
|
-
releaseQueryTimeout = setTimeout(localReleaseTemporaryRetain, DATA_RETENTION_TIMEOUT); // NOTE: Since temporaryRetain can be called multiple times, we release
|
225
|
-
// the previous temporary retain after we re-establish a new one, since
|
226
|
-
// we only ever need a single temporary retain until the permanent retain is
|
227
|
-
// established.
|
228
|
-
// temporaryRetain may be called multiple times by React during the render
|
229
|
-
// phase, as well as multiple times by other query components that are
|
230
|
-
// rendering the same query/variables.
|
231
|
-
|
232
|
-
if (_releaseTemporaryRetain != null) {
|
233
|
-
_releaseTemporaryRetain();
|
234
|
-
}
|
235
|
-
|
236
|
-
_releaseTemporaryRetain = localReleaseTemporaryRetain;
|
237
|
-
return {
|
238
|
-
dispose: function dispose() {
|
239
|
-
_releaseTemporaryRetain && _releaseTemporaryRetain();
|
240
|
-
}
|
241
|
-
};
|
242
|
-
},
|
243
|
-
permanentRetain: function permanentRetain(environment) {
|
244
|
-
var disposable = retain(environment);
|
245
|
-
|
246
|
-
if (_releaseTemporaryRetain != null) {
|
247
|
-
_releaseTemporaryRetain();
|
248
|
-
|
249
|
-
_releaseTemporaryRetain = null;
|
250
|
-
}
|
251
|
-
|
252
|
-
return {
|
253
|
-
dispose: function dispose() {
|
254
|
-
disposable.dispose();
|
255
|
-
|
256
|
-
if (isLiveQuery && retainCount <= 0 && currentNetworkSubscription != null) {
|
257
|
-
currentNetworkSubscription.unsubscribe();
|
258
|
-
}
|
259
|
-
}
|
260
|
-
};
|
261
|
-
},
|
262
|
-
releaseTemporaryRetain: function releaseTemporaryRetain() {
|
263
|
-
if (_releaseTemporaryRetain != null) {
|
264
|
-
_releaseTemporaryRetain();
|
265
|
-
|
266
|
-
_releaseTemporaryRetain = null;
|
267
|
-
}
|
268
|
-
}
|
269
|
-
};
|
270
|
-
return cacheEntry;
|
271
|
-
}
|
272
|
-
|
273
118
|
var QueryResourceImpl = /*#__PURE__*/function () {
|
274
119
|
function QueryResourceImpl(environment) {
|
275
120
|
var _this = this;
|
276
121
|
|
277
122
|
(0, _defineProperty2["default"])(this, "_clearCacheEntry", function (cacheEntry) {
|
278
|
-
|
279
|
-
// before calling _clearCacheEntry, whereas with the old code we do it here.
|
280
|
-
if (RelayFeatureFlags.REFACTOR_SUSPENSE_RESOURCE) {
|
281
|
-
_this._cache["delete"](cacheEntry.cacheIdentifier);
|
282
|
-
} else {
|
283
|
-
if (cacheEntry.getRetainCount() <= 0) {
|
284
|
-
_this._cache["delete"](cacheEntry.cacheIdentifier);
|
285
|
-
}
|
286
|
-
}
|
123
|
+
_this._cache["delete"](cacheEntry.cacheIdentifier);
|
287
124
|
});
|
288
125
|
this._environment = environment;
|
289
126
|
this._cache = LRUCache.create(CACHE_CAPACITY);
|
@@ -429,7 +266,8 @@ var QueryResourceImpl = /*#__PURE__*/function () {
|
|
429
266
|
var hasFullQuery = queryStatus === 'available';
|
430
267
|
var canPartialRender = hasFullQuery || renderPolicy === 'partial' && queryStatus !== 'stale';
|
431
268
|
var shouldFetch;
|
432
|
-
var shouldAllowRender;
|
269
|
+
var shouldAllowRender; // Different definitions for Promise in our repos can cause this variable
|
270
|
+
// to cause errors when synced elsewhere
|
433
271
|
|
434
272
|
var resolveNetworkPromise = function resolveNetworkPromise() {};
|
435
273
|
|
@@ -529,7 +367,7 @@ var QueryResourceImpl = /*#__PURE__*/function () {
|
|
529
367
|
} else {
|
530
368
|
// TODO:T92030819 Remove this warning and actually throw the network error
|
531
369
|
// To complete this task we need to have a way of precisely tracking suspendable points
|
532
|
-
process.env.NODE_ENV !== "production" ? warning(false, 'QueryResource: An incremental payload for query
|
370
|
+
process.env.NODE_ENV !== "production" ? warning(false, 'QueryResource: An incremental payload for query `%s` returned an error: `%s`.', operation.fragment.node.name, String(_error.message)) : void 0;
|
533
371
|
}
|
534
372
|
|
535
373
|
resolveNetworkPromise();
|
@@ -64,17 +64,13 @@ function preloadQuery(environment, preloadableRequest, variables, options, envir
|
|
64
64
|
return;
|
65
65
|
}
|
66
66
|
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
}, DEFAULT_PREFETCH_TIMEOUT);
|
75
|
-
} else {
|
76
|
-
cleanup(pendingQueries, queryEntry);
|
77
|
-
}
|
67
|
+
setTimeout(function () {
|
68
|
+
// Clear the cache entry after the default timeout
|
69
|
+
// null-check for Flow
|
70
|
+
if (queryEntry != null) {
|
71
|
+
cleanup(pendingQueries, queryEntry);
|
72
|
+
}
|
73
|
+
}, DEFAULT_PREFETCH_TIMEOUT);
|
78
74
|
};
|
79
75
|
}) : null;
|
80
76
|
return {
|
@@ -0,0 +1,37 @@
|
|
1
|
+
/**
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
3
|
+
*
|
4
|
+
* This source code is licensed under the MIT license found in the
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
6
|
+
*
|
7
|
+
*
|
8
|
+
* @emails oncall+relay
|
9
|
+
* @format
|
10
|
+
*/
|
11
|
+
// flowlint ambiguous-object-type:error
|
12
|
+
'use strict';
|
13
|
+
|
14
|
+
var invariant = require('invariant'); // $FlowFixMe[prop-missing] These exist in experimental builds but aren't in React's types yet.
|
15
|
+
|
16
|
+
|
17
|
+
var _require = require('react'),
|
18
|
+
unstable_getCacheForType = _require.unstable_getCacheForType,
|
19
|
+
unstable_getCacheSignal = _require.unstable_getCacheSignal;
|
20
|
+
|
21
|
+
var _require2 = require('relay-runtime'),
|
22
|
+
RelayFeatureFlags = _require2.RelayFeatureFlags;
|
23
|
+
|
24
|
+
function getCacheForType(factory) {
|
25
|
+
!(typeof unstable_getCacheForType === 'function' && RelayFeatureFlags.USE_REACT_CACHE) ? process.env.NODE_ENV !== "production" ? invariant(false, 'RelayReactCache.getCacheForType should only be called when the USE_REACT_CACHE feature flag is enabled and when on an experimental React build that supports it.') : invariant(false) : void 0;
|
26
|
+
return unstable_getCacheForType(factory);
|
27
|
+
}
|
28
|
+
|
29
|
+
function getCacheSignal() {
|
30
|
+
!(typeof unstable_getCacheSignal === 'function' && RelayFeatureFlags.USE_REACT_CACHE) ? process.env.NODE_ENV !== "production" ? invariant(false, 'RelayReactCache.getCacheSignal should only be called when the USE_REACT_CACHE feature flag is enabled and when on an experimental React build that supports it.') : invariant(false) : void 0;
|
31
|
+
return unstable_getCacheSignal();
|
32
|
+
}
|
33
|
+
|
34
|
+
module.exports = {
|
35
|
+
getCacheForType: getCacheForType,
|
36
|
+
getCacheSignal: getCacheSignal
|
37
|
+
};
|