@atlaskit/editor-synced-block-provider 3.30.1 → 3.30.3
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/CHANGELOG.md +16 -0
- package/dist/cjs/hooks/useFetchSyncBlockData.js +11 -5
- package/dist/cjs/index.js +13 -0
- package/dist/cjs/providers/block-service/blockServiceAPI.js +31 -10
- package/dist/cjs/providers/syncBlockProvider.js +6 -2
- package/dist/cjs/store-manager/referenceSyncBlockStoreManager.js +40 -54
- package/dist/cjs/store-manager/syncBlockInMemorySessionCache.js +75 -0
- package/dist/es2019/hooks/useFetchSyncBlockData.js +12 -6
- package/dist/es2019/index.js +1 -0
- package/dist/es2019/providers/block-service/blockServiceAPI.js +31 -10
- package/dist/es2019/providers/syncBlockProvider.js +6 -2
- package/dist/es2019/store-manager/referenceSyncBlockStoreManager.js +49 -63
- package/dist/es2019/store-manager/syncBlockInMemorySessionCache.js +57 -0
- package/dist/esm/hooks/useFetchSyncBlockData.js +11 -5
- package/dist/esm/index.js +1 -0
- package/dist/esm/providers/block-service/blockServiceAPI.js +31 -10
- package/dist/esm/providers/syncBlockProvider.js +6 -2
- package/dist/esm/store-manager/referenceSyncBlockStoreManager.js +40 -54
- package/dist/esm/store-manager/syncBlockInMemorySessionCache.js +68 -0
- package/dist/types/hooks/useFetchSyncBlockData.d.ts +1 -1
- package/dist/types/index.d.ts +1 -0
- package/dist/types/store-manager/referenceSyncBlockStoreManager.d.ts +3 -3
- package/dist/types/store-manager/syncBlockInMemorySessionCache.d.ts +23 -0
- package/dist/types/utils/validValue.d.ts +1 -1
- package/dist/types-ts4.5/hooks/useFetchSyncBlockData.d.ts +1 -1
- package/dist/types-ts4.5/index.d.ts +1 -0
- package/dist/types-ts4.5/store-manager/referenceSyncBlockStoreManager.d.ts +3 -3
- package/dist/types-ts4.5/store-manager/syncBlockInMemorySessionCache.d.ts +23 -0
- package/dist/types-ts4.5/utils/validValue.d.ts +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# @atlaskit/editor-synced-block-provider
|
|
2
2
|
|
|
3
|
+
## 3.30.3
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [`5ddfc9ed0352f`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/5ddfc9ed0352f) -
|
|
8
|
+
Switched from browser session storage to in memory session storage
|
|
9
|
+
- Updated dependencies
|
|
10
|
+
|
|
11
|
+
## 3.30.2
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- [`e794387202d1b`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/e794387202d1b) -
|
|
16
|
+
EDITOR-4824 add additional error logging for sync blocks
|
|
17
|
+
- Updated dependencies
|
|
18
|
+
|
|
3
19
|
## 3.30.1
|
|
4
20
|
|
|
5
21
|
### Patch Changes
|
|
@@ -12,11 +12,13 @@ var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/sli
|
|
|
12
12
|
var _react = require("react");
|
|
13
13
|
var _coreUtils = require("@atlaskit/editor-common/core-utils");
|
|
14
14
|
var _monitoring = require("@atlaskit/editor-common/monitoring");
|
|
15
|
+
var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
|
|
15
16
|
var _types = require("../common/types");
|
|
17
|
+
var _errorHandling = require("../utils/errorHandling");
|
|
16
18
|
var _utils = require("../utils/utils");
|
|
17
19
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
18
20
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
19
|
-
var useFetchSyncBlockData = exports.useFetchSyncBlockData = function useFetchSyncBlockData(manager, resourceId, localId,
|
|
21
|
+
var useFetchSyncBlockData = exports.useFetchSyncBlockData = function useFetchSyncBlockData(manager, resourceId, localId, fireAnalyticsEvent) {
|
|
20
22
|
// Initialize both states from a single cache lookup to avoid race conditions.
|
|
21
23
|
// When a block is moved/remounted, the old component's cleanup may clear the cache
|
|
22
24
|
// before or after the new component mounts. By doing a single lookup, we ensure
|
|
@@ -77,9 +79,13 @@ var useFetchSyncBlockData = exports.useFetchSyncBlockData = function useFetchSyn
|
|
|
77
79
|
(0, _monitoring.logException)(_context.t0, {
|
|
78
80
|
location: 'editor-synced-block-provider/useFetchSyncBlockData'
|
|
79
81
|
});
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
}
|
|
82
|
+
if ((0, _platformFeatureFlags.fg)('platform_synced_block_patch_3')) {
|
|
83
|
+
fireAnalyticsEvent === null || fireAnalyticsEvent === void 0 || fireAnalyticsEvent((0, _errorHandling.fetchErrorPayload)(_context.t0.message));
|
|
84
|
+
} else {
|
|
85
|
+
manager === null || manager === void 0 || (_manager$referenceMan2 = manager.referenceManager) === null || _manager$referenceMan2 === void 0 || (_manager$referenceMan2 = _manager$referenceMan2.fetchExperience) === null || _manager$referenceMan2 === void 0 || _manager$referenceMan2.failure({
|
|
86
|
+
reason: _context.t0.message
|
|
87
|
+
});
|
|
88
|
+
}
|
|
83
89
|
|
|
84
90
|
// Set error state if fetching fails
|
|
85
91
|
setFetchState({
|
|
@@ -103,7 +109,7 @@ var useFetchSyncBlockData = exports.useFetchSyncBlockData = function useFetchSyn
|
|
|
103
109
|
return _context.stop();
|
|
104
110
|
}
|
|
105
111
|
}, _callee, null, [[2, 11]]);
|
|
106
|
-
})), [isLoading, localId, manager.referenceManager, resourceId]);
|
|
112
|
+
})), [isLoading, localId, manager.referenceManager, resourceId, fireAnalyticsEvent]);
|
|
107
113
|
(0, _react.useEffect)(function () {
|
|
108
114
|
if ((0, _coreUtils.isSSR)()) {
|
|
109
115
|
// in SSR, we don't need to subscribe to updates,
|
package/dist/cjs/index.js
CHANGED
|
@@ -21,6 +21,12 @@ Object.defineProperty(exports, "SyncBlockError", {
|
|
|
21
21
|
return _types.SyncBlockError;
|
|
22
22
|
}
|
|
23
23
|
});
|
|
24
|
+
Object.defineProperty(exports, "SyncBlockInMemorySessionCache", {
|
|
25
|
+
enumerable: true,
|
|
26
|
+
get: function get() {
|
|
27
|
+
return _syncBlockInMemorySessionCache.SyncBlockInMemorySessionCache;
|
|
28
|
+
}
|
|
29
|
+
});
|
|
24
30
|
Object.defineProperty(exports, "SyncBlockStoreManager", {
|
|
25
31
|
enumerable: true,
|
|
26
32
|
get: function get() {
|
|
@@ -189,6 +195,12 @@ Object.defineProperty(exports, "resolveSyncBlockInstance", {
|
|
|
189
195
|
return _resolveSyncBlockInstance.resolveSyncBlockInstance;
|
|
190
196
|
}
|
|
191
197
|
});
|
|
198
|
+
Object.defineProperty(exports, "syncBlockInMemorySessionCache", {
|
|
199
|
+
enumerable: true,
|
|
200
|
+
get: function get() {
|
|
201
|
+
return _syncBlockInMemorySessionCache.syncBlockInMemorySessionCache;
|
|
202
|
+
}
|
|
203
|
+
});
|
|
192
204
|
Object.defineProperty(exports, "useFetchSyncBlockData", {
|
|
193
205
|
enumerable: true,
|
|
194
206
|
get: function get() {
|
|
@@ -245,6 +257,7 @@ var _blockServiceAPI = require("./providers/block-service/blockServiceAPI");
|
|
|
245
257
|
var _sourceInfo = require("./clients/confluence/sourceInfo");
|
|
246
258
|
var _syncBlockProvider = require("./providers/syncBlockProvider");
|
|
247
259
|
var _referenceSyncBlockStoreManager = require("./store-manager/referenceSyncBlockStoreManager");
|
|
260
|
+
var _syncBlockInMemorySessionCache = require("./store-manager/syncBlockInMemorySessionCache");
|
|
248
261
|
var _syncBlockStoreManager = require("./store-manager/syncBlockStoreManager");
|
|
249
262
|
var _resolveSyncBlockInstance = require("./utils/resolveSyncBlockInstance");
|
|
250
263
|
var _resourceId = require("./utils/resourceId");
|
|
@@ -12,6 +12,7 @@ var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/creat
|
|
|
12
12
|
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
13
13
|
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
14
14
|
var _react = require("react");
|
|
15
|
+
var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
|
|
15
16
|
var _ari = require("../../clients/block-service/ari");
|
|
16
17
|
var _blockService = require("../../clients/block-service/blockService");
|
|
17
18
|
var _blockSubscription = require("../../clients/block-service/blockSubscription");
|
|
@@ -300,12 +301,22 @@ var _batchFetchData = exports.batchFetchData = /*#__PURE__*/function () {
|
|
|
300
301
|
resourceId: resourceId
|
|
301
302
|
});
|
|
302
303
|
} catch (_unused3) {
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
304
|
+
if ((0, _platformFeatureFlags.fg)('platform_synced_block_patch_3')) {
|
|
305
|
+
results.push({
|
|
306
|
+
error: {
|
|
307
|
+
type: _types.SyncBlockError.Errored,
|
|
308
|
+
reason: "parsing JSON content response failed for resourceId: ".concat(resourceId, " localId: ").concat(blockAri)
|
|
309
|
+
},
|
|
310
|
+
resourceId: resourceId
|
|
311
|
+
});
|
|
312
|
+
} else {
|
|
313
|
+
results.push({
|
|
314
|
+
error: {
|
|
315
|
+
type: _types.SyncBlockError.Errored
|
|
316
|
+
},
|
|
317
|
+
resourceId: resourceId
|
|
318
|
+
});
|
|
319
|
+
}
|
|
309
320
|
}
|
|
310
321
|
case 25:
|
|
311
322
|
_context2.next = 14;
|
|
@@ -345,7 +356,10 @@ var _batchFetchData = exports.batchFetchData = /*#__PURE__*/function () {
|
|
|
345
356
|
case 44:
|
|
346
357
|
processedResourceIds.add(_resourceId);
|
|
347
358
|
results.push({
|
|
348
|
-
error: {
|
|
359
|
+
error: (0, _platformFeatureFlags.fg)('platform_synced_block_patch_3') ? {
|
|
360
|
+
type: mapErrorResponseCode(errorResponse.code),
|
|
361
|
+
reason: errorResponse.reason
|
|
362
|
+
} : {
|
|
349
363
|
type: mapErrorResponseCode(errorResponse.code)
|
|
350
364
|
},
|
|
351
365
|
resourceId: _resourceId
|
|
@@ -391,7 +405,8 @@ var _batchFetchData = exports.batchFetchData = /*#__PURE__*/function () {
|
|
|
391
405
|
return _context2.abrupt("return", blockNodeIdentifiers.map(function (blockNodeIdentifier) {
|
|
392
406
|
return {
|
|
393
407
|
error: {
|
|
394
|
-
type: _context2.t2 instanceof _blockService.BlockError ? mapBlockError(_context2.t2) : _types.SyncBlockError.Errored
|
|
408
|
+
type: _context2.t2 instanceof _blockService.BlockError ? mapBlockError(_context2.t2) : _types.SyncBlockError.Errored,
|
|
409
|
+
reason: (0, _platformFeatureFlags.fg)('platform_synced_block_patch_3') ? _context2.t2.message : undefined
|
|
395
410
|
},
|
|
396
411
|
resourceId: blockNodeIdentifier.resourceId
|
|
397
412
|
};
|
|
@@ -477,14 +492,20 @@ var BlockServiceADFFetchProvider = /*#__PURE__*/function () {
|
|
|
477
492
|
break;
|
|
478
493
|
}
|
|
479
494
|
return _context3.abrupt("return", {
|
|
480
|
-
error: {
|
|
495
|
+
error: (0, _platformFeatureFlags.fg)('platform_synced_block_patch_3') ? {
|
|
496
|
+
type: mapBlockError(_context3.t0),
|
|
497
|
+
reason: _context3.t0.message
|
|
498
|
+
} : {
|
|
481
499
|
type: mapBlockError(_context3.t0)
|
|
482
500
|
},
|
|
483
501
|
resourceId: resourceId
|
|
484
502
|
});
|
|
485
503
|
case 16:
|
|
486
504
|
return _context3.abrupt("return", {
|
|
487
|
-
error: {
|
|
505
|
+
error: (0, _platformFeatureFlags.fg)('platform_synced_block_patch_3') ? {
|
|
506
|
+
type: _types.SyncBlockError.Errored,
|
|
507
|
+
reason: _context3.t0.message
|
|
508
|
+
} : {
|
|
488
509
|
type: _types.SyncBlockError.Errored
|
|
489
510
|
},
|
|
490
511
|
resourceId: resourceId
|
|
@@ -14,6 +14,7 @@ var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/ge
|
|
|
14
14
|
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
|
|
15
15
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
16
16
|
var _react = require("react");
|
|
17
|
+
var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
|
|
17
18
|
var _ari = require("../clients/block-service/ari");
|
|
18
19
|
var _ari2 = require("../clients/confluence/ari");
|
|
19
20
|
var _sourceInfo2 = require("../clients/confluence/sourceInfo");
|
|
@@ -114,9 +115,12 @@ var SyncedBlockProvider = exports.SyncedBlockProvider = /*#__PURE__*/function (_
|
|
|
114
115
|
return _context.abrupt("return", Promise.allSettled(blockIdentifiers.map(function (blockIdentifier) {
|
|
115
116
|
return _this2.fetchProvider.fetchData(blockIdentifier.resourceId).then(function (data) {
|
|
116
117
|
return data;
|
|
117
|
-
}, function () {
|
|
118
|
+
}, function (error) {
|
|
118
119
|
return {
|
|
119
|
-
error: {
|
|
120
|
+
error: (0, _platformFeatureFlags.fg)('platform_synced_block_patch_3') ? {
|
|
121
|
+
type: _types.SyncBlockError.Errored,
|
|
122
|
+
reason: error
|
|
123
|
+
} : {
|
|
120
124
|
type: _types.SyncBlockError.Errored
|
|
121
125
|
},
|
|
122
126
|
resourceId: blockIdentifier.resourceId
|
|
@@ -22,12 +22,13 @@ var _experienceTracking = require("../utils/experienceTracking");
|
|
|
22
22
|
var _resolveSyncBlockInstance = require("../utils/resolveSyncBlockInstance");
|
|
23
23
|
var _resourceId = require("../utils/resourceId");
|
|
24
24
|
var _utils = require("../utils/utils");
|
|
25
|
+
var _syncBlockInMemorySessionCache = require("./syncBlockInMemorySessionCache");
|
|
25
26
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
26
27
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
27
28
|
function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t.return || t.return(); } finally { if (u) throw o; } } }; }
|
|
28
29
|
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
|
|
29
30
|
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
|
|
30
|
-
var
|
|
31
|
+
var CACHE_KEY_PREFIX = 'sync-block-data-';
|
|
31
32
|
|
|
32
33
|
// A store manager responsible for the lifecycle and state management of reference sync blocks in an editor instance.
|
|
33
34
|
// Designed to manage local in-memory state and synchronize with an external data provider.
|
|
@@ -85,8 +86,8 @@ var ReferenceSyncBlockStoreManager = exports.ReferenceSyncBlockStoreManager = /*
|
|
|
85
86
|
this.subscriptionChangeListeners = new Set();
|
|
86
87
|
this.newlyAddedSyncBlocks = new Set();
|
|
87
88
|
|
|
88
|
-
// The provider might have SSR data cache already set, so we need to update the cache in session storage
|
|
89
|
-
this.
|
|
89
|
+
// The provider might have SSR data cache already set, so we need to update the cache in session memory storage
|
|
90
|
+
this.setSSRDataInSessionCache((_this$dataProvider = this.dataProvider) === null || _this$dataProvider === void 0 ? void 0 : _this$dataProvider.getNodeDataCacheKeys());
|
|
90
91
|
}
|
|
91
92
|
|
|
92
93
|
/**
|
|
@@ -225,52 +226,32 @@ var ReferenceSyncBlockStoreManager = exports.ReferenceSyncBlockStoreManager = /*
|
|
|
225
226
|
value: function getInitialSyncBlockData(resourceId) {
|
|
226
227
|
var _this$dataProvider2;
|
|
227
228
|
var syncBlockNode = (0, _utils.createSyncBlockNode)('', resourceId);
|
|
228
|
-
var
|
|
229
|
-
if (
|
|
230
|
-
return
|
|
229
|
+
var providerData = (_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;
|
|
230
|
+
if (providerData) {
|
|
231
|
+
return providerData;
|
|
231
232
|
}
|
|
232
|
-
|
|
233
|
-
var sessionData = this.getSyncBlockDataFromSessionStorage(resourceId);
|
|
234
|
-
if (sessionData) {
|
|
235
|
-
return sessionData;
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
return undefined;
|
|
233
|
+
return this.getFromSessionCache(resourceId);
|
|
239
234
|
}
|
|
240
235
|
}, {
|
|
241
|
-
key: "
|
|
242
|
-
value: function
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
sessionStorage.setItem("".concat(SESSION_STORAGE_KEY_PREFIX).concat(resourceId), JSON.stringify(latestData));
|
|
247
|
-
}
|
|
248
|
-
} catch (error) {
|
|
249
|
-
(0, _monitoring.logException)(error, {
|
|
250
|
-
location: 'editor-synced-block-provider/referenceSyncBlockStoreManager/updateCacheInSessionStorage'
|
|
251
|
-
});
|
|
236
|
+
key: "updateSessionCache",
|
|
237
|
+
value: function updateSessionCache(resourceId) {
|
|
238
|
+
var latestData = this.getFromCache(resourceId);
|
|
239
|
+
if (latestData) {
|
|
240
|
+
_syncBlockInMemorySessionCache.syncBlockInMemorySessionCache.setItem("".concat(CACHE_KEY_PREFIX).concat(resourceId), JSON.stringify(latestData));
|
|
252
241
|
}
|
|
253
242
|
}
|
|
254
243
|
}, {
|
|
255
|
-
key: "
|
|
256
|
-
value: function
|
|
257
|
-
var sessionData = null;
|
|
258
|
-
try {
|
|
259
|
-
sessionData = sessionStorage.getItem("".concat(SESSION_STORAGE_KEY_PREFIX).concat(resourceId));
|
|
260
|
-
} catch (error) {
|
|
261
|
-
(0, _monitoring.logException)(error, {
|
|
262
|
-
location: 'editor-synced-block-provider/referenceSyncBlockStoreManager/getSyncBlockDataFromSessionStorage'
|
|
263
|
-
});
|
|
264
|
-
return undefined;
|
|
265
|
-
}
|
|
266
|
-
if (!sessionData) {
|
|
267
|
-
return undefined;
|
|
268
|
-
}
|
|
244
|
+
key: "getFromSessionCache",
|
|
245
|
+
value: function getFromSessionCache(resourceId) {
|
|
269
246
|
try {
|
|
270
|
-
|
|
247
|
+
var raw = _syncBlockInMemorySessionCache.syncBlockInMemorySessionCache.getItem("".concat(CACHE_KEY_PREFIX).concat(resourceId));
|
|
248
|
+
if (!raw) {
|
|
249
|
+
return undefined;
|
|
250
|
+
}
|
|
251
|
+
return JSON.parse(raw);
|
|
271
252
|
} catch (error) {
|
|
272
253
|
(0, _monitoring.logException)(error, {
|
|
273
|
-
location: 'editor-synced-block-provider/referenceSyncBlockStoreManager/
|
|
254
|
+
location: 'editor-synced-block-provider/referenceSyncBlockStoreManager/getFromSessionCache'
|
|
274
255
|
});
|
|
275
256
|
return undefined;
|
|
276
257
|
}
|
|
@@ -425,8 +406,9 @@ var ReferenceSyncBlockStoreManager = exports.ReferenceSyncBlockStoreManager = /*
|
|
|
425
406
|
});
|
|
426
407
|
this.fetchSyncBlockSourceInfo(resolvedSyncBlockInstance.resourceId);
|
|
427
408
|
} else {
|
|
428
|
-
var
|
|
429
|
-
(
|
|
409
|
+
var _syncBlockInstance$er, _syncBlockInstance$er2, _syncBlockInstance$er3, _this$fireAnalyticsEv3;
|
|
410
|
+
var errorMessage = (0, _platformFeatureFlags.fg)('platform_synced_block_patch_3') ? ((_syncBlockInstance$er = syncBlockInstance.error) === null || _syncBlockInstance$er === void 0 ? void 0 : _syncBlockInstance$er.reason) || ((_syncBlockInstance$er2 = syncBlockInstance.error) === null || _syncBlockInstance$er2 === void 0 ? void 0 : _syncBlockInstance$er2.type) : (_syncBlockInstance$er3 = syncBlockInstance.error) === null || _syncBlockInstance$er3 === void 0 ? void 0 : _syncBlockInstance$er3.type;
|
|
411
|
+
(_this$fireAnalyticsEv3 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv3 === void 0 || _this$fireAnalyticsEv3.call(this, (0, _errorHandling.fetchErrorPayload)(errorMessage, syncBlockInstance.resourceId));
|
|
430
412
|
}
|
|
431
413
|
}
|
|
432
414
|
|
|
@@ -765,8 +747,9 @@ var ReferenceSyncBlockStoreManager = exports.ReferenceSyncBlockStoreManager = /*
|
|
|
765
747
|
data.forEach(function (syncBlockInstance) {
|
|
766
748
|
var _resolvedSyncBlockIns;
|
|
767
749
|
if (!syncBlockInstance.resourceId) {
|
|
768
|
-
var
|
|
769
|
-
(
|
|
750
|
+
var _syncBlockInstance$er4, _syncBlockInstance$er5, _syncBlockInstance$er6, _this9$fireAnalyticsE;
|
|
751
|
+
var payload = (0, _platformFeatureFlags.fg)('platform_synced_block_patch_3') ? ((_syncBlockInstance$er4 = syncBlockInstance.error) === null || _syncBlockInstance$er4 === void 0 ? void 0 : _syncBlockInstance$er4.reason) || ((_syncBlockInstance$er5 = syncBlockInstance.error) === null || _syncBlockInstance$er5 === void 0 ? void 0 : _syncBlockInstance$er5.type) || 'Returned sync block instance does not have resource id' : ((_syncBlockInstance$er6 = syncBlockInstance.error) === null || _syncBlockInstance$er6 === void 0 ? void 0 : _syncBlockInstance$er6.type) || 'Returned sync block instance does not have resource id';
|
|
752
|
+
(_this9$fireAnalyticsE = _this9.fireAnalyticsEvent) === null || _this9$fireAnalyticsE === void 0 || _this9$fireAnalyticsE.call(_this9, (0, _errorHandling.fetchErrorPayload)(payload));
|
|
770
753
|
return;
|
|
771
754
|
}
|
|
772
755
|
var existingSyncBlock = _this9.getFromCache(syncBlockInstance.resourceId);
|
|
@@ -784,8 +767,13 @@ var ReferenceSyncBlockStoreManager = exports.ReferenceSyncBlockStoreManager = /*
|
|
|
784
767
|
_this9.newlyAddedSyncBlocks.delete(syncBlockInstance.resourceId);
|
|
785
768
|
}
|
|
786
769
|
if (syncBlockInstance.error) {
|
|
787
|
-
|
|
788
|
-
|
|
770
|
+
if ((0, _platformFeatureFlags.fg)('platform_synced_block_patch_3')) {
|
|
771
|
+
var _this9$fireAnalyticsE2;
|
|
772
|
+
(_this9$fireAnalyticsE2 = _this9.fireAnalyticsEvent) === null || _this9$fireAnalyticsE2 === void 0 || _this9$fireAnalyticsE2.call(_this9, (0, _errorHandling.fetchErrorPayload)(syncBlockInstance.error.reason || syncBlockInstance.error.type, syncBlockInstance.resourceId));
|
|
773
|
+
} else {
|
|
774
|
+
var _this9$fireAnalyticsE3;
|
|
775
|
+
(_this9$fireAnalyticsE3 = _this9.fireAnalyticsEvent) === null || _this9$fireAnalyticsE3 === void 0 || _this9$fireAnalyticsE3.call(_this9, (0, _errorHandling.fetchErrorPayload)(syncBlockInstance.error.type, syncBlockInstance.resourceId));
|
|
776
|
+
}
|
|
789
777
|
if (syncBlockInstance.error.type === _types.SyncBlockError.NotFound || syncBlockInstance.error.type === _types.SyncBlockError.Forbidden) {
|
|
790
778
|
hasExpectedError = true;
|
|
791
779
|
} else if (syncBlockInstance.error) {
|
|
@@ -796,8 +784,8 @@ var ReferenceSyncBlockStoreManager = exports.ReferenceSyncBlockStoreManager = /*
|
|
|
796
784
|
var callbacks = _this9.subscriptions.get(syncBlockInstance.resourceId);
|
|
797
785
|
var localIds = callbacks ? Object.keys(callbacks) : [];
|
|
798
786
|
localIds.forEach(function (localId) {
|
|
799
|
-
var _this9$
|
|
800
|
-
(_this9$
|
|
787
|
+
var _this9$fireAnalyticsE4, _syncBlockInstance$da2;
|
|
788
|
+
(_this9$fireAnalyticsE4 = _this9.fireAnalyticsEvent) === null || _this9$fireAnalyticsE4 === void 0 || _this9$fireAnalyticsE4.call(_this9, (0, _errorHandling.fetchSuccessPayload)(syncBlockInstance.resourceId, localId, (_syncBlockInstance$da2 = syncBlockInstance.data) === null || _syncBlockInstance$da2 === void 0 ? void 0 : _syncBlockInstance$da2.product));
|
|
801
789
|
});
|
|
802
790
|
}
|
|
803
791
|
_this9.fetchSyncBlockSourceInfo(resolvedSyncBlockInstance.resourceId);
|
|
@@ -839,7 +827,7 @@ var ReferenceSyncBlockStoreManager = exports.ReferenceSyncBlockStoreManager = /*
|
|
|
839
827
|
});
|
|
840
828
|
}
|
|
841
829
|
if ((0, _platformFeatureFlags.fg)('platform_synced_block_patch_3')) {
|
|
842
|
-
this.
|
|
830
|
+
this.updateSessionCache(resourceId);
|
|
843
831
|
}
|
|
844
832
|
}
|
|
845
833
|
}
|
|
@@ -884,14 +872,14 @@ var ReferenceSyncBlockStoreManager = exports.ReferenceSyncBlockStoreManager = /*
|
|
|
884
872
|
}
|
|
885
873
|
}
|
|
886
874
|
}, {
|
|
887
|
-
key: "
|
|
888
|
-
value: function
|
|
875
|
+
key: "setSSRDataInSessionCache",
|
|
876
|
+
value: function setSSRDataInSessionCache(resourceIds) {
|
|
889
877
|
var _this0 = this;
|
|
890
878
|
if (!resourceIds || resourceIds.length === 0) {
|
|
891
879
|
return;
|
|
892
880
|
}
|
|
893
881
|
resourceIds.forEach(function (resourceId) {
|
|
894
|
-
_this0.
|
|
882
|
+
_this0.updateSessionCache(resourceId);
|
|
895
883
|
});
|
|
896
884
|
}
|
|
897
885
|
}, {
|
|
@@ -922,8 +910,6 @@ var ReferenceSyncBlockStoreManager = exports.ReferenceSyncBlockStoreManager = /*
|
|
|
922
910
|
this.notifySubscriptionChangeListeners();
|
|
923
911
|
}
|
|
924
912
|
var syncBlockNode = (0, _utils.createSyncBlockNode)(localId, resourceId);
|
|
925
|
-
|
|
926
|
-
// call the callback immediately if we have cached data
|
|
927
913
|
var cachedData = (_this$dataProvider7 = this.dataProvider) === null || _this$dataProvider7 === void 0 || (_this$dataProvider7 = _this$dataProvider7.getNodeDataFromCache(syncBlockNode)) === null || _this$dataProvider7 === void 0 ? void 0 : _this$dataProvider7.data;
|
|
928
914
|
if (cachedData) {
|
|
929
915
|
callback(cachedData);
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.syncBlockInMemorySessionCache = exports.SyncBlockInMemorySessionCache = void 0;
|
|
8
|
+
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
9
|
+
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
10
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
11
|
+
/**
|
|
12
|
+
* In-memory session cache for sync block data with size-based LRU eviction.
|
|
13
|
+
*
|
|
14
|
+
* Backed by a plain Map so that potentially private ADF content is never
|
|
15
|
+
* written to any browser-persistent storage (sessionStorage, localStorage,
|
|
16
|
+
* IndexedDB). The module-level singleton survives SPA transitions (no full
|
|
17
|
+
* page reload) and is naturally cleared on hard navigation or tab close.
|
|
18
|
+
*
|
|
19
|
+
* Uses JavaScript Map's insertion-order guarantee to implement LRU:
|
|
20
|
+
* on every read or write the accessed entry is moved to the end of the
|
|
21
|
+
* iteration order; when total cached size exceeds `maxSize`, the oldest
|
|
22
|
+
* (least-recently-used) entries are evicted first.
|
|
23
|
+
*/
|
|
24
|
+
var SyncBlockInMemorySessionCache = exports.SyncBlockInMemorySessionCache = /*#__PURE__*/function () {
|
|
25
|
+
function SyncBlockInMemorySessionCache() {
|
|
26
|
+
var maxSize = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 5 * 1024 * 1024;
|
|
27
|
+
(0, _classCallCheck2.default)(this, SyncBlockInMemorySessionCache);
|
|
28
|
+
(0, _defineProperty2.default)(this, "store", new Map());
|
|
29
|
+
(0, _defineProperty2.default)(this, "currentSize", 0);
|
|
30
|
+
this.maxSize = maxSize;
|
|
31
|
+
}
|
|
32
|
+
return (0, _createClass2.default)(SyncBlockInMemorySessionCache, [{
|
|
33
|
+
key: "getItem",
|
|
34
|
+
value: function getItem(key) {
|
|
35
|
+
var value = this.store.get(key);
|
|
36
|
+
if (value === undefined) {
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
this.store.delete(key);
|
|
40
|
+
this.store.set(key, value);
|
|
41
|
+
return value;
|
|
42
|
+
}
|
|
43
|
+
}, {
|
|
44
|
+
key: "setItem",
|
|
45
|
+
value: function setItem(key, value) {
|
|
46
|
+
var existing = this.store.get(key);
|
|
47
|
+
if (existing !== undefined) {
|
|
48
|
+
this.currentSize -= existing.length;
|
|
49
|
+
this.store.delete(key);
|
|
50
|
+
}
|
|
51
|
+
this.store.set(key, value);
|
|
52
|
+
this.currentSize += value.length;
|
|
53
|
+
while (this.currentSize > this.maxSize && this.store.size > 1) {
|
|
54
|
+
var oldestKey = this.store.keys().next().value;
|
|
55
|
+
if (oldestKey !== undefined) {
|
|
56
|
+
var oldestValue = this.store.get(oldestKey);
|
|
57
|
+
if (oldestValue !== undefined) {
|
|
58
|
+
this.currentSize -= oldestValue.length;
|
|
59
|
+
}
|
|
60
|
+
this.store.delete(oldestKey);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}, {
|
|
65
|
+
key: "removeItem",
|
|
66
|
+
value: function removeItem(key) {
|
|
67
|
+
var value = this.store.get(key);
|
|
68
|
+
if (value !== undefined) {
|
|
69
|
+
this.currentSize -= value.length;
|
|
70
|
+
this.store.delete(key);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}]);
|
|
74
|
+
}();
|
|
75
|
+
var syncBlockInMemorySessionCache = exports.syncBlockInMemorySessionCache = new SyncBlockInMemorySessionCache();
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { useCallback, useEffect, useMemo, useState } from 'react';
|
|
2
2
|
import { isSSR } from '@atlaskit/editor-common/core-utils';
|
|
3
3
|
import { logException } from '@atlaskit/editor-common/monitoring';
|
|
4
|
+
import { fg } from '@atlaskit/platform-feature-flags';
|
|
4
5
|
import { SyncBlockError } from '../common/types';
|
|
6
|
+
import { fetchErrorPayload } from '../utils/errorHandling';
|
|
5
7
|
import { createSyncBlockNode } from '../utils/utils';
|
|
6
|
-
export const useFetchSyncBlockData = (manager, resourceId, localId,
|
|
8
|
+
export const useFetchSyncBlockData = (manager, resourceId, localId, fireAnalyticsEvent) => {
|
|
7
9
|
// Initialize both states from a single cache lookup to avoid race conditions.
|
|
8
10
|
// When a block is moved/remounted, the old component's cleanup may clear the cache
|
|
9
11
|
// before or after the new component mounts. By doing a single lookup, we ensure
|
|
@@ -42,13 +44,17 @@ export const useFetchSyncBlockData = (manager, resourceId, localId, _fireAnalyti
|
|
|
42
44
|
// Fetch sync block data, the `subscribeToSyncBlock` will update the state once data is fetched
|
|
43
45
|
await manager.referenceManager.fetchSyncBlocksData([syncBlockNode]);
|
|
44
46
|
} catch (error) {
|
|
45
|
-
var _manager$referenceMan2, _manager$referenceMan3;
|
|
46
47
|
logException(error, {
|
|
47
48
|
location: 'editor-synced-block-provider/useFetchSyncBlockData'
|
|
48
49
|
});
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
}
|
|
50
|
+
if (fg('platform_synced_block_patch_3')) {
|
|
51
|
+
fireAnalyticsEvent === null || fireAnalyticsEvent === void 0 ? void 0 : fireAnalyticsEvent(fetchErrorPayload(error.message));
|
|
52
|
+
} else {
|
|
53
|
+
var _manager$referenceMan2, _manager$referenceMan3;
|
|
54
|
+
manager === null || manager === void 0 ? void 0 : (_manager$referenceMan2 = manager.referenceManager) === null || _manager$referenceMan2 === void 0 ? void 0 : (_manager$referenceMan3 = _manager$referenceMan2.fetchExperience) === null || _manager$referenceMan3 === void 0 ? void 0 : _manager$referenceMan3.failure({
|
|
55
|
+
reason: error.message
|
|
56
|
+
});
|
|
57
|
+
}
|
|
52
58
|
|
|
53
59
|
// Set error state if fetching fails
|
|
54
60
|
setFetchState({
|
|
@@ -66,7 +72,7 @@ export const useFetchSyncBlockData = (manager, resourceId, localId, _fireAnalyti
|
|
|
66
72
|
...prev,
|
|
67
73
|
isLoading: false
|
|
68
74
|
}));
|
|
69
|
-
}, [isLoading, localId, manager.referenceManager, resourceId]);
|
|
75
|
+
}, [isLoading, localId, manager.referenceManager, resourceId, fireAnalyticsEvent]);
|
|
70
76
|
useEffect(() => {
|
|
71
77
|
if (isSSR()) {
|
|
72
78
|
// in SSR, we don't need to subscribe to updates,
|
package/dist/es2019/index.js
CHANGED
|
@@ -21,6 +21,7 @@ export { fetchConfluencePageInfo } from './clients/confluence/sourceInfo';
|
|
|
21
21
|
export { SyncedBlockProvider, useMemoizedSyncedBlockProvider } from './providers/syncBlockProvider';
|
|
22
22
|
// store managers
|
|
23
23
|
export { ReferenceSyncBlockStoreManager } from './store-manager/referenceSyncBlockStoreManager';
|
|
24
|
+
export { SyncBlockInMemorySessionCache, syncBlockInMemorySessionCache } from './store-manager/syncBlockInMemorySessionCache';
|
|
24
25
|
export { SyncBlockStoreManager, useMemoizedSyncBlockStoreManager } from './store-manager/syncBlockStoreManager';
|
|
25
26
|
|
|
26
27
|
// utils
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/* eslint-disable require-unicode-regexp */
|
|
2
2
|
import { useMemo } from 'react';
|
|
3
|
+
import { fg } from '@atlaskit/platform-feature-flags';
|
|
3
4
|
import { generateBlockAri, generateBlockAriFromReference } from '../../clients/block-service/ari';
|
|
4
5
|
import { batchRetrieveSyncedBlocks, BlockError, createSyncedBlock, deleteSyncedBlock, getReferenceSyncedBlocks, getReferenceSyncedBlocksByBlockAri, getSyncedBlockContent, updateReferenceSyncedBlockOnDocument, updateSyncedBlock } from '../../clients/block-service/blockService';
|
|
5
6
|
import { subscribeToBlockUpdates as subscribeToBlockUpdatesWS } from '../../clients/block-service/blockSubscription';
|
|
@@ -242,12 +243,22 @@ export const batchFetchData = async (cloudId, parentAri, blockNodeIdentifiers) =
|
|
|
242
243
|
resourceId
|
|
243
244
|
});
|
|
244
245
|
} catch {
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
246
|
+
if (fg('platform_synced_block_patch_3')) {
|
|
247
|
+
results.push({
|
|
248
|
+
error: {
|
|
249
|
+
type: SyncBlockError.Errored,
|
|
250
|
+
reason: `parsing JSON content response failed for resourceId: ${resourceId} localId: ${blockAri}`
|
|
251
|
+
},
|
|
252
|
+
resourceId
|
|
253
|
+
});
|
|
254
|
+
} else {
|
|
255
|
+
results.push({
|
|
256
|
+
error: {
|
|
257
|
+
type: SyncBlockError.Errored
|
|
258
|
+
},
|
|
259
|
+
resourceId
|
|
260
|
+
});
|
|
261
|
+
}
|
|
251
262
|
}
|
|
252
263
|
}
|
|
253
264
|
}
|
|
@@ -262,7 +273,10 @@ export const batchFetchData = async (cloudId, parentAri, blockNodeIdentifiers) =
|
|
|
262
273
|
}
|
|
263
274
|
processedResourceIds.add(resourceId);
|
|
264
275
|
results.push({
|
|
265
|
-
error: {
|
|
276
|
+
error: fg('platform_synced_block_patch_3') ? {
|
|
277
|
+
type: mapErrorResponseCode(errorResponse.code),
|
|
278
|
+
reason: errorResponse.reason
|
|
279
|
+
} : {
|
|
266
280
|
type: mapErrorResponseCode(errorResponse.code)
|
|
267
281
|
},
|
|
268
282
|
resourceId
|
|
@@ -286,7 +300,8 @@ export const batchFetchData = async (cloudId, parentAri, blockNodeIdentifiers) =
|
|
|
286
300
|
// If batch request fails, return error for all resourceIds
|
|
287
301
|
return blockNodeIdentifiers.map(blockNodeIdentifier => ({
|
|
288
302
|
error: {
|
|
289
|
-
type: error instanceof BlockError ? mapBlockError(error) : SyncBlockError.Errored
|
|
303
|
+
type: error instanceof BlockError ? mapBlockError(error) : SyncBlockError.Errored,
|
|
304
|
+
reason: fg('platform_synced_block_patch_3') ? error.message : undefined
|
|
290
305
|
},
|
|
291
306
|
resourceId: blockNodeIdentifier.resourceId
|
|
292
307
|
}));
|
|
@@ -354,14 +369,20 @@ class BlockServiceADFFetchProvider {
|
|
|
354
369
|
} catch (error) {
|
|
355
370
|
if (error instanceof BlockError) {
|
|
356
371
|
return {
|
|
357
|
-
error: {
|
|
372
|
+
error: fg('platform_synced_block_patch_3') ? {
|
|
373
|
+
type: mapBlockError(error),
|
|
374
|
+
reason: error.message
|
|
375
|
+
} : {
|
|
358
376
|
type: mapBlockError(error)
|
|
359
377
|
},
|
|
360
378
|
resourceId
|
|
361
379
|
};
|
|
362
380
|
}
|
|
363
381
|
return {
|
|
364
|
-
error: {
|
|
382
|
+
error: fg('platform_synced_block_patch_3') ? {
|
|
383
|
+
type: SyncBlockError.Errored,
|
|
384
|
+
reason: error.message
|
|
385
|
+
} : {
|
|
365
386
|
type: SyncBlockError.Errored
|
|
366
387
|
},
|
|
367
388
|
resourceId
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
2
|
import { useMemo } from 'react';
|
|
3
|
+
import { fg } from '@atlaskit/platform-feature-flags';
|
|
3
4
|
import { getProductFromSourceAri } from '../clients/block-service/ari';
|
|
4
5
|
import { getPageIdAndTypeFromConfluencePageAri } from '../clients/confluence/ari';
|
|
5
6
|
import { fetchConfluencePageInfo } from '../clients/confluence/sourceInfo';
|
|
@@ -70,9 +71,12 @@ export class SyncedBlockProvider extends SyncBlockDataProviderInterface {
|
|
|
70
71
|
return Promise.allSettled(blockIdentifiers.map(blockIdentifier => {
|
|
71
72
|
return this.fetchProvider.fetchData(blockIdentifier.resourceId).then(data => {
|
|
72
73
|
return data;
|
|
73
|
-
},
|
|
74
|
+
}, error => {
|
|
74
75
|
return {
|
|
75
|
-
error: {
|
|
76
|
+
error: fg('platform_synced_block_patch_3') ? {
|
|
77
|
+
type: SyncBlockError.Errored,
|
|
78
|
+
reason: error
|
|
79
|
+
} : {
|
|
76
80
|
type: SyncBlockError.Errored
|
|
77
81
|
},
|
|
78
82
|
resourceId: blockIdentifier.resourceId
|