relay-runtime 0.0.0-main-a4e82e93 → 0.0.0-main-5c3febad

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/experimental.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Relay v0.0.0-main-a4e82e93
2
+ * Relay v0.0.0-main-5c3febad
3
3
  *
4
4
  * Copyright (c) Meta Platforms, Inc. and affiliates.
5
5
  *
package/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Relay v0.0.0-main-a4e82e93
2
+ * Relay v0.0.0-main-5c3febad
3
3
  *
4
4
  * Copyright (c) Meta Platforms, Inc. and affiliates.
5
5
  *
@@ -144,12 +144,18 @@ var LiveResolverCache = /*#__PURE__*/function () {
144
144
  var liveStateRecord = recordSource.get(liveStateID);
145
145
  !(liveStateRecord != null) ? process.env.NODE_ENV !== "production" ? invariant(false, 'Expected to find record for live resolver.') : invariant(false) : void 0;
146
146
  var liveState = RelayModernRecord.getValue(liveStateRecord, RELAY_RESOLVER_LIVE_STATE_VALUE);
147
- return new Promise(function (resolve) {
147
+ var promise = new Promise(function (resolve) {
148
148
  var unsubscribe = liveState.subscribe(function () {
149
149
  unsubscribe();
150
150
  resolve();
151
151
  });
152
152
  });
153
+ if (liveState.getSuspenseDisplayName != null) {
154
+ try {
155
+ promise.displayName = liveState.getSuspenseDisplayName();
156
+ } catch (_unused) {}
157
+ }
158
+ return promise;
153
159
  };
154
160
  _proto._setLiveStateValue = function _setLiveStateValue(linkedRecord, linkedID, liveState, field, variables) {
155
161
  var handler = this._makeLiveStateHandler(linkedID);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "relay-runtime",
3
3
  "description": "A core runtime for building GraphQL-driven applications.",
4
- "version": "0.0.0-main-a4e82e93",
4
+ "version": "0.0.0-main-5c3febad",
5
5
  "keywords": [
6
6
  "graphql",
7
7
  "relay"
@@ -1297,6 +1297,18 @@ export interface LiveState<T> {
1297
1297
  * should stop calling the callback for state updates.
1298
1298
  */
1299
1299
  subscribe(callback: () => void): () => void;
1300
+
1301
+ /**
1302
+ * Optional. Called when Relay creates a suspense promise for this live
1303
+ * state, and used to name that promise. Called at promise-creation time,
1304
+ * so it can describe whatever is loading at that moment.
1305
+ *
1306
+ * Runs while a read is suspending, so it must be pure and cheap. The name
1307
+ * may be reported to profiling tools, so prefer a fixed label or a small
1308
+ * enum over anything request-specific. Return null when there is nothing
1309
+ * specific to say.
1310
+ */
1311
+ readonly getSuspenseDisplayName?: () => string | null | undefined;
1300
1312
  }
1301
1313
 
1302
1314
  export function suspenseSentinel(): never;
@@ -1666,6 +1666,17 @@ export type LiveState<out T> = {
1666
1666
  * call the callback when the value of the live state changes.
1667
1667
  */
1668
1668
  subscribe(cb: () => void): () => void,
1669
+ /**
1670
+ * Optional. Called when Relay creates a suspense promise for this live
1671
+ * state, and used to name that promise. Called at promise-creation time, so
1672
+ * it can describe whatever is loading at that moment.
1673
+ *
1674
+ * Runs while a read is suspending, so it must be pure and cheap. The name
1675
+ * may be reported to profiling tools, so prefer a fixed label or a small
1676
+ * enum over anything request-specific. Return null when there is nothing
1677
+ * specific to say.
1678
+ */
1679
+ readonly getSuspenseDisplayName?: () => ?string,
1669
1680
  };
1670
1681
 
1671
1682
  /**
@@ -332,12 +332,24 @@ class LiveResolverCache implements ResolverCache {
332
332
  RELAY_RESOLVER_LIVE_STATE_VALUE,
333
333
  );
334
334
 
335
- return new Promise(resolve => {
335
+ const promise = new Promise<void>(resolve => {
336
336
  const unsubscribe: () => void = liveState.subscribe(() => {
337
337
  unsubscribe();
338
338
  resolve();
339
339
  });
340
340
  });
341
+
342
+ if (liveState.getSuspenseDisplayName != null) {
343
+ try {
344
+ // $FlowExpectedError[prop-missing] Expando to annotate Promises.
345
+ promise.displayName = liveState.getSuspenseDisplayName();
346
+ } catch {
347
+ // The name only annotates the promise, so a bug in the producer's
348
+ // implementation must not fail the read that is suspending.
349
+ }
350
+ }
351
+
352
+ return promise;
341
353
  }
342
354
 
343
355
  // Register a new Live State object in the store, subscribing to future