@atlaskit/react-ufo 4.2.2 → 4.2.4

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 CHANGED
@@ -1,5 +1,21 @@
1
1
  # @atlaskit/ufo-interaction-ignore
2
2
 
3
+ ## 4.2.4
4
+
5
+ ### Patch Changes
6
+
7
+ - [#199942](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/pull-requests/199942)
8
+ [`260cb0fb9e934`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/260cb0fb9e934) -
9
+ Fix ssr placeholder size/dimension check resolution in TTVC v3
10
+
11
+ ## 4.2.3
12
+
13
+ ### Patch Changes
14
+
15
+ - [#199487](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/pull-requests/199487)
16
+ [`65e285a7a4cbc`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/65e285a7a4cbc) -
17
+ Added segments threshold when creating React UFO payload
18
+
3
19
  ## 4.2.2
4
20
 
5
21
  ### Patch Changes
@@ -5,15 +5,25 @@ Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
7
  exports.buildSegmentTree = buildSegmentTree;
8
+ exports.getOldSegmentsLabelStack = getOldSegmentsLabelStack;
8
9
  exports.isSegmentLabel = isSegmentLabel;
9
10
  exports.labelStackStartWith = labelStackStartWith;
10
11
  exports.optimizeLabelStack = optimizeLabelStack;
11
12
  exports.sanitizeUfoName = sanitizeUfoName;
12
13
  exports.stringifyLabelStackFully = stringifyLabelStackFully;
14
+ exports.stringifyLabelStackWithoutId = stringifyLabelStackWithoutId;
15
+ var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
13
16
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
14
17
  var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
18
+ var _config = require("../../../config");
19
+ var _getReactUfoPayloadVersion = require("../../utils/get-react-ufo-payload-version");
20
+ var _excluded = ["labelStack"],
21
+ _excluded2 = ["labelStack"];
15
22
  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; }
16
23
  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; }
24
+ 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; } } }; }
25
+ 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; } }
26
+ 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; }
17
27
  function sanitizeUfoName(name) {
18
28
  return name.replace(/_/g, '-');
19
29
  }
@@ -25,26 +35,72 @@ function buildSegmentTree(labelStacks) {
25
35
  n: 'segment-tree-root',
26
36
  c: {}
27
37
  };
28
- labelStacks.forEach(function (labelStack) {
29
- var currentNode = r;
30
- labelStack.forEach(function (label) {
31
- var name = label.name;
32
- var id = isSegmentLabel(label) ? label.segmentId : undefined;
33
- var key = id !== undefined ? id : name;
34
- var type = isSegmentLabel(label) ? label.type : undefined;
35
- if (!currentNode.c) {
36
- currentNode.c = {};
38
+ var config = (0, _config.getConfig)();
39
+ var segmentThreshold = config === null || config === void 0 ? void 0 : config.segmentsThreshold;
40
+ var addSegmentsMap = new Map();
41
+ if ((0, _platformFeatureFlags.fg)('platform_ufo_add_segments_count_threshold')) {
42
+ labelStacks.forEach(function (labelStack) {
43
+ var stringifiedLabelStack = stringifyLabelStackWithoutId(labelStack);
44
+ var currentNode = r;
45
+ var _iterator = _createForOfIteratorHelper(labelStack),
46
+ _step;
47
+ try {
48
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
49
+ var label = _step.value;
50
+ var isSegment = isSegmentLabel(label);
51
+ var name = label.name;
52
+ if (isSegment && segmentThreshold && segmentThreshold[name]) {
53
+ var threshold = segmentThreshold[name];
54
+ var count = addSegmentsMap.get(stringifiedLabelStack) || 0;
55
+ if (count < threshold) {
56
+ addSegmentsMap.set(stringifiedLabelStack, count + 1);
57
+ } else {
58
+ break;
59
+ }
60
+ }
61
+ var id = isSegment ? label.segmentId : undefined;
62
+ var key = id !== undefined ? id : name;
63
+ var type = isSegment ? label.type : undefined;
64
+ if (!currentNode.c) {
65
+ currentNode.c = {};
66
+ }
67
+ if (!currentNode.c[key]) {
68
+ currentNode.c[key] = _objectSpread({
69
+ n: name
70
+ }, type && (0, _platformFeatureFlags.fg)('platform_ufo_add_type_for_3p_segments') ? {
71
+ t: type
72
+ } : {});
73
+ }
74
+ currentNode = currentNode.c[key];
75
+ }
76
+ } catch (err) {
77
+ _iterator.e(err);
78
+ } finally {
79
+ _iterator.f();
37
80
  }
38
- if (!currentNode.c[key]) {
39
- currentNode.c[key] = _objectSpread({
40
- n: name
41
- }, type && (0, _platformFeatureFlags.fg)('platform_ufo_add_type_for_3p_segments') ? {
42
- t: type
43
- } : {});
44
- }
45
- currentNode = currentNode.c[key];
46
81
  });
47
- });
82
+ } else {
83
+ labelStacks.forEach(function (labelStack) {
84
+ var currentNode = r;
85
+ labelStack.forEach(function (label) {
86
+ var name = label.name;
87
+ var id = isSegmentLabel(label) ? label.segmentId : undefined;
88
+ var key = id !== undefined ? id : name;
89
+ var type = isSegmentLabel(label) ? label.type : undefined;
90
+ if (!currentNode.c) {
91
+ currentNode.c = {};
92
+ }
93
+ if (!currentNode.c[key]) {
94
+ currentNode.c[key] = _objectSpread({
95
+ n: name
96
+ }, type && (0, _platformFeatureFlags.fg)('platform_ufo_add_type_for_3p_segments') ? {
97
+ t: type
98
+ } : {});
99
+ }
100
+ currentNode = currentNode.c[key];
101
+ });
102
+ });
103
+ }
48
104
  return {
49
105
  r: r
50
106
  };
@@ -57,6 +113,14 @@ function stringifyLabelStackFully(labelStack) {
57
113
  return l.name;
58
114
  }).join('/');
59
115
  }
116
+ function stringifyLabelStackWithoutId(labelStack) {
117
+ return labelStack.map(function (l) {
118
+ if (isSegmentLabel(l)) {
119
+ return "".concat(l.name, ":segment");
120
+ }
121
+ return l.name;
122
+ }).join('/');
123
+ }
60
124
  function getLabelStackReference(labelStack) {
61
125
  return labelStack.map(function (l) {
62
126
  return isSegmentLabel(l) ? l.segmentId : l.name;
@@ -75,4 +139,55 @@ function optimizeLabelStack(labelStack, reactUFOVersion) {
75
139
  t: ls.type
76
140
  } : {});
77
141
  });
142
+ }
143
+ function getOldSegmentsLabelStack(segments, interactionType) {
144
+ if ((0, _platformFeatureFlags.fg)('platform_ufo_add_segments_count_threshold')) {
145
+ var config = (0, _config.getConfig)();
146
+ var addSegmentsMap = new Map();
147
+ var segmentThreshold = config === null || config === void 0 ? void 0 : config.segmentsThreshold;
148
+ return segments.map(function (_ref) {
149
+ var labelStack = _ref.labelStack,
150
+ others = (0, _objectWithoutProperties2.default)(_ref, _excluded);
151
+ var stringifiedLabelStack = stringifyLabelStackWithoutId(labelStack);
152
+ var segmentsInfo = [];
153
+ var _iterator2 = _createForOfIteratorHelper(labelStack),
154
+ _step2;
155
+ try {
156
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
157
+ var ls = _step2.value;
158
+ var isSegment = isSegmentLabel(ls);
159
+ if (isSegment && segmentThreshold && segmentThreshold[ls.name]) {
160
+ var threshold = segmentThreshold[ls.name];
161
+ var count = addSegmentsMap.get(stringifiedLabelStack) || 0;
162
+ if (count < threshold) {
163
+ addSegmentsMap.set(stringifiedLabelStack, count + 1);
164
+ } else {
165
+ break;
166
+ }
167
+ }
168
+ segmentsInfo.push(_objectSpread(_objectSpread({
169
+ n: ls.name
170
+ }, ls.segmentId ? {
171
+ s: ls.segmentId
172
+ } : {}), ls.type && (0, _platformFeatureFlags.fg)('platform_ufo_add_type_for_3p_segments') ? {
173
+ t: ls.type
174
+ } : {}));
175
+ }
176
+ } catch (err) {
177
+ _iterator2.e(err);
178
+ } finally {
179
+ _iterator2.f();
180
+ }
181
+ return _objectSpread(_objectSpread({}, others), {}, {
182
+ labelStack: segmentsInfo
183
+ });
184
+ });
185
+ }
186
+ return segments.map(function (_ref2) {
187
+ var labelStack = _ref2.labelStack,
188
+ others = (0, _objectWithoutProperties2.default)(_ref2, _excluded2);
189
+ return _objectSpread(_objectSpread({}, others), {}, {
190
+ labelStack: optimizeLabelStack(labelStack, (0, _getReactUfoPayloadVersion.getReactUFOPayloadVersion)(interactionType))
191
+ });
192
+ });
78
193
  }
@@ -47,8 +47,7 @@ var _getTtai = _interopRequireDefault(require("./utils/get-ttai"));
47
47
  var _getVcMetrics = _interopRequireDefault(require("./utils/get-vc-metrics"));
48
48
  var _excluded = ["labelStack", "time"],
49
49
  _excluded2 = ["stopTime", "labelStack"],
50
- _excluded3 = ["labelStack"],
51
- _excluded4 = ["labelStack"];
50
+ _excluded3 = ["labelStack"];
52
51
  function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
53
52
  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; }
54
53
  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; } // Import common utilities
@@ -756,13 +755,7 @@ function _createInteractionMetricsPayload() {
756
755
  apdex: optimizeApdex(interaction.apdex, (0, _getReactUfoPayloadVersion.getReactUFOPayloadVersion)(interaction.type)),
757
756
  end: Math.round(end),
758
757
  start: Math.round(start),
759
- segments: (0, _getReactUfoPayloadVersion.getReactUFOPayloadVersion)(interaction.type) === '2.0.0' ? segmentTree : segments.map(function (_ref7) {
760
- var labelStack = _ref7.labelStack,
761
- others = (0, _objectWithoutProperties2.default)(_ref7, _excluded4);
762
- return _objectSpread(_objectSpread({}, others), {}, {
763
- labelStack: (0, _utils.optimizeLabelStack)(labelStack, (0, _getReactUfoPayloadVersion.getReactUFOPayloadVersion)(interaction.type))
764
- });
765
- }),
758
+ segments: (0, _getReactUfoPayloadVersion.getReactUFOPayloadVersion)(interaction.type) === '2.0.0' ? segmentTree : (0, _utils.getOldSegmentsLabelStack)(segments, interaction.type),
766
759
  marks: optimizeMarks(interaction.marks, (0, _getReactUfoPayloadVersion.getReactUFOPayloadVersion)(interaction.type)),
767
760
  customData: optimizeCustomData(interaction),
768
761
  reactProfilerTimings: optimizeReactProfilerTimings(interaction.reactProfilerTimings, start, (0, _getReactUfoPayloadVersion.getReactUFOPayloadVersion)(interaction.type))
@@ -213,6 +213,8 @@ var SSRPlaceholderHandlers = exports.SSRPlaceholderHandlers = /*#__PURE__*/funct
213
213
  }
214
214
  return element;
215
215
  }
216
+
217
+ // NOTE - for use when the FG `platform_ufo_ssr_placeholder_resolution_ttvc_v3` is disabled
216
218
  }, {
217
219
  key: "checkIfExistedAndSizeMatching",
218
220
  value: function checkIfExistedAndSizeMatching(el) {
@@ -230,6 +232,15 @@ var SSRPlaceholderHandlers = exports.SSRPlaceholderHandlers = /*#__PURE__*/funct
230
232
  }
231
233
  });
232
234
  }
235
+
236
+ // NOTE - for use when the FG `platform_ufo_ssr_placeholder_resolution_ttvc_v3` is enabled
237
+ }, {
238
+ key: "checkIfExistedAndSizeMatchingV3",
239
+ value: function checkIfExistedAndSizeMatchingV3(el) {
240
+ el = this.findNearestPlaceholderContainerIfIgnored(el);
241
+ var id = this.getPlaceholderId(el);
242
+ return this.staticPlaceholders.has(id);
243
+ }
233
244
  }, {
234
245
  key: "getSize",
235
246
  value: function getSize(el) {
@@ -11,6 +11,7 @@ var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/
11
11
  var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
12
12
  var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
13
13
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
14
+ var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
14
15
  var _vcUtils = require("../../vc-observer/media-wrapper/vc-utils");
15
16
  var _isNonVisualStyleMutation = _interopRequireDefault(require("../../vc-observer/observers/non-visual-styles/is-non-visual-style-mutation"));
16
17
  var _rllPlaceholders = require("../../vc-observer/observers/rll-placeholders");
@@ -122,8 +123,8 @@ var ViewportObserver = exports.default = /*#__PURE__*/function () {
122
123
  _iterator = _createForOfIteratorHelper(addedNodes);
123
124
  _context2.prev = 4;
124
125
  _loop = /*#__PURE__*/_regenerator.default.mark(function _loop() {
125
- var _this$intersectionObs8;
126
- var addedNodeRef, addedNode, ssrState, SSRStateEnum, _this$intersectionObs, _this$intersectionObs2, ssrPlaceholderHandler, result, _this$intersectionObs3, _result, _this$intersectionObs4, sameDeletedNode, isInIgnoreLsMarker, _this$intersectionObs5, _this$intersectionObs6, _checkWithinComponent, isWithinThirdPartySegment, _this$intersectionObs7;
126
+ var _this$intersectionObs9;
127
+ var addedNodeRef, addedNode, ssrState, SSRStateEnum, _this$intersectionObs, _this$intersectionObs2, ssrPlaceholderHandler, _this$intersectionObs3, result, _this$intersectionObs4, _result, _this$intersectionObs5, sameDeletedNode, isInIgnoreLsMarker, _this$intersectionObs6, _this$intersectionObs7, _checkWithinComponent, isWithinThirdPartySegment, _this$intersectionObs8;
127
128
  return _regenerator.default.wrap(function _loop$(_context) {
128
129
  while (1) switch (_context.prev = _context.next) {
129
130
  case 0:
@@ -171,44 +172,58 @@ var ViewportObserver = exports.default = /*#__PURE__*/function () {
171
172
  ssrState.state = SSRStateEnum.normal;
172
173
  case 19:
173
174
  if (!_this.getSSRPlaceholderHandler) {
174
- _context.next = 36;
175
+ _context.next = 42;
175
176
  break;
176
177
  }
177
178
  ssrPlaceholderHandler = _this.getSSRPlaceholderHandler();
178
179
  if (!ssrPlaceholderHandler) {
179
- _context.next = 36;
180
+ _context.next = 42;
180
181
  break;
181
182
  }
182
183
  if (!(ssrPlaceholderHandler.isPlaceholder(addedNode) || ssrPlaceholderHandler.isPlaceholderIgnored(addedNode))) {
184
+ _context.next = 35;
185
+ break;
186
+ }
187
+ if (!(0, _platformFeatureFlags.fg)('platform_ufo_ssr_placeholder_resolution_ttvc_v3')) {
183
188
  _context.next = 29;
184
189
  break;
185
190
  }
186
- _context.next = 25;
191
+ if (!ssrPlaceholderHandler.checkIfExistedAndSizeMatchingV3(addedNode)) {
192
+ _context.next = 27;
193
+ break;
194
+ }
195
+ (_this$intersectionObs3 = _this.intersectionObserver) === null || _this$intersectionObs3 === void 0 || _this$intersectionObs3.watchAndTag(addedNode, 'mutation:ssr-placeholder');
196
+ return _context.abrupt("return", 0);
197
+ case 27:
198
+ _context.next = 35;
199
+ break;
200
+ case 29:
201
+ _context.next = 31;
187
202
  return ssrPlaceholderHandler.checkIfExistedAndSizeMatching(addedNode);
188
- case 25:
203
+ case 31:
189
204
  result = _context.sent;
190
205
  if (!(result !== false)) {
191
- _context.next = 29;
206
+ _context.next = 35;
192
207
  break;
193
208
  }
194
- (_this$intersectionObs3 = _this.intersectionObserver) === null || _this$intersectionObs3 === void 0 || _this$intersectionObs3.watchAndTag(addedNode, 'mutation:ssr-placeholder');
209
+ (_this$intersectionObs4 = _this.intersectionObserver) === null || _this$intersectionObs4 === void 0 || _this$intersectionObs4.watchAndTag(addedNode, 'mutation:ssr-placeholder');
195
210
  return _context.abrupt("return", 0);
196
- case 29:
211
+ case 35:
197
212
  if (!(ssrPlaceholderHandler.isPlaceholderReplacement(addedNode) || ssrPlaceholderHandler.isPlaceholderIgnored(addedNode))) {
198
- _context.next = 36;
213
+ _context.next = 42;
199
214
  break;
200
215
  }
201
- _context.next = 32;
216
+ _context.next = 38;
202
217
  return ssrPlaceholderHandler.validateReactComponentMatchToPlaceholder(addedNode);
203
- case 32:
218
+ case 38:
204
219
  _result = _context.sent;
205
220
  if (!(_result !== false)) {
206
- _context.next = 36;
221
+ _context.next = 42;
207
222
  break;
208
223
  }
209
- (_this$intersectionObs4 = _this.intersectionObserver) === null || _this$intersectionObs4 === void 0 || _this$intersectionObs4.watchAndTag(addedNode, 'mutation:ssr-placeholder');
224
+ (_this$intersectionObs5 = _this.intersectionObserver) === null || _this$intersectionObs5 === void 0 || _this$intersectionObs5.watchAndTag(addedNode, 'mutation:ssr-placeholder');
210
225
  return _context.abrupt("return", 0);
211
- case 36:
226
+ case 42:
212
227
  sameDeletedNode = removedNodes.find(function (ref) {
213
228
  var n = ref.deref();
214
229
  if (!n || !addedNode) {
@@ -218,29 +233,29 @@ var ViewportObserver = exports.default = /*#__PURE__*/function () {
218
233
  });
219
234
  isInIgnoreLsMarker = (0, _isInVcIgnoreIfNoLayoutShiftMarker.default)(addedNode);
220
235
  if (!(sameDeletedNode && isInIgnoreLsMarker)) {
221
- _context.next = 41;
236
+ _context.next = 47;
222
237
  break;
223
238
  }
224
- (_this$intersectionObs5 = _this.intersectionObserver) === null || _this$intersectionObs5 === void 0 || _this$intersectionObs5.watchAndTag(addedNode, 'mutation:remount');
239
+ (_this$intersectionObs6 = _this.intersectionObserver) === null || _this$intersectionObs6 === void 0 || _this$intersectionObs6.watchAndTag(addedNode, 'mutation:remount');
225
240
  return _context.abrupt("return", 0);
226
- case 41:
241
+ case 47:
227
242
  if (!(0, _vcUtils.isContainedWithinMediaWrapper)(addedNode)) {
228
- _context.next = 44;
243
+ _context.next = 50;
229
244
  break;
230
245
  }
231
- (_this$intersectionObs6 = _this.intersectionObserver) === null || _this$intersectionObs6 === void 0 || _this$intersectionObs6.watchAndTag(addedNode, 'mutation:media');
246
+ (_this$intersectionObs7 = _this.intersectionObserver) === null || _this$intersectionObs7 === void 0 || _this$intersectionObs7.watchAndTag(addedNode, 'mutation:media');
232
247
  return _context.abrupt("return", 0);
233
- case 44:
248
+ case 50:
234
249
  _checkWithinComponent = (0, _checkWithinComponent2.default)(addedNode, 'UFOThirdPartySegment', _this.mapIs3pResult), isWithinThirdPartySegment = _checkWithinComponent.isWithin;
235
250
  if (!isWithinThirdPartySegment) {
236
- _context.next = 48;
251
+ _context.next = 54;
237
252
  break;
238
253
  }
239
- (_this$intersectionObs7 = _this.intersectionObserver) === null || _this$intersectionObs7 === void 0 || _this$intersectionObs7.watchAndTag(addedNode, 'mutation:third-party-element');
254
+ (_this$intersectionObs8 = _this.intersectionObserver) === null || _this$intersectionObs8 === void 0 || _this$intersectionObs8.watchAndTag(addedNode, 'mutation:third-party-element');
240
255
  return _context.abrupt("return", 0);
241
- case 48:
242
- (_this$intersectionObs8 = _this.intersectionObserver) === null || _this$intersectionObs8 === void 0 || _this$intersectionObs8.watchAndTag(addedNode, createElementMutationsWatcher(removedNodeRects));
243
- case 49:
256
+ case 54:
257
+ (_this$intersectionObs9 = _this.intersectionObserver) === null || _this$intersectionObs9 === void 0 || _this$intersectionObs9.watchAndTag(addedNode, createElementMutationsWatcher(removedNodeRects));
258
+ case 55:
244
259
  case "end":
245
260
  return _context.stop();
246
261
  }
@@ -285,12 +300,12 @@ var ViewportObserver = exports.default = /*#__PURE__*/function () {
285
300
  };
286
301
  }());
287
302
  (0, _defineProperty2.default)(this, "handleAttributeMutation", function (_ref6) {
288
- var _this$intersectionObs9;
303
+ var _this$intersectionObs0;
289
304
  var target = _ref6.target,
290
305
  attributeName = _ref6.attributeName,
291
306
  oldValue = _ref6.oldValue,
292
307
  newValue = _ref6.newValue;
293
- (_this$intersectionObs9 = _this.intersectionObserver) === null || _this$intersectionObs9 === void 0 || _this$intersectionObs9.watchAndTag(target, function (_ref7) {
308
+ (_this$intersectionObs0 = _this.intersectionObserver) === null || _this$intersectionObs0 === void 0 || _this$intersectionObs0.watchAndTag(target, function (_ref7) {
294
309
  var target = _ref7.target,
295
310
  rect = _ref7.rect;
296
311
  if ((0, _vcUtils.isContainedWithinMediaWrapper)(target)) {
@@ -430,12 +445,12 @@ var ViewportObserver = exports.default = /*#__PURE__*/function () {
430
445
  }, {
431
446
  key: "stop",
432
447
  value: function stop() {
433
- var _this$mutationObserve2, _this$intersectionObs0, _this$performanceObse2;
448
+ var _this$mutationObserve2, _this$intersectionObs1, _this$performanceObse2;
434
449
  if (!this.isStarted) {
435
450
  return;
436
451
  }
437
452
  (_this$mutationObserve2 = this.mutationObserver) === null || _this$mutationObserve2 === void 0 || _this$mutationObserve2.disconnect();
438
- (_this$intersectionObs0 = this.intersectionObserver) === null || _this$intersectionObs0 === void 0 || _this$intersectionObs0.disconnect();
453
+ (_this$intersectionObs1 = this.intersectionObserver) === null || _this$intersectionObs1 === void 0 || _this$intersectionObs1.disconnect();
439
454
  (_this$performanceObse2 = this.performanceObserver) === null || _this$performanceObse2 === void 0 || _this$performanceObse2.disconnect();
440
455
  this.isStarted = false;
441
456
  // Clean up caches when stopping
@@ -1,4 +1,6 @@
1
1
  import { fg } from '@atlaskit/platform-feature-flags';
2
+ import { getConfig } from '../../../config';
3
+ import { getReactUFOPayloadVersion } from '../../utils/get-react-ufo-payload-version';
2
4
  export function sanitizeUfoName(name) {
3
5
  return name.replace(/_/g, '-');
4
6
  }
@@ -10,27 +12,65 @@ export function buildSegmentTree(labelStacks) {
10
12
  n: 'segment-tree-root',
11
13
  c: {}
12
14
  };
13
- labelStacks.forEach(labelStack => {
14
- let currentNode = r;
15
- labelStack.forEach(label => {
16
- const name = label.name;
17
- const id = isSegmentLabel(label) ? label.segmentId : undefined;
18
- const key = id !== undefined ? id : name;
19
- const type = isSegmentLabel(label) ? label.type : undefined;
20
- if (!currentNode.c) {
21
- currentNode.c = {};
15
+ const config = getConfig();
16
+ const segmentThreshold = config === null || config === void 0 ? void 0 : config.segmentsThreshold;
17
+ const addSegmentsMap = new Map();
18
+ if (fg('platform_ufo_add_segments_count_threshold')) {
19
+ labelStacks.forEach(labelStack => {
20
+ const stringifiedLabelStack = stringifyLabelStackWithoutId(labelStack);
21
+ let currentNode = r;
22
+ for (const label of labelStack) {
23
+ const isSegment = isSegmentLabel(label);
24
+ const name = label.name;
25
+ if (isSegment && segmentThreshold && segmentThreshold[name]) {
26
+ const threshold = segmentThreshold[name];
27
+ const count = addSegmentsMap.get(stringifiedLabelStack) || 0;
28
+ if (count < threshold) {
29
+ addSegmentsMap.set(stringifiedLabelStack, count + 1);
30
+ } else {
31
+ break;
32
+ }
33
+ }
34
+ const id = isSegment ? label.segmentId : undefined;
35
+ const key = id !== undefined ? id : name;
36
+ const type = isSegment ? label.type : undefined;
37
+ if (!currentNode.c) {
38
+ currentNode.c = {};
39
+ }
40
+ if (!currentNode.c[key]) {
41
+ currentNode.c[key] = {
42
+ n: name,
43
+ ...(type && fg('platform_ufo_add_type_for_3p_segments') ? {
44
+ t: type
45
+ } : {})
46
+ };
47
+ }
48
+ currentNode = currentNode.c[key];
22
49
  }
23
- if (!currentNode.c[key]) {
24
- currentNode.c[key] = {
25
- n: name,
26
- ...(type && fg('platform_ufo_add_type_for_3p_segments') ? {
27
- t: type
28
- } : {})
29
- };
30
- }
31
- currentNode = currentNode.c[key];
32
50
  });
33
- });
51
+ } else {
52
+ labelStacks.forEach(labelStack => {
53
+ let currentNode = r;
54
+ labelStack.forEach(label => {
55
+ const name = label.name;
56
+ const id = isSegmentLabel(label) ? label.segmentId : undefined;
57
+ const key = id !== undefined ? id : name;
58
+ const type = isSegmentLabel(label) ? label.type : undefined;
59
+ if (!currentNode.c) {
60
+ currentNode.c = {};
61
+ }
62
+ if (!currentNode.c[key]) {
63
+ currentNode.c[key] = {
64
+ n: name,
65
+ ...(type && fg('platform_ufo_add_type_for_3p_segments') ? {
66
+ t: type
67
+ } : {})
68
+ };
69
+ }
70
+ currentNode = currentNode.c[key];
71
+ });
72
+ });
73
+ }
34
74
  return {
35
75
  r
36
76
  };
@@ -43,6 +83,14 @@ export function stringifyLabelStackFully(labelStack) {
43
83
  return l.name;
44
84
  }).join('/');
45
85
  }
86
+ export function stringifyLabelStackWithoutId(labelStack) {
87
+ return labelStack.map(l => {
88
+ if (isSegmentLabel(l)) {
89
+ return `${l.name}:segment`;
90
+ }
91
+ return l.name;
92
+ }).join('/');
93
+ }
46
94
  function getLabelStackReference(labelStack) {
47
95
  return labelStack.map(l => isSegmentLabel(l) ? l.segmentId : l.name).join('/');
48
96
  }
@@ -59,4 +107,50 @@ export function optimizeLabelStack(labelStack, reactUFOVersion) {
59
107
  t: ls.type
60
108
  } : {})
61
109
  }));
110
+ }
111
+ export function getOldSegmentsLabelStack(segments, interactionType) {
112
+ if (fg('platform_ufo_add_segments_count_threshold')) {
113
+ const config = getConfig();
114
+ const addSegmentsMap = new Map();
115
+ const segmentThreshold = config === null || config === void 0 ? void 0 : config.segmentsThreshold;
116
+ return segments.map(({
117
+ labelStack,
118
+ ...others
119
+ }) => {
120
+ const stringifiedLabelStack = stringifyLabelStackWithoutId(labelStack);
121
+ const segmentsInfo = [];
122
+ for (const ls of labelStack) {
123
+ const isSegment = isSegmentLabel(ls);
124
+ if (isSegment && segmentThreshold && segmentThreshold[ls.name]) {
125
+ const threshold = segmentThreshold[ls.name];
126
+ const count = addSegmentsMap.get(stringifiedLabelStack) || 0;
127
+ if (count < threshold) {
128
+ addSegmentsMap.set(stringifiedLabelStack, count + 1);
129
+ } else {
130
+ break;
131
+ }
132
+ }
133
+ segmentsInfo.push({
134
+ n: ls.name,
135
+ ...(ls.segmentId ? {
136
+ s: ls.segmentId
137
+ } : {}),
138
+ ...(ls.type && fg('platform_ufo_add_type_for_3p_segments') ? {
139
+ t: ls.type
140
+ } : {})
141
+ });
142
+ }
143
+ return {
144
+ ...others,
145
+ labelStack: segmentsInfo
146
+ };
147
+ });
148
+ }
149
+ return segments.map(({
150
+ labelStack,
151
+ ...others
152
+ }) => ({
153
+ ...others,
154
+ labelStack: optimizeLabelStack(labelStack, getReactUFOPayloadVersion(interactionType))
155
+ }));
62
156
  }
@@ -19,7 +19,7 @@ import * as resourceTiming from '../resource-timing';
19
19
  import { filterResourceTimings } from '../resource-timing/common/utils/resource-timing-buffer';
20
20
  import { roundEpsilon } from '../round-number';
21
21
  import * as ssr from '../ssr';
22
- import { buildSegmentTree, labelStackStartWith, optimizeLabelStack, sanitizeUfoName, stringifyLabelStackFully } from './common/utils';
22
+ import { buildSegmentTree, getOldSegmentsLabelStack, labelStackStartWith, optimizeLabelStack, sanitizeUfoName, stringifyLabelStackFully } from './common/utils';
23
23
  import { createCriticalMetricsPayloads } from './critical-metrics-payload';
24
24
  import { addPerformanceMeasures } from './utils/add-performance-measures';
25
25
  import { getBrowserMetadataToLegacyFormat } from './utils/get-browser-metadata';
@@ -754,13 +754,7 @@ async function createInteractionMetricsPayload(interaction, interactionId, exper
754
754
  apdex: optimizeApdex(interaction.apdex, getReactUFOPayloadVersion(interaction.type)),
755
755
  end: Math.round(end),
756
756
  start: Math.round(start),
757
- segments: getReactUFOPayloadVersion(interaction.type) === '2.0.0' ? segmentTree : segments.map(({
758
- labelStack,
759
- ...others
760
- }) => ({
761
- ...others,
762
- labelStack: optimizeLabelStack(labelStack, getReactUFOPayloadVersion(interaction.type))
763
- })),
757
+ segments: getReactUFOPayloadVersion(interaction.type) === '2.0.0' ? segmentTree : getOldSegmentsLabelStack(segments, interaction.type),
764
758
  marks: optimizeMarks(interaction.marks, getReactUFOPayloadVersion(interaction.type)),
765
759
  customData: optimizeCustomData(interaction),
766
760
  reactProfilerTimings: optimizeReactProfilerTimings(interaction.reactProfilerTimings, start, getReactUFOPayloadVersion(interaction.type)),
@@ -184,6 +184,8 @@ export class SSRPlaceholderHandlers {
184
184
  }
185
185
  return element;
186
186
  }
187
+
188
+ // NOTE - for use when the FG `platform_ufo_ssr_placeholder_resolution_ttvc_v3` is disabled
187
189
  checkIfExistedAndSizeMatching(el) {
188
190
  el = this.findNearestPlaceholderContainerIfIgnored(el);
189
191
  const id = this.getPlaceholderId(el);
@@ -198,6 +200,13 @@ export class SSRPlaceholderHandlers {
198
200
  }
199
201
  });
200
202
  }
203
+
204
+ // NOTE - for use when the FG `platform_ufo_ssr_placeholder_resolution_ttvc_v3` is enabled
205
+ checkIfExistedAndSizeMatchingV3(el) {
206
+ el = this.findNearestPlaceholderContainerIfIgnored(el);
207
+ const id = this.getPlaceholderId(el);
208
+ return this.staticPlaceholders.has(id);
209
+ }
201
210
  getSize(el) {
202
211
  return new Promise(resolve => {
203
212
  var _this$intersectionObs4;