@atlaskit/editor-synced-block-provider 3.12.1 → 3.13.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.
Files changed (41) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/dist/cjs/clients/block-service/blockSubscription.js +124 -0
  3. package/dist/cjs/clients/jira/sourceInfo.js +152 -0
  4. package/dist/cjs/providers/block-service/blockServiceAPI.js +43 -6
  5. package/dist/cjs/providers/syncBlockProvider.js +40 -8
  6. package/dist/cjs/store-manager/referenceSyncBlockStoreManager.js +347 -114
  7. package/dist/cjs/store-manager/syncBlockStoreManager.js +2 -2
  8. package/dist/cjs/utils/resolveSyncBlockInstance.js +1 -1
  9. package/dist/es2019/clients/block-service/blockSubscription.js +125 -0
  10. package/dist/es2019/clients/jira/sourceInfo.js +87 -0
  11. package/dist/es2019/providers/block-service/blockServiceAPI.js +40 -5
  12. package/dist/es2019/providers/syncBlockProvider.js +26 -2
  13. package/dist/es2019/store-manager/referenceSyncBlockStoreManager.js +233 -45
  14. package/dist/es2019/store-manager/syncBlockStoreManager.js +2 -2
  15. package/dist/es2019/utils/resolveSyncBlockInstance.js +1 -1
  16. package/dist/esm/clients/block-service/blockSubscription.js +118 -0
  17. package/dist/esm/clients/jira/sourceInfo.js +147 -0
  18. package/dist/esm/providers/block-service/blockServiceAPI.js +43 -6
  19. package/dist/esm/providers/syncBlockProvider.js +38 -6
  20. package/dist/esm/store-manager/referenceSyncBlockStoreManager.js +347 -114
  21. package/dist/esm/store-manager/syncBlockStoreManager.js +2 -2
  22. package/dist/esm/utils/resolveSyncBlockInstance.js +1 -1
  23. package/dist/types/clients/block-service/blockService.d.ts +2 -2
  24. package/dist/types/clients/block-service/blockSubscription.d.ts +38 -0
  25. package/dist/types/clients/jira/sourceInfo.d.ts +2 -0
  26. package/dist/types/common/types.d.ts +4 -2
  27. package/dist/types/index.d.ts +2 -2
  28. package/dist/types/providers/block-service/blockServiceAPI.d.ts +8 -0
  29. package/dist/types/providers/syncBlockProvider.d.ts +9 -1
  30. package/dist/types/providers/types.d.ts +22 -6
  31. package/dist/types/store-manager/referenceSyncBlockStoreManager.d.ts +59 -0
  32. package/dist/types-ts4.5/clients/block-service/blockService.d.ts +2 -2
  33. package/dist/types-ts4.5/clients/block-service/blockSubscription.d.ts +38 -0
  34. package/dist/types-ts4.5/clients/jira/sourceInfo.d.ts +2 -0
  35. package/dist/types-ts4.5/common/types.d.ts +4 -2
  36. package/dist/types-ts4.5/index.d.ts +2 -2
  37. package/dist/types-ts4.5/providers/block-service/blockServiceAPI.d.ts +8 -0
  38. package/dist/types-ts4.5/providers/syncBlockProvider.d.ts +9 -1
  39. package/dist/types-ts4.5/providers/types.d.ts +22 -6
  40. package/dist/types-ts4.5/store-manager/referenceSyncBlockStoreManager.d.ts +59 -0
  41. package/package.json +2 -1
@@ -31,18 +31,17 @@ function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length)
31
31
  // Handles fetching source URL and title for sync blocks.
32
32
  // Can be used in both editor and renderer contexts.
33
33
  var ReferenceSyncBlockStoreManager = exports.ReferenceSyncBlockStoreManager = /*#__PURE__*/function () {
34
- // Track pending cache deletions to handle block moves (unmount/remount)
35
- // When a block is moved, the old component unmounts before the new one mounts,
36
- // causing the cache to be deleted prematurely. We delay deletion to allow
37
- // the new component to subscribe and cancel the pending deletion.
34
+ // Listeners for subscription changes (used by React components to know when to update)
38
35
 
39
36
  function ReferenceSyncBlockStoreManager(dataProvider) {
40
37
  (0, _classCallCheck2.default)(this, ReferenceSyncBlockStoreManager);
41
38
  // Keeps track of addition and deletion of reference synced blocks on the document
42
39
  // This starts as true to always flush the cache when document is saved for the first time
43
- // to cater the case when a editor seesion is closed without document being updated right after reference block is deleted
40
+ // to cater the case when a editor session is closed without document being updated right after reference block is deleted
44
41
  (0, _defineProperty2.default)(this, "isCacheDirty", true);
45
42
  (0, _defineProperty2.default)(this, "isRefreshingSubscriptions", false);
43
+ // Flag to indicate if real-time subscriptions are enabled
44
+ (0, _defineProperty2.default)(this, "useRealTimeSubscriptions", false);
46
45
  this.syncBlockCache = new Map();
47
46
  this.subscriptions = new Map();
48
47
  this.titleSubscriptions = new Map();
@@ -52,8 +51,105 @@ var ReferenceSyncBlockStoreManager = exports.ReferenceSyncBlockStoreManager = /*
52
51
  this.syncBlockSourceInfoRequests = new Map();
53
52
  this.providerFactories = new Map();
54
53
  this.pendingCacheDeletions = new Map();
54
+ this.graphqlSubscriptions = new Map();
55
+ this.subscriptionChangeListeners = new Set();
55
56
  }
57
+
58
+ /**
59
+ * Enables or disables real-time GraphQL subscriptions for block updates.
60
+ * When enabled, the store manager will subscribe to real-time updates
61
+ * instead of relying on polling.
62
+ * @param enabled - Whether to enable real-time subscriptions
63
+ */
56
64
  return (0, _createClass2.default)(ReferenceSyncBlockStoreManager, [{
65
+ key: "setRealTimeSubscriptionsEnabled",
66
+ value: function setRealTimeSubscriptionsEnabled(enabled) {
67
+ if (this.useRealTimeSubscriptions === enabled) {
68
+ return;
69
+ }
70
+ this.useRealTimeSubscriptions = enabled;
71
+ if (enabled) {
72
+ // Set up subscriptions for all currently subscribed blocks
73
+ this.setupGraphQLSubscriptionsForAllBlocks();
74
+ } else {
75
+ // Clean up all GraphQL subscriptions
76
+ this.cleanupAllGraphQLSubscriptions();
77
+ }
78
+ }
79
+
80
+ /**
81
+ * Checks if real-time subscriptions are currently enabled.
82
+ */
83
+ }, {
84
+ key: "isRealTimeSubscriptionsEnabled",
85
+ value: function isRealTimeSubscriptionsEnabled() {
86
+ return this.useRealTimeSubscriptions;
87
+ }
88
+
89
+ /**
90
+ * Returns all resource IDs that are currently subscribed to.
91
+ * Used by React components to render subscription components.
92
+ */
93
+ }, {
94
+ key: "getSubscribedResourceIds",
95
+ value: function getSubscribedResourceIds() {
96
+ return Array.from(this.subscriptions.keys());
97
+ }
98
+
99
+ /**
100
+ * Registers a listener that will be called when subscriptions change.
101
+ * @param listener - Callback function to invoke when subscriptions change
102
+ * @returns Unsubscribe function to remove the listener
103
+ */
104
+ }, {
105
+ key: "onSubscriptionsChanged",
106
+ value: function onSubscriptionsChanged(listener) {
107
+ var _this = this;
108
+ this.subscriptionChangeListeners.add(listener);
109
+ return function () {
110
+ _this.subscriptionChangeListeners.delete(listener);
111
+ };
112
+ }
113
+
114
+ /**
115
+ * Notifies all subscription change listeners.
116
+ */
117
+ }, {
118
+ key: "notifySubscriptionChangeListeners",
119
+ value: function notifySubscriptionChangeListeners() {
120
+ var _this2 = this;
121
+ this.subscriptionChangeListeners.forEach(function (listener) {
122
+ try {
123
+ listener();
124
+ } catch (error) {
125
+ var _this2$fireAnalyticsE;
126
+ (0, _monitoring.logException)(error, {
127
+ location: 'editor-synced-block-provider/referenceSyncBlockStoreManager/notifySubscriptionChangeListeners'
128
+ });
129
+ (_this2$fireAnalyticsE = _this2.fireAnalyticsEvent) === null || _this2$fireAnalyticsE === void 0 || _this2$fireAnalyticsE.call(_this2, (0, _errorHandling.fetchErrorPayload)(error.message));
130
+ }
131
+ });
132
+ }
133
+
134
+ /**
135
+ * Handles incoming data from a GraphQL subscription.
136
+ * Called by React subscription components when they receive updates.
137
+ * @param syncBlockInstance - The updated sync block instance
138
+ */
139
+ }, {
140
+ key: "handleSubscriptionUpdate",
141
+ value: function handleSubscriptionUpdate(syncBlockInstance) {
142
+ if (!syncBlockInstance.resourceId) {
143
+ return;
144
+ }
145
+ var existingSyncBlock = this.getFromCache(syncBlockInstance.resourceId);
146
+ var resolvedSyncBlockInstance = existingSyncBlock ? (0, _resolveSyncBlockInstance.resolveSyncBlockInstance)(existingSyncBlock, syncBlockInstance) : syncBlockInstance;
147
+ this.updateCache(resolvedSyncBlockInstance);
148
+ if (!syncBlockInstance.error) {
149
+ this.fetchSyncBlockSourceInfo(resolvedSyncBlockInstance.resourceId);
150
+ }
151
+ }
152
+ }, {
57
153
  key: "setFireAnalyticsEvent",
58
154
  value: function setFireAnalyticsEvent(fireAnalyticsEvent) {
59
155
  this.fireAnalyticsEvent = fireAnalyticsEvent;
@@ -84,6 +180,7 @@ var ReferenceSyncBlockStoreManager = exports.ReferenceSyncBlockStoreManager = /*
84
180
 
85
181
  /**
86
182
  * Refreshes the subscriptions for all sync blocks.
183
+ * This is a fallback polling mechanism when real-time subscriptions are not enabled.
87
184
  * @returns {Promise<void>}
88
185
  */
89
186
  }, {
@@ -94,16 +191,22 @@ var ReferenceSyncBlockStoreManager = exports.ReferenceSyncBlockStoreManager = /*
94
191
  return _regenerator.default.wrap(function _callee$(_context2) {
95
192
  while (1) switch (_context2.prev = _context2.next) {
96
193
  case 0:
97
- if (!this.isRefreshingSubscriptions) {
194
+ if (!this.useRealTimeSubscriptions) {
98
195
  _context2.next = 2;
99
196
  break;
100
197
  }
101
198
  return _context2.abrupt("return");
102
199
  case 2:
200
+ if (!this.isRefreshingSubscriptions) {
201
+ _context2.next = 4;
202
+ break;
203
+ }
204
+ return _context2.abrupt("return");
205
+ case 4:
103
206
  this.isRefreshingSubscriptions = true;
104
207
  syncBlocks = [];
105
208
  _iterator = _createForOfIteratorHelper(this.subscriptions.entries());
106
- _context2.prev = 5;
209
+ _context2.prev = 7;
107
210
  _loop = /*#__PURE__*/_regenerator.default.mark(function _loop() {
108
211
  var _step$value, resourceId, callbacks;
109
212
  return _regenerator.default.wrap(function _loop$(_context) {
@@ -120,59 +223,163 @@ var ReferenceSyncBlockStoreManager = exports.ReferenceSyncBlockStoreManager = /*
120
223
  }, _loop);
121
224
  });
122
225
  _iterator.s();
123
- case 8:
226
+ case 10:
124
227
  if ((_step = _iterator.n()).done) {
125
- _context2.next = 12;
228
+ _context2.next = 14;
126
229
  break;
127
230
  }
128
- return _context2.delegateYield(_loop(), "t0", 10);
129
- case 10:
130
- _context2.next = 8;
131
- break;
231
+ return _context2.delegateYield(_loop(), "t0", 12);
132
232
  case 12:
133
- _context2.next = 17;
233
+ _context2.next = 10;
134
234
  break;
135
235
  case 14:
136
- _context2.prev = 14;
137
- _context2.t1 = _context2["catch"](5);
236
+ _context2.next = 19;
237
+ break;
238
+ case 16:
239
+ _context2.prev = 16;
240
+ _context2.t1 = _context2["catch"](7);
138
241
  _iterator.e(_context2.t1);
139
- case 17:
140
- _context2.prev = 17;
242
+ case 19:
243
+ _context2.prev = 19;
141
244
  _iterator.f();
142
- return _context2.finish(17);
143
- case 20:
144
- _context2.prev = 20;
145
- _context2.next = 23;
245
+ return _context2.finish(19);
246
+ case 22:
247
+ _context2.prev = 22;
248
+ _context2.next = 25;
146
249
  return this.fetchSyncBlocksData(syncBlocks);
147
- case 23:
148
- _context2.next = 29;
149
- break;
150
250
  case 25:
151
- _context2.prev = 25;
152
- _context2.t2 = _context2["catch"](20);
251
+ _context2.next = 31;
252
+ break;
253
+ case 27:
254
+ _context2.prev = 27;
255
+ _context2.t2 = _context2["catch"](22);
153
256
  (0, _monitoring.logException)(_context2.t2, {
154
257
  location: 'editor-synced-block-provider/referenceSyncBlockStoreManager'
155
258
  });
156
259
  (_this$fireAnalyticsEv = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv === void 0 || _this$fireAnalyticsEv.call(this, (0, _errorHandling.fetchErrorPayload)(_context2.t2.message));
157
- case 29:
158
- _context2.prev = 29;
260
+ case 31:
261
+ _context2.prev = 31;
159
262
  this.isRefreshingSubscriptions = false;
160
- return _context2.finish(29);
161
- case 32:
263
+ return _context2.finish(31);
264
+ case 34:
162
265
  case "end":
163
266
  return _context2.stop();
164
267
  }
165
- }, _callee, this, [[5, 14, 17, 20], [20, 25, 29, 32]]);
268
+ }, _callee, this, [[7, 16, 19, 22], [22, 27, 31, 34]]);
166
269
  }));
167
270
  function refreshSubscriptions() {
168
271
  return _refreshSubscriptions.apply(this, arguments);
169
272
  }
170
273
  return refreshSubscriptions;
171
- }())
274
+ }()
275
+ /**
276
+ * Sets up a GraphQL subscription for a specific block.
277
+ * @param resourceId - The resource ID of the block to subscribe to
278
+ */
279
+ )
280
+ }, {
281
+ key: "setupGraphQLSubscription",
282
+ value: function setupGraphQLSubscription(resourceId) {
283
+ var _this$dataProvider2,
284
+ _this3 = this;
285
+ // Don't set up duplicate subscriptions
286
+ if (this.graphqlSubscriptions.has(resourceId)) {
287
+ return;
288
+ }
289
+ if (!((_this$dataProvider2 = this.dataProvider) !== null && _this$dataProvider2 !== void 0 && _this$dataProvider2.subscribeToBlockUpdates)) {
290
+ return;
291
+ }
292
+ var unsubscribe = this.dataProvider.subscribeToBlockUpdates(resourceId, function (syncBlockInstance) {
293
+ // Handle the subscription update
294
+ _this3.handleGraphQLSubscriptionUpdate(syncBlockInstance);
295
+ }, function (error) {
296
+ var _this3$fireAnalyticsE;
297
+ (0, _monitoring.logException)(error, {
298
+ location: 'editor-synced-block-provider/referenceSyncBlockStoreManager/graphql-subscription'
299
+ });
300
+ (_this3$fireAnalyticsE = _this3.fireAnalyticsEvent) === null || _this3$fireAnalyticsE === void 0 || _this3$fireAnalyticsE.call(_this3, (0, _errorHandling.fetchErrorPayload)(error.message));
301
+ });
302
+ if (unsubscribe) {
303
+ this.graphqlSubscriptions.set(resourceId, unsubscribe);
304
+ }
305
+ }
306
+
307
+ /**
308
+ * Handles updates received from GraphQL subscriptions.
309
+ * @param syncBlockInstance - The updated sync block instance
310
+ */
311
+ }, {
312
+ key: "handleGraphQLSubscriptionUpdate",
313
+ value: function handleGraphQLSubscriptionUpdate(syncBlockInstance) {
314
+ if (!syncBlockInstance.resourceId) {
315
+ return;
316
+ }
317
+ var existingSyncBlock = this.getFromCache(syncBlockInstance.resourceId);
318
+ var resolvedSyncBlockInstance = existingSyncBlock ? (0, _resolveSyncBlockInstance.resolveSyncBlockInstance)(existingSyncBlock, syncBlockInstance) : syncBlockInstance;
319
+ this.updateCache(resolvedSyncBlockInstance);
320
+ if (!syncBlockInstance.error) {
321
+ this.fetchSyncBlockSourceInfo(resolvedSyncBlockInstance.resourceId);
322
+ }
323
+ }
324
+
325
+ /**
326
+ * Cleans up the GraphQL subscription for a specific block.
327
+ * @param resourceId - The resource ID of the block to unsubscribe from
328
+ */
329
+ }, {
330
+ key: "cleanupGraphQLSubscription",
331
+ value: function cleanupGraphQLSubscription(resourceId) {
332
+ var unsubscribe = this.graphqlSubscriptions.get(resourceId);
333
+ if (unsubscribe) {
334
+ unsubscribe();
335
+ this.graphqlSubscriptions.delete(resourceId);
336
+ }
337
+ }
338
+
339
+ /**
340
+ * Sets up GraphQL subscriptions for all currently subscribed blocks.
341
+ */
342
+ }, {
343
+ key: "setupGraphQLSubscriptionsForAllBlocks",
344
+ value: function setupGraphQLSubscriptionsForAllBlocks() {
345
+ var _iterator2 = _createForOfIteratorHelper(this.subscriptions.keys()),
346
+ _step2;
347
+ try {
348
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
349
+ var resourceId = _step2.value;
350
+ this.setupGraphQLSubscription(resourceId);
351
+ }
352
+ } catch (err) {
353
+ _iterator2.e(err);
354
+ } finally {
355
+ _iterator2.f();
356
+ }
357
+ }
358
+
359
+ /**
360
+ * Cleans up all GraphQL subscriptions.
361
+ */
362
+ }, {
363
+ key: "cleanupAllGraphQLSubscriptions",
364
+ value: function cleanupAllGraphQLSubscriptions() {
365
+ var _iterator3 = _createForOfIteratorHelper(this.graphqlSubscriptions.values()),
366
+ _step3;
367
+ try {
368
+ for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
369
+ var unsubscribe = _step3.value;
370
+ unsubscribe();
371
+ }
372
+ } catch (err) {
373
+ _iterator3.e(err);
374
+ } finally {
375
+ _iterator3.f();
376
+ }
377
+ this.graphqlSubscriptions.clear();
378
+ }
172
379
  }, {
173
380
  key: "fetchSyncBlockSourceInfo",
174
381
  value: function fetchSyncBlockSourceInfo(resourceId) {
175
- var _this = this;
382
+ var _this4 = this;
176
383
  try {
177
384
  if (!resourceId || !this.dataProvider) {
178
385
  throw new Error('Data provider or resourceId not set');
@@ -195,7 +402,7 @@ var ReferenceSyncBlockStoreManager = exports.ReferenceSyncBlockStoreManager = /*
195
402
  blockInstanceId = _ref.blockInstanceId,
196
403
  sourceURL = _ref.sourceURL,
197
404
  sourceTitle = _ref.sourceTitle,
198
- onSamePage = _ref.onSamePage,
405
+ onSameDocument = _ref.onSameDocument,
199
406
  sourceSubType = _ref.sourceSubType;
200
407
  // skip if source URL and title are already present
201
408
  if (sourceURL && sourceTitle) {
@@ -205,7 +412,7 @@ var ReferenceSyncBlockStoreManager = exports.ReferenceSyncBlockStoreManager = /*
205
412
  url: sourceURL,
206
413
  subType: sourceSubType,
207
414
  sourceAri: sourceAri || '',
208
- onSamePage: onSamePage,
415
+ onSameDocument: onSameDocument,
209
416
  productType: product
210
417
  });
211
418
  } else {
@@ -224,46 +431,46 @@ var ReferenceSyncBlockStoreManager = exports.ReferenceSyncBlockStoreManager = /*
224
431
  var sourceInfoPromise = this.dataProvider.fetchSyncBlockSourceInfo(blockInstanceId, sourceAri, product, this.fireAnalyticsEvent).then(function (sourceInfo) {
225
432
  if (!sourceInfo) {
226
433
  if ((0, _platformFeatureFlags.fg)('platform_synced_block_dogfooding')) {
227
- var _this$fetchSourceInfo2, _this$fireAnalyticsEv3;
228
- (_this$fetchSourceInfo2 = _this.fetchSourceInfoExperience) === null || _this$fetchSourceInfo2 === void 0 || _this$fetchSourceInfo2.failure({
434
+ var _this4$fetchSourceInf, _this4$fireAnalyticsE;
435
+ (_this4$fetchSourceInf = _this4.fetchSourceInfoExperience) === null || _this4$fetchSourceInf === void 0 || _this4$fetchSourceInf.failure({
229
436
  reason: 'No source info returned'
230
437
  });
231
- (_this$fireAnalyticsEv3 = _this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv3 === void 0 || _this$fireAnalyticsEv3.call(_this, (0, _errorHandling.getSourceInfoErrorPayload)('No source info returned', resourceId));
438
+ (_this4$fireAnalyticsE = _this4.fireAnalyticsEvent) === null || _this4$fireAnalyticsE === void 0 || _this4$fireAnalyticsE.call(_this4, (0, _errorHandling.getSourceInfoErrorPayload)('No source info returned', resourceId));
232
439
  }
233
440
  return undefined;
234
441
  }
235
- _this.updateCacheWithSourceInfo(resourceId, sourceInfo);
442
+ _this4.updateCacheWithSourceInfo(resourceId, sourceInfo);
236
443
  if (sourceInfo.title) {
237
- _this.updateSourceTitleSubscriptions(resourceId, sourceInfo.title);
444
+ _this4.updateSourceTitleSubscriptions(resourceId, sourceInfo.title);
238
445
  }
239
446
  if ((0, _platformFeatureFlags.fg)('platform_synced_block_dogfooding')) {
240
447
  if (sourceInfo.title && sourceInfo.url) {
241
- var _this$fetchSourceInfo3;
242
- (_this$fetchSourceInfo3 = _this.fetchSourceInfoExperience) === null || _this$fetchSourceInfo3 === void 0 || _this$fetchSourceInfo3.success();
448
+ var _this4$fetchSourceInf2;
449
+ (_this4$fetchSourceInf2 = _this4.fetchSourceInfoExperience) === null || _this4$fetchSourceInf2 === void 0 || _this4$fetchSourceInf2.success();
243
450
  } else {
244
- var _this$fetchSourceInfo4, _this$fireAnalyticsEv4;
245
- (_this$fetchSourceInfo4 = _this.fetchSourceInfoExperience) === null || _this$fetchSourceInfo4 === void 0 || _this$fetchSourceInfo4.failure({
451
+ var _this4$fetchSourceInf3, _this4$fireAnalyticsE2;
452
+ (_this4$fetchSourceInf3 = _this4.fetchSourceInfoExperience) === null || _this4$fetchSourceInf3 === void 0 || _this4$fetchSourceInf3.failure({
246
453
  reason: 'Missing title or url'
247
454
  });
248
- (_this$fireAnalyticsEv4 = _this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv4 === void 0 || _this$fireAnalyticsEv4.call(_this, (0, _errorHandling.getSourceInfoErrorPayload)('Missing title or url', resourceId));
455
+ (_this4$fireAnalyticsE2 = _this4.fireAnalyticsEvent) === null || _this4$fireAnalyticsE2 === void 0 || _this4$fireAnalyticsE2.call(_this4, (0, _errorHandling.getSourceInfoErrorPayload)('Missing title or url', resourceId));
249
456
  }
250
457
  return sourceInfo;
251
458
  }
252
459
  }).catch(function (error) {
253
- var _this$fireAnalyticsEv5;
460
+ var _this4$fireAnalyticsE3;
254
461
  if ((0, _platformFeatureFlags.fg)('platform_synced_block_dogfooding')) {
255
- var _this$fetchSourceInfo5;
256
- (_this$fetchSourceInfo5 = _this.fetchSourceInfoExperience) === null || _this$fetchSourceInfo5 === void 0 || _this$fetchSourceInfo5.failure({
462
+ var _this4$fetchSourceInf4;
463
+ (_this4$fetchSourceInf4 = _this4.fetchSourceInfoExperience) === null || _this4$fetchSourceInf4 === void 0 || _this4$fetchSourceInf4.failure({
257
464
  reason: error.message
258
465
  });
259
466
  }
260
- (_this$fireAnalyticsEv5 = _this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv5 === void 0 || _this$fireAnalyticsEv5.call(_this, (0, _errorHandling.getSourceInfoErrorPayload)(error.message, resourceId));
467
+ (_this4$fireAnalyticsE3 = _this4.fireAnalyticsEvent) === null || _this4$fireAnalyticsE3 === void 0 || _this4$fireAnalyticsE3.call(_this4, (0, _errorHandling.getSourceInfoErrorPayload)(error.message, resourceId));
261
468
  return undefined;
262
469
  }).finally(function () {
263
470
  if ((0, _platformFeatureFlags.fg)('platform_synced_block_dogfooding')) {
264
- _this.syncBlockSourceInfoRequests.delete(resourceId);
471
+ _this4.syncBlockSourceInfoRequests.delete(resourceId);
265
472
  } else {
266
- _this.syncBlockSourceInfoRequestsOld.delete(resourceId);
473
+ _this4.syncBlockSourceInfoRequestsOld.delete(resourceId);
267
474
  }
268
475
  });
269
476
  if ((0, _platformFeatureFlags.fg)('platform_synced_block_dogfooding')) {
@@ -273,11 +480,11 @@ var ReferenceSyncBlockStoreManager = exports.ReferenceSyncBlockStoreManager = /*
273
480
  this.syncBlockSourceInfoRequestsOld.set(resourceId, true);
274
481
  }
275
482
  } catch (error) {
276
- var _this$fireAnalyticsEv6;
483
+ var _this$fireAnalyticsEv3;
277
484
  (0, _monitoring.logException)(error, {
278
485
  location: 'editor-synced-block-provider/referenceSyncBlockStoreManager'
279
486
  });
280
- (_this$fireAnalyticsEv6 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv6 === void 0 || _this$fireAnalyticsEv6.call(this, (0, _errorHandling.getSourceInfoErrorPayload)(error.message, resourceId));
487
+ (_this$fireAnalyticsEv3 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv3 === void 0 || _this$fireAnalyticsEv3.call(this, (0, _errorHandling.getSourceInfoErrorPayload)(error.message, resourceId));
281
488
  }
282
489
  return Promise.resolve(undefined);
283
490
  }
@@ -291,7 +498,7 @@ var ReferenceSyncBlockStoreManager = exports.ReferenceSyncBlockStoreManager = /*
291
498
  key: "fetchSyncBlocksData",
292
499
  value: (function () {
293
500
  var _fetchSyncBlocksData = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2(syncBlockNodes) {
294
- var _this2 = this;
501
+ var _this5 = this;
295
502
  var nodesToFetch, _this$fetchExperience, data, resolvedData, hasUnexpectedError, hasExpectedError, _this$fetchExperience2, _this$fetchExperience3, _this$fetchExperience4;
296
503
  return _regenerator.default.wrap(function _callee2$(_context3) {
297
504
  while (1) switch (_context3.prev = _context3.next) {
@@ -305,10 +512,10 @@ var ReferenceSyncBlockStoreManager = exports.ReferenceSyncBlockStoreManager = /*
305
512
  // Don't fetch for not_found error since the source is already deleted
306
513
  nodesToFetch = [];
307
514
  syncBlockNodes.forEach(function (node) {
308
- if (_this2.syncBlockFetchDataRequests.get(node.attrs.resourceId)) {
515
+ if (_this5.syncBlockFetchDataRequests.get(node.attrs.resourceId)) {
309
516
  return;
310
517
  }
311
- var existingSyncBlock = _this2.getFromCache(node.attrs.resourceId);
518
+ var existingSyncBlock = _this5.getFromCache(node.attrs.resourceId);
312
519
  if ((existingSyncBlock === null || existingSyncBlock === void 0 ? void 0 : existingSyncBlock.error) === _types.SyncBlockError.NotFound) {
313
520
  return;
314
521
  }
@@ -327,7 +534,7 @@ var ReferenceSyncBlockStoreManager = exports.ReferenceSyncBlockStoreManager = /*
327
534
  throw new Error('Data provider not set');
328
535
  case 8:
329
536
  nodesToFetch.forEach(function (node) {
330
- _this2.syncBlockFetchDataRequests.set(node.attrs.resourceId, true);
537
+ _this5.syncBlockFetchDataRequests.set(node.attrs.resourceId, true);
331
538
  });
332
539
  if ((0, _platformFeatureFlags.fg)('platform_synced_block_dogfooding')) {
333
540
  (_this$fetchExperience = this.fetchExperience) === null || _this$fetchExperience === void 0 || _this$fetchExperience.start({});
@@ -335,7 +542,7 @@ var ReferenceSyncBlockStoreManager = exports.ReferenceSyncBlockStoreManager = /*
335
542
  _context3.next = 12;
336
543
  return this.dataProvider.fetchNodesData(nodesToFetch).finally(function () {
337
544
  nodesToFetch.forEach(function (node) {
338
- _this2.syncBlockFetchDataRequests.delete(node.attrs.resourceId);
545
+ _this5.syncBlockFetchDataRequests.delete(node.attrs.resourceId);
339
546
  });
340
547
  });
341
548
  case 12:
@@ -345,17 +552,17 @@ var ReferenceSyncBlockStoreManager = exports.ReferenceSyncBlockStoreManager = /*
345
552
  hasExpectedError = false;
346
553
  data.forEach(function (syncBlockInstance) {
347
554
  if (!syncBlockInstance.resourceId) {
348
- var _this2$fireAnalyticsE;
349
- (_this2$fireAnalyticsE = _this2.fireAnalyticsEvent) === null || _this2$fireAnalyticsE === void 0 || _this2$fireAnalyticsE.call(_this2, (0, _errorHandling.fetchErrorPayload)(syncBlockInstance.error || 'Returned sync block instance does not have resource id'));
555
+ var _this5$fireAnalyticsE;
556
+ (_this5$fireAnalyticsE = _this5.fireAnalyticsEvent) === null || _this5$fireAnalyticsE === void 0 || _this5$fireAnalyticsE.call(_this5, (0, _errorHandling.fetchErrorPayload)(syncBlockInstance.error || 'Returned sync block instance does not have resource id'));
350
557
  return;
351
558
  }
352
- var existingSyncBlock = _this2.getFromCache(syncBlockInstance.resourceId);
559
+ var existingSyncBlock = _this5.getFromCache(syncBlockInstance.resourceId);
353
560
  var resolvedSyncBlockInstance = existingSyncBlock ? (0, _resolveSyncBlockInstance.resolveSyncBlockInstance)(existingSyncBlock, syncBlockInstance) : syncBlockInstance;
354
- _this2.updateCache(resolvedSyncBlockInstance);
561
+ _this5.updateCache(resolvedSyncBlockInstance);
355
562
  resolvedData.push(resolvedSyncBlockInstance);
356
563
  if (syncBlockInstance.error) {
357
- var _this2$fireAnalyticsE2;
358
- (_this2$fireAnalyticsE2 = _this2.fireAnalyticsEvent) === null || _this2$fireAnalyticsE2 === void 0 || _this2$fireAnalyticsE2.call(_this2, (0, _errorHandling.fetchErrorPayload)(syncBlockInstance.error, syncBlockInstance.resourceId));
564
+ var _this5$fireAnalyticsE2;
565
+ (_this5$fireAnalyticsE2 = _this5.fireAnalyticsEvent) === null || _this5$fireAnalyticsE2 === void 0 || _this5$fireAnalyticsE2.call(_this5, (0, _errorHandling.fetchErrorPayload)(syncBlockInstance.error, syncBlockInstance.resourceId));
359
566
  if (syncBlockInstance.error === _types.SyncBlockError.NotFound || syncBlockInstance.error === _types.SyncBlockError.Forbidden) {
360
567
  hasExpectedError = true;
361
568
  } else if (syncBlockInstance.error) {
@@ -363,10 +570,10 @@ var ReferenceSyncBlockStoreManager = exports.ReferenceSyncBlockStoreManager = /*
363
570
  }
364
571
  return;
365
572
  } else if ((0, _platformFeatureFlags.fg)('platform_synced_block_dogfooding')) {
366
- var _this2$fireAnalyticsE3, _syncBlockInstance$da, _syncBlockInstance$da2;
367
- (_this2$fireAnalyticsE3 = _this2.fireAnalyticsEvent) === null || _this2$fireAnalyticsE3 === void 0 || _this2$fireAnalyticsE3.call(_this2, (0, _errorHandling.fetchSuccessPayload)(syncBlockInstance.resourceId, (_syncBlockInstance$da = syncBlockInstance.data) === null || _syncBlockInstance$da === void 0 ? void 0 : _syncBlockInstance$da.blockInstanceId, (_syncBlockInstance$da2 = syncBlockInstance.data) === null || _syncBlockInstance$da2 === void 0 ? void 0 : _syncBlockInstance$da2.product));
573
+ var _this5$fireAnalyticsE3, _syncBlockInstance$da, _syncBlockInstance$da2;
574
+ (_this5$fireAnalyticsE3 = _this5.fireAnalyticsEvent) === null || _this5$fireAnalyticsE3 === void 0 || _this5$fireAnalyticsE3.call(_this5, (0, _errorHandling.fetchSuccessPayload)(syncBlockInstance.resourceId, (_syncBlockInstance$da = syncBlockInstance.data) === null || _syncBlockInstance$da === void 0 ? void 0 : _syncBlockInstance$da.blockInstanceId, (_syncBlockInstance$da2 = syncBlockInstance.data) === null || _syncBlockInstance$da2 === void 0 ? void 0 : _syncBlockInstance$da2.product));
368
575
  }
369
- _this2.fetchSyncBlockSourceInfo(resolvedSyncBlockInstance.resourceId);
576
+ _this5.fetchSyncBlockSourceInfo(resolvedSyncBlockInstance.resourceId);
370
577
  });
371
578
  if ((0, _platformFeatureFlags.fg)('platform_synced_block_dogfooding')) {
372
579
  if (hasUnexpectedError) {
@@ -401,7 +608,7 @@ var ReferenceSyncBlockStoreManager = exports.ReferenceSyncBlockStoreManager = /*
401
608
  existingSyncBlock.data = _objectSpread(_objectSpread({}, existingSyncBlock.data), {}, {
402
609
  sourceURL: sourceInfo === null || sourceInfo === void 0 ? void 0 : sourceInfo.url,
403
610
  sourceTitle: sourceInfo === null || sourceInfo === void 0 ? void 0 : sourceInfo.title,
404
- onSamePage: sourceInfo === null || sourceInfo === void 0 ? void 0 : sourceInfo.onSamePage,
611
+ onSameDocument: sourceInfo === null || sourceInfo === void 0 ? void 0 : sourceInfo.onSameDocument,
405
612
  sourceSubType: sourceInfo === null || sourceInfo === void 0 ? void 0 : sourceInfo.subType
406
613
  });
407
614
  this.updateCache(existingSyncBlock);
@@ -445,8 +652,8 @@ var ReferenceSyncBlockStoreManager = exports.ReferenceSyncBlockStoreManager = /*
445
652
  }, {
446
653
  key: "subscribeToSyncBlock",
447
654
  value: function subscribeToSyncBlock(resourceId, localId, callback) {
448
- var _this$dataProvider2,
449
- _this3 = this;
655
+ var _this$dataProvider3,
656
+ _this6 = this;
450
657
  // Cancel any pending cache deletion for this resourceId.
451
658
  // This handles the case where a block is moved - the old component unmounts
452
659
  // (scheduling deletion) but the new component mounts and subscribes before
@@ -459,34 +666,52 @@ var ReferenceSyncBlockStoreManager = exports.ReferenceSyncBlockStoreManager = /*
459
666
 
460
667
  // add to subscriptions map
461
668
  var resourceSubscriptions = this.subscriptions.get(resourceId) || {};
669
+ var isNewResourceSubscription = Object.keys(resourceSubscriptions).length === 0;
462
670
  this.subscriptions.set(resourceId, _objectSpread(_objectSpread({}, resourceSubscriptions), {}, (0, _defineProperty2.default)({}, localId, callback)));
463
671
 
464
672
  // New subscription means new reference synced block is added to the document
465
673
  this.isCacheDirty = true;
674
+
675
+ // Notify listeners if this is a new resource subscription
676
+ if (isNewResourceSubscription) {
677
+ this.notifySubscriptionChangeListeners();
678
+ }
466
679
  var syncBlockNode = (0, _utils.createSyncBlockNode)(localId, resourceId);
467
680
 
468
681
  // call the callback immediately if we have cached data
469
682
  // prefer cache from store manager first, should update data provider to use the same cache
470
- var cachedData = this.getFromCache(resourceId) || ((_this$dataProvider2 = this.dataProvider) === null || _this$dataProvider2 === void 0 || (_this$dataProvider2 = _this$dataProvider2.getNodeDataFromCache(syncBlockNode)) === null || _this$dataProvider2 === void 0 ? void 0 : _this$dataProvider2.data);
683
+ var cachedData = this.getFromCache(resourceId) || ((_this$dataProvider3 = this.dataProvider) === null || _this$dataProvider3 === void 0 || (_this$dataProvider3 = _this$dataProvider3.getNodeDataFromCache(syncBlockNode)) === null || _this$dataProvider3 === void 0 ? void 0 : _this$dataProvider3.data);
471
684
  if (cachedData) {
472
685
  callback(cachedData);
473
686
  } else {
474
687
  this.fetchSyncBlocksData([syncBlockNode]).catch(function (error) {
475
- var _this3$fireAnalyticsE;
688
+ var _this6$fireAnalyticsE;
476
689
  (0, _monitoring.logException)(error, {
477
690
  location: 'editor-synced-block-provider/referenceSyncBlockStoreManager'
478
691
  });
479
- (_this3$fireAnalyticsE = _this3.fireAnalyticsEvent) === null || _this3$fireAnalyticsE === void 0 || _this3$fireAnalyticsE.call(_this3, (0, _errorHandling.fetchErrorPayload)(error.message, resourceId));
692
+ (_this6$fireAnalyticsE = _this6.fireAnalyticsEvent) === null || _this6$fireAnalyticsE === void 0 || _this6$fireAnalyticsE.call(_this6, (0, _errorHandling.fetchErrorPayload)(error.message, resourceId));
480
693
  });
481
694
  }
695
+
696
+ // Set up GraphQL subscription if real-time subscriptions are enabled
697
+ if (this.useRealTimeSubscriptions) {
698
+ this.setupGraphQLSubscription(resourceId);
699
+ }
482
700
  return function () {
483
- var resourceSubscriptions = _this3.subscriptions.get(resourceId);
701
+ var resourceSubscriptions = _this6.subscriptions.get(resourceId);
484
702
  if (resourceSubscriptions) {
485
703
  // Unsubscription means a reference synced block is removed from the document
486
- _this3.isCacheDirty = true;
704
+ _this6.isCacheDirty = true;
487
705
  delete resourceSubscriptions[localId];
488
706
  if (Object.keys(resourceSubscriptions).length === 0) {
489
- _this3.subscriptions.delete(resourceId);
707
+ _this6.subscriptions.delete(resourceId);
708
+
709
+ // Clean up GraphQL subscription when no more local subscribers
710
+ _this6.cleanupGraphQLSubscription(resourceId);
711
+
712
+ // Notify listeners that subscription was removed
713
+ _this6.notifySubscriptionChangeListeners();
714
+
490
715
  // Delay cache deletion to handle block moves (unmount/remount).
491
716
  // When a block is moved, the old component unmounts before the new one mounts.
492
717
  // By delaying deletion, we give the new component time to subscribe and
@@ -494,14 +719,14 @@ var ReferenceSyncBlockStoreManager = exports.ReferenceSyncBlockStoreManager = /*
494
719
  // TODO: EDITOR-4152 - Rework this logic
495
720
  var deletionTimeout = setTimeout(function () {
496
721
  // Only delete if still no subscribers (wasn't re-subscribed)
497
- if (!_this3.subscriptions.has(resourceId)) {
498
- _this3.deleteFromCache(resourceId);
722
+ if (!_this6.subscriptions.has(resourceId)) {
723
+ _this6.deleteFromCache(resourceId);
499
724
  }
500
- _this3.pendingCacheDeletions.delete(resourceId);
725
+ _this6.pendingCacheDeletions.delete(resourceId);
501
726
  }, 1000);
502
- _this3.pendingCacheDeletions.set(resourceId, deletionTimeout);
727
+ _this6.pendingCacheDeletions.set(resourceId, deletionTimeout);
503
728
  } else {
504
- _this3.subscriptions.set(resourceId, resourceSubscriptions);
729
+ _this6.subscriptions.set(resourceId, resourceSubscriptions);
505
730
  }
506
731
  }
507
732
  };
@@ -510,7 +735,7 @@ var ReferenceSyncBlockStoreManager = exports.ReferenceSyncBlockStoreManager = /*
510
735
  key: "subscribeToSourceTitle",
511
736
  value: function subscribeToSourceTitle(node, callback) {
512
737
  var _cachedData$data,
513
- _this4 = this;
738
+ _this7 = this;
514
739
  // check node is a sync block, as we only support sync block subscriptions
515
740
  if (node.type.name !== 'syncBlock') {
516
741
  return function () {};
@@ -530,13 +755,13 @@ var ReferenceSyncBlockStoreManager = exports.ReferenceSyncBlockStoreManager = /*
530
755
  var resourceSubscriptions = this.titleSubscriptions.get(resourceId) || {};
531
756
  this.titleSubscriptions.set(resourceId, _objectSpread(_objectSpread({}, resourceSubscriptions), {}, (0, _defineProperty2.default)({}, localId, callback)));
532
757
  return function () {
533
- var resourceSubscriptions = _this4.titleSubscriptions.get(resourceId);
758
+ var resourceSubscriptions = _this7.titleSubscriptions.get(resourceId);
534
759
  if (resourceSubscriptions) {
535
760
  delete resourceSubscriptions[localId];
536
761
  if (Object.keys(resourceSubscriptions).length === 0) {
537
- _this4.titleSubscriptions.delete(resourceId);
762
+ _this7.titleSubscriptions.delete(resourceId);
538
763
  } else {
539
- _this4.titleSubscriptions.set(resourceId, resourceSubscriptions);
764
+ _this7.titleSubscriptions.set(resourceId, resourceSubscriptions);
540
765
  }
541
766
  }
542
767
  };
@@ -557,11 +782,11 @@ var ReferenceSyncBlockStoreManager = exports.ReferenceSyncBlockStoreManager = /*
557
782
  }
558
783
  return this.subscribeToSyncBlock(resourceId, localId, callback);
559
784
  } catch (error) {
560
- var _this$fireAnalyticsEv7;
785
+ var _this$fireAnalyticsEv4;
561
786
  (0, _monitoring.logException)(error, {
562
787
  location: 'editor-synced-block-provider/referenceSyncBlockStoreManager'
563
788
  });
564
- (_this$fireAnalyticsEv7 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv7 === void 0 || _this$fireAnalyticsEv7.call(this, (0, _errorHandling.fetchErrorPayload)(error.message));
789
+ (_this$fireAnalyticsEv4 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv4 === void 0 || _this$fireAnalyticsEv4.call(this, (0, _errorHandling.fetchErrorPayload)(error.message));
565
790
  return function () {};
566
791
  }
567
792
  }
@@ -585,12 +810,12 @@ var ReferenceSyncBlockStoreManager = exports.ReferenceSyncBlockStoreManager = /*
585
810
  key: "getProviderFactory",
586
811
  value: function getProviderFactory(resourceId) {
587
812
  if (!this.dataProvider) {
588
- var _this$fireAnalyticsEv8;
813
+ var _this$fireAnalyticsEv5;
589
814
  var error = new Error('Data provider not set');
590
815
  (0, _monitoring.logException)(error, {
591
816
  location: 'editor-synced-block-provider/referenceSyncBlockStoreManager'
592
817
  });
593
- (_this$fireAnalyticsEv8 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv8 === void 0 || _this$fireAnalyticsEv8.call(this, (0, _errorHandling.fetchErrorPayload)(error.message));
818
+ (_this$fireAnalyticsEv5 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv5 === void 0 || _this$fireAnalyticsEv5.call(this, (0, _errorHandling.fetchErrorPayload)(error.message));
594
819
  return undefined;
595
820
  }
596
821
  var _this$dataProvider$ge = this.dataProvider.getSyncedBlockRendererProviderOptions(),
@@ -619,11 +844,11 @@ var ReferenceSyncBlockStoreManager = exports.ReferenceSyncBlockStoreManager = /*
619
844
  try {
620
845
  this.retrieveDynamicProviders(resourceId, providerFactory, providerCreator);
621
846
  } catch (error) {
622
- var _this$fireAnalyticsEv9;
847
+ var _this$fireAnalyticsEv6;
623
848
  (0, _monitoring.logException)(error, {
624
849
  location: 'editor-synced-block-provider/referenceSyncBlockStoreManager'
625
850
  });
626
- (_this$fireAnalyticsEv9 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv9 === void 0 || _this$fireAnalyticsEv9.call(this, (0, _errorHandling.fetchErrorPayload)(error.message, resourceId));
851
+ (_this$fireAnalyticsEv6 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv6 === void 0 || _this$fireAnalyticsEv6.call(this, (0, _errorHandling.fetchErrorPayload)(error.message, resourceId));
627
852
  }
628
853
  }
629
854
  return providerFactory;
@@ -683,8 +908,8 @@ var ReferenceSyncBlockStoreManager = exports.ReferenceSyncBlockStoreManager = /*
683
908
  return;
684
909
  }
685
910
  if (!((_syncBlock$data2 = syncBlock.data) !== null && _syncBlock$data2 !== void 0 && _syncBlock$data2.sourceAri) || !((_syncBlock$data3 = syncBlock.data) !== null && _syncBlock$data3 !== void 0 && _syncBlock$data3.product)) {
686
- var _this$fireAnalyticsEv0;
687
- (_this$fireAnalyticsEv0 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv0 === void 0 || _this$fireAnalyticsEv0.call(this, (0, _errorHandling.fetchErrorPayload)('Sync block source ari or product not found'));
911
+ var _this$fireAnalyticsEv7;
912
+ (_this$fireAnalyticsEv7 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv7 === void 0 || _this$fireAnalyticsEv7.call(this, (0, _errorHandling.fetchErrorPayload)('Sync block source ari or product not found'));
688
913
  return;
689
914
  }
690
915
  var parentInfo = this.dataProvider.retrieveSyncBlockParentInfo((_syncBlock$data4 = syncBlock.data) === null || _syncBlock$data4 === void 0 ? void 0 : _syncBlock$data4.sourceAri, (_syncBlock$data5 = syncBlock.data) === null || _syncBlock$data5 === void 0 ? void 0 : _syncBlock$data5.product);
@@ -734,7 +959,7 @@ var ReferenceSyncBlockStoreManager = exports.ReferenceSyncBlockStoreManager = /*
734
959
  key: "flush",
735
960
  value: (function () {
736
961
  var _flush = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee3() {
737
- var success, blocks, _this$saveExperience, updateResult, _this$fireAnalyticsEv1, _this$saveExperience2, _this$fireAnalyticsEv10, _this$saveExperience3, _this$saveExperience4;
962
+ var success, blocks, _this$saveExperience, updateResult, _this$fireAnalyticsEv8, _this$saveExperience2, _this$fireAnalyticsEv9, _this$saveExperience3, _this$saveExperience4;
738
963
  return _regenerator.default.wrap(function _callee3$(_context4) {
739
964
  while (1) switch (_context4.prev = _context4.next) {
740
965
  case 0:
@@ -758,19 +983,23 @@ var ReferenceSyncBlockStoreManager = exports.ReferenceSyncBlockStoreManager = /*
758
983
  });
759
984
  });
760
985
  });
986
+ if ((0, _platformFeatureFlags.fg)('platform_synced_block_dogfooding')) {
987
+ _context4.next = 10;
988
+ break;
989
+ }
761
990
  if (!(blocks.length === 0)) {
762
- _context4.next = 9;
991
+ _context4.next = 10;
763
992
  break;
764
993
  }
765
994
  this.isCacheDirty = false;
766
995
  return _context4.abrupt("return", true);
767
- case 9:
996
+ case 10:
768
997
  if (this.dataProvider) {
769
- _context4.next = 11;
998
+ _context4.next = 12;
770
999
  break;
771
1000
  }
772
1001
  throw new Error('Data provider not set');
773
- case 11:
1002
+ case 12:
774
1003
  // reset isCacheDirty early to prevent race condition
775
1004
  // There is a race condition where if a user makes changes (create/delete) to a reference sync block
776
1005
  // on a live page and the reference sync block is being saved while the user
@@ -780,9 +1009,9 @@ var ReferenceSyncBlockStoreManager = exports.ReferenceSyncBlockStoreManager = /*
780
1009
  if ((0, _platformFeatureFlags.fg)('platform_synced_block_dogfooding')) {
781
1010
  (_this$saveExperience = this.saveExperience) === null || _this$saveExperience === void 0 || _this$saveExperience.start();
782
1011
  }
783
- _context4.next = 15;
1012
+ _context4.next = 16;
784
1013
  return this.dataProvider.updateReferenceData(blocks);
785
- case 15:
1014
+ case 16:
786
1015
  updateResult = _context4.sent;
787
1016
  if (!updateResult.success) {
788
1017
  success = false;
@@ -791,12 +1020,12 @@ var ReferenceSyncBlockStoreManager = exports.ReferenceSyncBlockStoreManager = /*
791
1020
  reason: updateResult.error || 'Failed to update reference synced blocks on the document'
792
1021
  });
793
1022
  }
794
- (_this$fireAnalyticsEv1 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv1 === void 0 || _this$fireAnalyticsEv1.call(this, (0, _errorHandling.updateReferenceErrorPayload)(updateResult.error || 'Failed to update reference synced blocks on the document'));
1023
+ (_this$fireAnalyticsEv8 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv8 === void 0 || _this$fireAnalyticsEv8.call(this, (0, _errorHandling.updateReferenceErrorPayload)(updateResult.error || 'Failed to update reference synced blocks on the document'));
795
1024
  }
796
- _context4.next = 25;
1025
+ _context4.next = 26;
797
1026
  break;
798
- case 19:
799
- _context4.prev = 19;
1027
+ case 20:
1028
+ _context4.prev = 20;
800
1029
  _context4.t0 = _context4["catch"](3);
801
1030
  success = false;
802
1031
  (0, _monitoring.logException)(_context4.t0, {
@@ -807,23 +1036,23 @@ var ReferenceSyncBlockStoreManager = exports.ReferenceSyncBlockStoreManager = /*
807
1036
  reason: _context4.t0.message
808
1037
  });
809
1038
  }
810
- (_this$fireAnalyticsEv10 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv10 === void 0 || _this$fireAnalyticsEv10.call(this, (0, _errorHandling.updateReferenceErrorPayload)(_context4.t0.message));
811
- case 25:
812
- _context4.prev = 25;
1039
+ (_this$fireAnalyticsEv9 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv9 === void 0 || _this$fireAnalyticsEv9.call(this, (0, _errorHandling.updateReferenceErrorPayload)(_context4.t0.message));
1040
+ case 26:
1041
+ _context4.prev = 26;
813
1042
  if (!success) {
814
1043
  // set isCacheDirty back to true for cases where it failed to update the reference synced blocks on the BE
815
1044
  this.isCacheDirty = true;
816
1045
  } else if ((0, _platformFeatureFlags.fg)('platform_synced_block_dogfooding')) {
817
1046
  (_this$saveExperience4 = this.saveExperience) === null || _this$saveExperience4 === void 0 || _this$saveExperience4.success();
818
1047
  }
819
- return _context4.finish(25);
820
- case 28:
821
- return _context4.abrupt("return", success);
1048
+ return _context4.finish(26);
822
1049
  case 29:
1050
+ return _context4.abrupt("return", success);
1051
+ case 30:
823
1052
  case "end":
824
1053
  return _context4.stop();
825
1054
  }
826
- }, _callee3, this, [[3, 19, 25, 28]]);
1055
+ }, _callee3, this, [[3, 20, 26, 29]]);
827
1056
  }));
828
1057
  function flush() {
829
1058
  return _flush.apply(this, arguments);
@@ -833,7 +1062,9 @@ var ReferenceSyncBlockStoreManager = exports.ReferenceSyncBlockStoreManager = /*
833
1062
  }, {
834
1063
  key: "destroy",
835
1064
  value: function destroy() {
836
- var _this$saveExperience5, _this$fetchExperience5, _this$fetchSourceInfo6;
1065
+ var _this$saveExperience5, _this$fetchExperience5, _this$fetchSourceInfo2;
1066
+ // Clean up all GraphQL subscriptions first
1067
+ this.cleanupAllGraphQLSubscriptions();
837
1068
  this.dataProvider = undefined;
838
1069
  this.syncBlockCache.clear();
839
1070
  this.subscriptions.clear();
@@ -843,6 +1074,8 @@ var ReferenceSyncBlockStoreManager = exports.ReferenceSyncBlockStoreManager = /*
843
1074
  this.syncBlockSourceInfoRequests.clear();
844
1075
  this.providerFactories.clear();
845
1076
  this.isRefreshingSubscriptions = false;
1077
+ this.useRealTimeSubscriptions = false;
1078
+ this.subscriptionChangeListeners.clear();
846
1079
  this.providerFactories.forEach(function (providerFactory) {
847
1080
  providerFactory.destroy();
848
1081
  });
@@ -853,7 +1086,7 @@ var ReferenceSyncBlockStoreManager = exports.ReferenceSyncBlockStoreManager = /*
853
1086
  (_this$fetchExperience5 = this.fetchExperience) === null || _this$fetchExperience5 === void 0 || _this$fetchExperience5.abort({
854
1087
  reason: 'editor-destroyed'
855
1088
  });
856
- (_this$fetchSourceInfo6 = this.fetchSourceInfoExperience) === null || _this$fetchSourceInfo6 === void 0 || _this$fetchSourceInfo6.abort({
1089
+ (_this$fetchSourceInfo2 = this.fetchSourceInfoExperience) === null || _this$fetchSourceInfo2 === void 0 || _this$fetchSourceInfo2.abort({
857
1090
  reason: 'editor-destroyed'
858
1091
  });
859
1092
  this.fireAnalyticsEvent = undefined;