react-relay 13.1.1 → 13.2.0
Sign up to get free protection for your applications and to get access to all the features.
- package/ReactRelayContext.js +1 -1
- package/ReactRelayLocalQueryRenderer.js.flow +1 -1
- package/ReactRelayQueryRenderer.js.flow +1 -4
- 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/ReactRelayQueryRenderer.js +1 -1
- package/lib/jest-react/internalAct.js +24 -4
- package/lib/relay-hooks/FragmentResource.js +10 -13
- package/lib/relay-hooks/QueryResource.js +2 -165
- 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 +197 -0
- package/lib/relay-hooks/react-cache/useFragmentInternal_REACT_CACHE.js +395 -0
- package/lib/relay-hooks/react-cache/useLazyLoadQuery_REACT_CACHE.js +45 -0
- 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/relay-hooks/FragmentResource.js.flow +17 -18
- package/relay-hooks/QueryResource.js.flow +4 -201
- 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 +243 -0
- package/relay-hooks/react-cache/useFragmentInternal_REACT_CACHE.js.flow +416 -0
- package/relay-hooks/react-cache/useLazyLoadQuery_REACT_CACHE.js.flow +66 -0
package/ReactRelayContext.js
CHANGED
@@ -40,7 +40,7 @@ const queryRendererContext: ReactRelayQueryRendererContextType = {
|
|
40
40
|
rootIsQueryRenderer: true,
|
41
41
|
};
|
42
42
|
|
43
|
-
function useDeepCompare<T:
|
43
|
+
function useDeepCompare<T: {...}>(value: T): T {
|
44
44
|
const latestValue = React.useRef(value);
|
45
45
|
if (!areEqual(latestValue.current, value)) {
|
46
46
|
if (__DEV__) {
|
@@ -157,10 +157,7 @@ class ReactRelayQueryRenderer extends React.Component<Props, State> {
|
|
157
157
|
}
|
158
158
|
|
159
159
|
componentDidMount() {
|
160
|
-
if (
|
161
|
-
RelayFeatureFlags.ENABLE_QUERY_RENDERER_OFFSCREEN_SUPPORT === true &&
|
162
|
-
this._maybeHiddenOrFastRefresh === true
|
163
|
-
) {
|
160
|
+
if (this._maybeHiddenOrFastRefresh === true) {
|
164
161
|
// This block only runs if the component has previously "unmounted"
|
165
162
|
// due to it being hidden by the Offscreen API, or during fast refresh.
|
166
163
|
// At this point, the current cached resource will have been disposed
|
package/hooks.js
CHANGED
package/index.js
CHANGED
@@ -36,7 +36,7 @@ interface Thenable<+R> {
|
|
36
36
|
|
37
37
|
let actingUpdatesScopeDepth = 0;
|
38
38
|
|
39
|
-
function act(scope: () => Thenable<
|
39
|
+
function act<T>(scope: () => Thenable<T> | T): Thenable<T> {
|
40
40
|
if (Scheduler.unstable_flushAllWithoutAsserting === undefined) {
|
41
41
|
throw Error(
|
42
42
|
'This version of `act` requires a special mock build of Scheduler.',
|
@@ -49,10 +49,19 @@ function act(scope: () => Thenable<mixed> | void) {
|
|
49
49
|
);
|
50
50
|
}
|
51
51
|
|
52
|
+
const previousIsActEnvironment = global.IS_REACT_ACT_ENVIRONMENT;
|
52
53
|
const previousActingUpdatesScopeDepth = actingUpdatesScopeDepth;
|
53
54
|
actingUpdatesScopeDepth++;
|
55
|
+
if (__DEV__ && actingUpdatesScopeDepth === 1) {
|
56
|
+
// Because this is not the "real" `act`, we set this to `false` so React
|
57
|
+
// knows not to fire `act` warnings.
|
58
|
+
global.IS_REACT_ACT_ENVIRONMENT = false;
|
59
|
+
}
|
54
60
|
|
55
61
|
const unwind = () => {
|
62
|
+
if (__DEV__ && actingUpdatesScopeDepth === 1) {
|
63
|
+
global.IS_REACT_ACT_ENVIRONMENT = previousIsActEnvironment;
|
64
|
+
}
|
56
65
|
actingUpdatesScopeDepth--;
|
57
66
|
|
58
67
|
if (__DEV__) {
|
@@ -71,20 +80,21 @@ function act(scope: () => Thenable<mixed> | void) {
|
|
71
80
|
// returned and 2) we could use async/await. Since it's only our used in
|
72
81
|
// our test suite, we should be able to.
|
73
82
|
try {
|
74
|
-
const
|
83
|
+
const result = scope();
|
75
84
|
if (
|
76
|
-
typeof
|
77
|
-
|
78
|
-
typeof
|
85
|
+
typeof result === 'object' &&
|
86
|
+
result !== null &&
|
87
|
+
typeof result.then === 'function'
|
79
88
|
) {
|
89
|
+
const thenableResult: Thenable<T> = (result: any);
|
80
90
|
return {
|
81
|
-
then(resolve
|
82
|
-
|
83
|
-
|
91
|
+
then(resolve, reject) {
|
92
|
+
thenableResult.then(
|
93
|
+
returnValue => {
|
84
94
|
flushActWork(
|
85
95
|
() => {
|
86
96
|
unwind();
|
87
|
-
resolve();
|
97
|
+
resolve(returnValue);
|
88
98
|
},
|
89
99
|
error => {
|
90
100
|
unwind();
|
@@ -100,6 +110,7 @@ function act(scope: () => Thenable<mixed> | void) {
|
|
100
110
|
},
|
101
111
|
};
|
102
112
|
} else {
|
113
|
+
const returnValue: T = (result: any);
|
103
114
|
try {
|
104
115
|
// TODO: Let's not support non-async scopes at all in our tests. Need to
|
105
116
|
// migrate existing tests.
|
@@ -107,6 +118,11 @@ function act(scope: () => Thenable<mixed> | void) {
|
|
107
118
|
do {
|
108
119
|
didFlushWork = Scheduler.unstable_flushAllWithoutAsserting();
|
109
120
|
} while (didFlushWork);
|
121
|
+
return {
|
122
|
+
then(resolve, reject) {
|
123
|
+
resolve(returnValue);
|
124
|
+
},
|
125
|
+
};
|
110
126
|
} finally {
|
111
127
|
unwind();
|
112
128
|
}
|
package/legacy.js
CHANGED
@@ -132,7 +132,7 @@ var ReactRelayQueryRenderer = /*#__PURE__*/function (_React$Component) {
|
|
132
132
|
_proto.componentDidMount = function componentDidMount() {
|
133
133
|
var _this2 = this;
|
134
134
|
|
135
|
-
if (
|
135
|
+
if (this._maybeHiddenOrFastRefresh === true) {
|
136
136
|
// This block only runs if the component has previously "unmounted"
|
137
137
|
// due to it being hidden by the Offscreen API, or during fast refresh.
|
138
138
|
// At this point, the current cached resource will have been disposed
|
@@ -36,10 +36,21 @@ function act(scope) {
|
|
36
36
|
throw Error("This version of `act` requires Jest's timer mocks " + '(i.e. jest.useFakeTimers).');
|
37
37
|
}
|
38
38
|
|
39
|
+
var previousIsActEnvironment = global.IS_REACT_ACT_ENVIRONMENT;
|
39
40
|
var previousActingUpdatesScopeDepth = actingUpdatesScopeDepth;
|
40
41
|
actingUpdatesScopeDepth++;
|
41
42
|
|
43
|
+
if (process.env.NODE_ENV !== "production" && actingUpdatesScopeDepth === 1) {
|
44
|
+
// Because this is not the "real" `act`, we set this to `false` so React
|
45
|
+
// knows not to fire `act` warnings.
|
46
|
+
global.IS_REACT_ACT_ENVIRONMENT = false;
|
47
|
+
}
|
48
|
+
|
42
49
|
var unwind = function unwind() {
|
50
|
+
if (process.env.NODE_ENV !== "production" && actingUpdatesScopeDepth === 1) {
|
51
|
+
global.IS_REACT_ACT_ENVIRONMENT = previousIsActEnvironment;
|
52
|
+
}
|
53
|
+
|
43
54
|
actingUpdatesScopeDepth--;
|
44
55
|
|
45
56
|
if (process.env.NODE_ENV !== "production") {
|
@@ -55,15 +66,16 @@ function act(scope) {
|
|
55
66
|
|
56
67
|
|
57
68
|
try {
|
58
|
-
var
|
69
|
+
var result = scope();
|
59
70
|
|
60
|
-
if (typeof
|
71
|
+
if (typeof result === 'object' && result !== null && typeof result.then === 'function') {
|
72
|
+
var thenableResult = result;
|
61
73
|
return {
|
62
74
|
then: function then(resolve, reject) {
|
63
|
-
|
75
|
+
thenableResult.then(function (returnValue) {
|
64
76
|
flushActWork(function () {
|
65
77
|
unwind();
|
66
|
-
resolve();
|
78
|
+
resolve(returnValue);
|
67
79
|
}, function (error) {
|
68
80
|
unwind();
|
69
81
|
reject(error);
|
@@ -75,6 +87,8 @@ function act(scope) {
|
|
75
87
|
}
|
76
88
|
};
|
77
89
|
} else {
|
90
|
+
var returnValue = result;
|
91
|
+
|
78
92
|
try {
|
79
93
|
// TODO: Let's not support non-async scopes at all in our tests. Need to
|
80
94
|
// migrate existing tests.
|
@@ -83,6 +97,12 @@ function act(scope) {
|
|
83
97
|
do {
|
84
98
|
didFlushWork = Scheduler.unstable_flushAllWithoutAsserting();
|
85
99
|
} while (didFlushWork);
|
100
|
+
|
101
|
+
return {
|
102
|
+
then: function then(resolve, reject) {
|
103
|
+
resolve(returnValue);
|
104
|
+
}
|
105
|
+
};
|
86
106
|
} finally {
|
87
107
|
unwind();
|
88
108
|
}
|
@@ -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
|
@@ -263,7 +263,7 @@ var FragmentResourceImpl = /*#__PURE__*/function () {
|
|
263
263
|
}
|
264
264
|
|
265
265
|
if (cachedValue.kind === 'done' && cachedValue.result.snapshot) {
|
266
|
-
this.
|
266
|
+
this._handlePotentialSnapshotErrorsInSnapshot(cachedValue.result.snapshot);
|
267
267
|
|
268
268
|
return cachedValue.result;
|
269
269
|
}
|
@@ -279,7 +279,7 @@ var FragmentResourceImpl = /*#__PURE__*/function () {
|
|
279
279
|
var fragmentResult = getFragmentResult(fragmentIdentifier, snapshot, storeEpoch);
|
280
280
|
|
281
281
|
if (!fragmentResult.isMissingData) {
|
282
|
-
this.
|
282
|
+
this._handlePotentialSnapshotErrorsInSnapshot(snapshot);
|
283
283
|
|
284
284
|
this._cache.set(fragmentIdentifier, {
|
285
285
|
kind: 'done',
|
@@ -361,7 +361,7 @@ var FragmentResourceImpl = /*#__PURE__*/function () {
|
|
361
361
|
throw ((_clientEdgePromises2 = clientEdgePromises) === null || _clientEdgePromises2 === void 0 ? void 0 : _clientEdgePromises2.length) ? Promise.all([parentQueryPromiseResultPromise].concat((0, _toConsumableArray2["default"])(clientEdgePromises))) : parentQueryPromiseResultPromise;
|
362
362
|
}
|
363
363
|
|
364
|
-
this.
|
364
|
+
this._handlePotentialSnapshotErrorsInSnapshot(snapshot);
|
365
365
|
|
366
366
|
return getFragmentResult(fragmentIdentifier, snapshot, storeEpoch);
|
367
367
|
};
|
@@ -383,19 +383,15 @@ var FragmentResourceImpl = /*#__PURE__*/function () {
|
|
383
383
|
};
|
384
384
|
};
|
385
385
|
|
386
|
-
_proto2.
|
386
|
+
_proto2._handlePotentialSnapshotErrorsInSnapshot = function _handlePotentialSnapshotErrorsInSnapshot(snapshot) {
|
387
387
|
var _this4 = this;
|
388
388
|
|
389
389
|
if (Array.isArray(snapshot)) {
|
390
390
|
snapshot.forEach(function (s) {
|
391
|
-
|
392
|
-
reportMissingRequiredFields(_this4._environment, s.missingRequiredFields);
|
393
|
-
}
|
391
|
+
handlePotentialSnapshotErrors(_this4._environment, s.missingRequiredFields, s.relayResolverErrors);
|
394
392
|
});
|
395
393
|
} else {
|
396
|
-
|
397
|
-
reportMissingRequiredFields(this._environment, snapshot.missingRequiredFields);
|
398
|
-
}
|
394
|
+
handlePotentialSnapshotErrors(this._environment, snapshot.missingRequiredFields, snapshot.relayResolverErrors);
|
399
395
|
}
|
400
396
|
};
|
401
397
|
|
@@ -559,7 +555,8 @@ var FragmentResourceImpl = /*#__PURE__*/function () {
|
|
559
555
|
missingClientEdges: currentSnapshot.missingClientEdges,
|
560
556
|
seenRecords: currentSnapshot.seenRecords,
|
561
557
|
selector: currentSnapshot.selector,
|
562
|
-
missingRequiredFields: currentSnapshot.missingRequiredFields
|
558
|
+
missingRequiredFields: currentSnapshot.missingRequiredFields,
|
559
|
+
relayResolverErrors: currentSnapshot.relayResolverErrors
|
563
560
|
};
|
564
561
|
|
565
562
|
if (updatedData !== renderData) {
|
@@ -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);
|
@@ -529,7 +366,7 @@ var QueryResourceImpl = /*#__PURE__*/function () {
|
|
529
366
|
} else {
|
530
367
|
// TODO:T92030819 Remove this warning and actually throw the network error
|
531
368
|
// 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
|
369
|
+
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
370
|
}
|
534
371
|
|
535
372
|
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
|
+
};
|