@atlaskit/react-ufo 2.3.2 → 2.4.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 (33) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/dist/cjs/common/constants.js +2 -1
  3. package/dist/cjs/create-payload/common/utils/index.js +61 -2
  4. package/dist/cjs/create-payload/index.js +22 -47
  5. package/dist/cjs/vc/index.js +3 -4
  6. package/dist/cjs/vc/vc-observer/index.js +6 -0
  7. package/dist/es2019/common/constants.js +2 -1
  8. package/dist/es2019/create-payload/common/utils/index.js +53 -2
  9. package/dist/es2019/create-payload/index.js +5 -31
  10. package/dist/es2019/vc/index.js +3 -4
  11. package/dist/es2019/vc/vc-observer/index.js +3 -0
  12. package/dist/esm/common/constants.js +2 -1
  13. package/dist/esm/create-payload/common/utils/index.js +57 -2
  14. package/dist/esm/create-payload/index.js +7 -32
  15. package/dist/esm/vc/index.js +3 -4
  16. package/dist/esm/vc/vc-observer/index.js +6 -0
  17. package/dist/types/common/constants.d.ts +1 -1
  18. package/dist/types/common/vc/types.d.ts +1 -1
  19. package/dist/types/create-payload/common/types.d.ts +1 -1
  20. package/dist/types/create-payload/common/utils/index.d.ts +15 -1
  21. package/dist/types/create-payload/index.d.ts +144 -144
  22. package/dist/types/interaction-context/index.d.ts +1 -1
  23. package/dist/types/vc/index.d.ts +3 -0
  24. package/dist/types/vc/vc-observer/index.d.ts +2 -1
  25. package/dist/types-ts4.5/common/constants.d.ts +1 -1
  26. package/dist/types-ts4.5/common/vc/types.d.ts +1 -1
  27. package/dist/types-ts4.5/create-payload/common/types.d.ts +1 -1
  28. package/dist/types-ts4.5/create-payload/common/utils/index.d.ts +15 -1
  29. package/dist/types-ts4.5/create-payload/index.d.ts +144 -144
  30. package/dist/types-ts4.5/interaction-context/index.d.ts +1 -1
  31. package/dist/types-ts4.5/vc/index.d.ts +3 -0
  32. package/dist/types-ts4.5/vc/vc-observer/index.d.ts +2 -1
  33. package/package.json +4 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,21 @@
1
1
  # @atlaskit/ufo-interaction-ignore
2
2
 
3
+ ## 2.4.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#169410](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/169410)
8
+ [`70969d8e13353`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/70969d8e13353) -
9
+ Optimising React UFO payload size by referncing segments tree
10
+
11
+ ## 2.3.3
12
+
13
+ ### Patch Changes
14
+
15
+ - [#169231](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/169231)
16
+ [`bf7c1455e4d57`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/bf7c1455e4d57) -
17
+ allow for custom VC abort reasons
18
+
3
19
  ## 2.3.2
4
20
 
5
21
  ### Patch Changes
@@ -4,4 +4,5 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.REACT_UFO_VERSION = void 0;
7
- var REACT_UFO_VERSION = exports.REACT_UFO_VERSION = '1.0.1';
7
+ var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
8
+ var REACT_UFO_VERSION = exports.REACT_UFO_VERSION = (0, _platformFeatureFlags.fg)('react-ufo-payload-segment-compressed') ? '2.0.0' : '1.0.1';
@@ -1,15 +1,74 @@
1
1
  "use strict";
2
2
 
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
3
4
  Object.defineProperty(exports, "__esModule", {
4
5
  value: true
5
6
  });
7
+ exports.buildSegmentTree = buildSegmentTree;
6
8
  exports.isSegmentLabel = isSegmentLabel;
9
+ exports.labelStackStartWith = labelStackStartWith;
10
+ exports.optimizeLabelStack = optimizeLabelStack;
7
11
  exports.sanitizeUfoName = void 0;
12
+ exports.stringifyLabelStackFully = stringifyLabelStackFully;
13
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
14
+ var _constants = require("../../../common/constants");
15
+ 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
+ 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; } /* eslint-disable @typescript-eslint/no-non-null-asserted-optional-chain */
8
17
  var sanitizeUfoName = exports.sanitizeUfoName = function sanitizeUfoName(name) {
9
18
  return name.replace(/_/g, '-');
10
19
  };
11
-
12
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
13
20
  function isSegmentLabel(obj) {
14
21
  return obj && typeof obj.name === 'string' && typeof obj.segmentId === 'string';
22
+ }
23
+ function buildSegmentTree(labelStacks) {
24
+ var r = {
25
+ n: 'segment-tree-root',
26
+ c: {}
27
+ };
28
+ labelStacks.forEach(function (labelStack) {
29
+ var currentNode = r;
30
+ labelStack.forEach(function (label, index) {
31
+ var _currentNode$c;
32
+ var name = label.name;
33
+ var id = isSegmentLabel(label) ? label.segmentId : undefined;
34
+ var key = id !== undefined ? id.toString() : name;
35
+ if (currentNode.c && !currentNode.c[key]) {
36
+ currentNode.c[key] = {
37
+ n: name
38
+ };
39
+ }
40
+ currentNode = (_currentNode$c = currentNode.c) === null || _currentNode$c === void 0 ? void 0 : _currentNode$c[key];
41
+ if (index < labelStack.length - 1) {
42
+ currentNode.c = _objectSpread({}, currentNode.c || {});
43
+ }
44
+ });
45
+ });
46
+ return {
47
+ r: r
48
+ };
49
+ }
50
+ function stringifyLabelStackFully(labelStack) {
51
+ return labelStack.map(function (l) {
52
+ if (isSegmentLabel(l)) {
53
+ return "".concat(l.name, ":").concat(l.segmentId);
54
+ }
55
+ return l.name;
56
+ }).join('/');
57
+ }
58
+ function getLabelStackReference(labelStack) {
59
+ return labelStack.map(function (l) {
60
+ return isSegmentLabel(l) ? l.segmentId : l.name;
61
+ }).join('/');
62
+ }
63
+ function labelStackStartWith(labelStack, startWith) {
64
+ return stringifyLabelStackFully(labelStack).startsWith(stringifyLabelStackFully(startWith));
65
+ }
66
+ function optimizeLabelStack(labelStack) {
67
+ return _constants.REACT_UFO_VERSION === '2.0.0' ? getLabelStackReference(labelStack) : labelStack.map(function (ls) {
68
+ return _objectSpread({
69
+ n: ls.name
70
+ }, ls.segmentId ? {
71
+ s: ls.segmentId
72
+ } : {});
73
+ });
15
74
  }
@@ -49,17 +49,6 @@ function getUfoNameOverride(interaction) {
49
49
  return ufoName;
50
50
  }
51
51
  }
52
- function stringifyLabelStackFully(labelStack) {
53
- return labelStack.map(function (l) {
54
- if ((0, _utils.isSegmentLabel)(l)) {
55
- return "".concat(l.name, ":").concat(l.segmentId);
56
- }
57
- return l.name;
58
- }).join('/');
59
- }
60
- function labelStackStartWith(labelStack, startWith) {
61
- return stringifyLabelStackFully(labelStack).startsWith(stringifyLabelStackFully(startWith));
62
- }
63
52
  function getEarliestLegacyStopTime(interaction, labelStack) {
64
53
  var earliestLegacyStopTime = null;
65
54
  interaction.apdex.forEach(function (a) {
@@ -67,7 +56,7 @@ function getEarliestLegacyStopTime(interaction, labelStack) {
67
56
  if (!(a !== null && a !== void 0 && a.stopTime)) {
68
57
  return;
69
58
  }
70
- if (!labelStackStartWith((_a$labelStack = a.labelStack) !== null && _a$labelStack !== void 0 ? _a$labelStack : [], labelStack)) {
59
+ if (!(0, _utils.labelStackStartWith)((_a$labelStack = a.labelStack) !== null && _a$labelStack !== void 0 ? _a$labelStack : [], labelStack)) {
71
60
  return;
72
61
  }
73
62
  if (a.stopTime > interaction.start && ((_earliestLegacyStopTi = earliestLegacyStopTime) !== null && _earliestLegacyStopTi !== void 0 ? _earliestLegacyStopTi : a.stopTime) >= a.stopTime) {
@@ -345,18 +334,6 @@ var getTracingContextData = function getTracingContextData(interaction) {
345
334
  }
346
335
  return tracingContextData;
347
336
  };
348
-
349
- // interaction metric
350
-
351
- function optimizeLabelStack(labelStack) {
352
- return labelStack.map(function (ls) {
353
- return _objectSpread({
354
- n: ls.name
355
- }, ls.segmentId ? {
356
- s: ls.segmentId
357
- } : {});
358
- });
359
- }
360
337
  function optimizeCustomData(interaction) {
361
338
  var customData = interaction.customData,
362
339
  legacyMetrics = interaction.legacyMetrics;
@@ -364,10 +341,10 @@ function optimizeCustomData(interaction) {
364
341
  var _result$get$data, _result$get;
365
342
  var labelStack = _ref2.labelStack,
366
343
  data = _ref2.data;
367
- var label = stringifyLabelStackFully(labelStack);
344
+ var label = (0, _utils.stringifyLabelStackFully)(labelStack);
368
345
  var value = (_result$get$data = (_result$get = result.get(label)) === null || _result$get === void 0 ? void 0 : _result$get.data) !== null && _result$get$data !== void 0 ? _result$get$data : {};
369
346
  result.set(label, {
370
- labelStack: optimizeLabelStack(labelStack),
347
+ labelStack: (0, _utils.optimizeLabelStack)(labelStack),
371
348
  data: Object.assign(value, data)
372
349
  });
373
350
  return result;
@@ -381,10 +358,10 @@ function optimizeCustomData(interaction) {
381
358
  var _Object$entries$_i = (0, _slicedToArray2.default)(_Object$entries[_i], 2),
382
359
  _key = _Object$entries$_i[0],
383
360
  value = _Object$entries$_i[1];
384
- var label = stringifyLabelStackFully([]);
361
+ var label = (0, _utils.stringifyLabelStackFully)([]);
385
362
  var labelValue = (_result$get$data2 = (_result$get2 = result.get(label)) === null || _result$get2 === void 0 ? void 0 : _result$get2.data) !== null && _result$get$data2 !== void 0 ? _result$get$data2 : {};
386
363
  result.set(label, {
387
- labelStack: optimizeLabelStack([]),
364
+ labelStack: (0, _utils.optimizeLabelStack)([]),
388
365
  data: Object.assign(labelValue, (0, _defineProperty2.default)({}, _key, value))
389
366
  });
390
367
  }
@@ -402,11 +379,11 @@ function optimizeReactProfilerTimings(reactProfilerTimings, interactionStart) {
402
379
  actualDuration = _ref3.actualDuration,
403
380
  type = _ref3.type;
404
381
  if (labelStack && startTime >= interactionStart) {
405
- var label = stringifyLabelStackFully(labelStack);
382
+ var label = (0, _utils.stringifyLabelStackFully)(labelStack);
406
383
  var start = Math.round(startTime);
407
384
  var end = Math.round(commitTime);
408
385
  var timing = result.get(label) || {
409
- labelStack: optimizeLabelStack(labelStack),
386
+ labelStack: (0, _utils.optimizeLabelStack)(labelStack),
410
387
  startTime: start,
411
388
  endTime: end,
412
389
  mountCount: 0,
@@ -461,13 +438,13 @@ function optimizeHoldInfo(holdInfo, interactionStart) {
461
438
  end = hold.end,
462
439
  ignoreOnSubmit = hold.ignoreOnSubmit;
463
440
  if (labelStack && !ignoreOnSubmit && start >= interactionStart) {
464
- var label = stringifyLabelStackFully([].concat((0, _toConsumableArray2.default)(labelStack), [{
441
+ var label = (0, _utils.stringifyLabelStackFully)([].concat((0, _toConsumableArray2.default)(labelStack), [{
465
442
  name: name
466
443
  }]));
467
444
  var startTime = Math.round(start);
468
445
  var endTime = Math.round(end);
469
446
  var timing = result.get(label) || {
470
- labelStack: optimizeLabelStack([].concat((0, _toConsumableArray2.default)(labelStack), [{
447
+ labelStack: (0, _utils.optimizeLabelStack)([].concat((0, _toConsumableArray2.default)(labelStack), [{
471
448
  name: name
472
449
  }])),
473
450
  startTime: startTime,
@@ -494,7 +471,7 @@ function optimizeSpans(spans, interactionStart) {
494
471
  end = span.end;
495
472
  if (labelStack && start >= interactionStart) {
496
473
  result.push({
497
- labelStack: optimizeLabelStack([].concat((0, _toConsumableArray2.default)(labelStack), [{
474
+ labelStack: (0, _utils.optimizeLabelStack)([].concat((0, _toConsumableArray2.default)(labelStack), [{
498
475
  name: name
499
476
  }])),
500
477
  startTime: Math.round(start),
@@ -518,7 +495,7 @@ function optimizeRequestInfo(requestInfo, interactionStart) {
518
495
  var endTime = networkComplete !== null && networkComplete !== void 0 ? networkComplete : end;
519
496
  if (labelStack && start >= interactionStart && endTime) {
520
497
  result.push({
521
- labelStack: optimizeLabelStack([].concat((0, _toConsumableArray2.default)(labelStack), [{
498
+ labelStack: (0, _utils.optimizeLabelStack)([].concat((0, _toConsumableArray2.default)(labelStack), [{
522
499
  name: name
523
500
  }])),
524
501
  startTime: Math.round(startTime),
@@ -530,7 +507,7 @@ function optimizeRequestInfo(requestInfo, interactionStart) {
530
507
  return updatedRequestInfo;
531
508
  }
532
509
  function optimizeCustomTimings(customTimings, interactionStart) {
533
- var updatedCustomTimings = customTimings.reduce(function (result, item) {
510
+ return customTimings.reduce(function (result, item) {
534
511
  Object.keys(item.data).forEach(function (key) {
535
512
  if (item.data[key].startTime >= interactionStart) {
536
513
  result.push({
@@ -544,7 +521,6 @@ function optimizeCustomTimings(customTimings, interactionStart) {
544
521
  });
545
522
  return result;
546
523
  }, []);
547
- return updatedCustomTimings;
548
524
  }
549
525
  function optimizeMarks(marks) {
550
526
  return marks.map(function (_ref4) {
@@ -552,7 +528,7 @@ function optimizeMarks(marks) {
552
528
  time = _ref4.time,
553
529
  others = (0, _objectWithoutProperties2.default)(_ref4, _excluded);
554
530
  return _objectSpread(_objectSpread({}, others), {}, {
555
- labelStack: labelStack && optimizeLabelStack(labelStack),
531
+ labelStack: labelStack && (0, _utils.optimizeLabelStack)(labelStack),
556
532
  time: Math.round(time)
557
533
  });
558
534
  });
@@ -565,12 +541,10 @@ function optimizeApdex(apdex) {
565
541
  return _objectSpread(_objectSpread({}, others), {}, {
566
542
  stopTime: Math.round(stopTime)
567
543
  }, labelStack ? {
568
- labelStack: optimizeLabelStack(labelStack)
544
+ labelStack: (0, _utils.optimizeLabelStack)(labelStack)
569
545
  } : {});
570
546
  });
571
547
  }
572
-
573
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
574
548
  function objectToArray() {
575
549
  var obj = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
576
550
  return Object.keys(obj).reduce(function (result, key) {
@@ -579,9 +553,7 @@ function objectToArray() {
579
553
  data: obj[key]
580
554
  });
581
555
  return result;
582
- },
583
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
584
- []);
556
+ }, []);
585
557
  }
586
558
  function getBM3SubmetricsTimings(submetrics) {
587
559
  if (!submetrics) {
@@ -657,13 +629,16 @@ function createInteractionMetricsPayload(interaction, interactionId) {
657
629
  var pageVisibilityAtTTI = getPageVisibilityUpToTTI(interaction);
658
630
  var pageVisibilityAtTTAI = getPageVisibilityUpToTTAI(interaction);
659
631
  var segments = config.killswitchNestedSegments ? [] : knownSegments;
632
+ var segmentTree = (0, _utils.buildSegmentTree)(segments.map(function (segment) {
633
+ return segment.labelStack;
634
+ }));
660
635
  var isDetailedPayload = pageVisibilityAtTTAI === 'visible';
661
636
  var isPageLoad = type === 'page_load';
662
637
  var calculatePageVisibilityFromTheStartOfPageLoad = config.enableBetterPageVisibilityApi && isPageLoad;
663
638
  var moreAccuratePageVisibilityAtTTI = calculatePageVisibilityFromTheStartOfPageLoad ? getMoreAccuratePageVisibilityUpToTTI(interaction) : null;
664
639
  var moreAccuratePageVisibilityAtTTAI = calculatePageVisibilityFromTheStartOfPageLoad ? getMoreAccuratePageVisibilityUpToTTAI(interaction) : null;
665
640
  var labelStack = interaction.labelStack ? {
666
- labelStack: optimizeLabelStack(interaction.labelStack)
641
+ labelStack: (0, _utils.optimizeLabelStack)(interaction.labelStack)
667
642
  } : {};
668
643
  // Page Load
669
644
  var getPageLoadInteractionMetrics = function getPageLoadInteractionMetrics() {
@@ -693,7 +668,7 @@ function createInteractionMetricsPayload(interaction, interactionId) {
693
668
  var labelStack = _ref6.labelStack,
694
669
  others = (0, _objectWithoutProperties2.default)(_ref6, _excluded3);
695
670
  return _objectSpread(_objectSpread({}, others), {}, {
696
- labelStack: labelStack && optimizeLabelStack(labelStack)
671
+ labelStack: labelStack && (0, _utils.optimizeLabelStack)(labelStack)
697
672
  });
698
673
  }),
699
674
  holdActive: (0, _toConsumableArray2.default)(interaction.holdActive.values()),
@@ -762,11 +737,11 @@ function createInteractionMetricsPayload(interaction, interactionId) {
762
737
  apdex: optimizeApdex(interaction.apdex),
763
738
  end: Math.round(end),
764
739
  start: Math.round(start),
765
- segments: segments.map(function (_ref7) {
740
+ segments: _constants.REACT_UFO_VERSION === '2.0.0' ? segmentTree : segments.map(function (_ref7) {
766
741
  var labelStack = _ref7.labelStack,
767
742
  others = (0, _objectWithoutProperties2.default)(_ref7, _excluded4);
768
743
  return _objectSpread(_objectSpread({}, others), {}, {
769
- labelStack: optimizeLabelStack(labelStack)
744
+ labelStack: (0, _utils.optimizeLabelStack)(labelStack)
770
745
  });
771
746
  }),
772
747
  marks: optimizeMarks(interaction.marks),
@@ -5,11 +5,10 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.getVCObserver = void 0;
7
7
  var _vcObserver = require("./vc-observer");
8
- var instance = null;
9
8
  var getVCObserver = exports.getVCObserver = function getVCObserver() {
10
9
  var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
11
- if (instance === null) {
12
- instance = new _vcObserver.VCObserver(opts);
10
+ if (!globalThis.__vcObserver) {
11
+ globalThis.__vcObserver = new _vcObserver.VCObserver(opts);
13
12
  }
14
- return instance;
13
+ return globalThis.__vcObserver;
15
14
  };
@@ -364,6 +364,12 @@ var VCObserver = exports.VCObserver = /*#__PURE__*/function () {
364
364
  var stopTime = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : performance.now();
365
365
  this.observers.setReactRootRenderStop(stopTime);
366
366
  }
367
+ }, {
368
+ key: "abortObservation",
369
+ value: function abortObservation() {
370
+ var abortReason = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'custom';
371
+ this.setAbortReason(abortReason, performance.now());
372
+ }
367
373
  }, {
368
374
  key: "setAbortReason",
369
375
  value: function setAbortReason(abort, timestamp) {
@@ -1 +1,2 @@
1
- export const REACT_UFO_VERSION = '1.0.1';
1
+ import { fg } from '@atlaskit/platform-feature-flags';
2
+ export const REACT_UFO_VERSION = fg('react-ufo-payload-segment-compressed') ? '2.0.0' : '1.0.1';
@@ -1,8 +1,59 @@
1
+ /* eslint-disable @typescript-eslint/no-non-null-asserted-optional-chain */
2
+ import { REACT_UFO_VERSION } from '../../../common/constants';
1
3
  export const sanitizeUfoName = name => {
2
4
  return name.replace(/_/g, '-');
3
5
  };
4
-
5
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
6
6
  export function isSegmentLabel(obj) {
7
7
  return obj && typeof obj.name === 'string' && typeof obj.segmentId === 'string';
8
+ }
9
+ export function buildSegmentTree(labelStacks) {
10
+ const r = {
11
+ n: 'segment-tree-root',
12
+ c: {}
13
+ };
14
+ labelStacks.forEach(labelStack => {
15
+ let currentNode = r;
16
+ labelStack.forEach((label, index) => {
17
+ var _currentNode$c;
18
+ const name = label.name;
19
+ const id = isSegmentLabel(label) ? label.segmentId : undefined;
20
+ const key = id !== undefined ? id.toString() : name;
21
+ if (currentNode.c && !currentNode.c[key]) {
22
+ currentNode.c[key] = {
23
+ n: name
24
+ };
25
+ }
26
+ currentNode = (_currentNode$c = currentNode.c) === null || _currentNode$c === void 0 ? void 0 : _currentNode$c[key];
27
+ if (index < labelStack.length - 1) {
28
+ currentNode.c = {
29
+ ...(currentNode.c || {})
30
+ };
31
+ }
32
+ });
33
+ });
34
+ return {
35
+ r
36
+ };
37
+ }
38
+ export function stringifyLabelStackFully(labelStack) {
39
+ return labelStack.map(l => {
40
+ if (isSegmentLabel(l)) {
41
+ return `${l.name}:${l.segmentId}`;
42
+ }
43
+ return l.name;
44
+ }).join('/');
45
+ }
46
+ function getLabelStackReference(labelStack) {
47
+ return labelStack.map(l => isSegmentLabel(l) ? l.segmentId : l.name).join('/');
48
+ }
49
+ export function labelStackStartWith(labelStack, startWith) {
50
+ return stringifyLabelStackFully(labelStack).startsWith(stringifyLabelStackFully(startWith));
51
+ }
52
+ export function optimizeLabelStack(labelStack) {
53
+ return REACT_UFO_VERSION === '2.0.0' ? getLabelStackReference(labelStack) : labelStack.map(ls => ({
54
+ n: ls.name,
55
+ ...(ls.segmentId ? {
56
+ s: ls.segmentId
57
+ } : {})
58
+ }));
8
59
  }
@@ -11,7 +11,7 @@ import * as resourceTiming from '../resource-timing';
11
11
  import { roundEpsilon } from '../round-number';
12
12
  import * as ssr from '../ssr';
13
13
  import { getVCObserver } from '../vc';
14
- import { isSegmentLabel, sanitizeUfoName } from './common/utils';
14
+ import { buildSegmentTree, labelStackStartWith, optimizeLabelStack, sanitizeUfoName, stringifyLabelStackFully } from './common/utils';
15
15
  function getUfoNameOverride(interaction) {
16
16
  const {
17
17
  ufoName,
@@ -31,17 +31,6 @@ function getUfoNameOverride(interaction) {
31
31
  return ufoName;
32
32
  }
33
33
  }
34
- function stringifyLabelStackFully(labelStack) {
35
- return labelStack.map(l => {
36
- if (isSegmentLabel(l)) {
37
- return `${l.name}:${l.segmentId}`;
38
- }
39
- return l.name;
40
- }).join('/');
41
- }
42
- function labelStackStartWith(labelStack, startWith) {
43
- return stringifyLabelStackFully(labelStack).startsWith(stringifyLabelStackFully(startWith));
44
- }
45
34
  function getEarliestLegacyStopTime(interaction, labelStack) {
46
35
  let earliestLegacyStopTime = null;
47
36
  interaction.apdex.forEach(a => {
@@ -329,17 +318,6 @@ const getTracingContextData = interaction => {
329
318
  }
330
319
  return tracingContextData;
331
320
  };
332
-
333
- // interaction metric
334
-
335
- function optimizeLabelStack(labelStack) {
336
- return labelStack.map(ls => ({
337
- n: ls.name,
338
- ...(ls.segmentId ? {
339
- s: ls.segmentId
340
- } : {})
341
- }));
342
- }
343
321
  function optimizeCustomData(interaction) {
344
322
  const {
345
323
  customData,
@@ -520,7 +498,7 @@ function optimizeRequestInfo(requestInfo, interactionStart) {
520
498
  return updatedRequestInfo;
521
499
  }
522
500
  function optimizeCustomTimings(customTimings, interactionStart) {
523
- const updatedCustomTimings = customTimings.reduce((result, item) => {
501
+ return customTimings.reduce((result, item) => {
524
502
  Object.keys(item.data).forEach(key => {
525
503
  if (item.data[key].startTime >= interactionStart) {
526
504
  result.push({
@@ -534,7 +512,6 @@ function optimizeCustomTimings(customTimings, interactionStart) {
534
512
  });
535
513
  return result;
536
514
  }, []);
537
- return updatedCustomTimings;
538
515
  }
539
516
  function optimizeMarks(marks) {
540
517
  return marks.map(({
@@ -560,8 +537,6 @@ function optimizeApdex(apdex) {
560
537
  } : {})
561
538
  }));
562
539
  }
563
-
564
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
565
540
  function objectToArray(obj = {}) {
566
541
  return Object.keys(obj).reduce((result, key) => {
567
542
  result.push({
@@ -569,9 +544,7 @@ function objectToArray(obj = {}) {
569
544
  data: obj[key]
570
545
  });
571
546
  return result;
572
- },
573
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
574
- []);
547
+ }, []);
575
548
  }
576
549
  function getBM3SubmetricsTimings(submetrics) {
577
550
  if (!submetrics) {
@@ -650,6 +623,7 @@ function createInteractionMetricsPayload(interaction, interactionId) {
650
623
  const pageVisibilityAtTTI = getPageVisibilityUpToTTI(interaction);
651
624
  const pageVisibilityAtTTAI = getPageVisibilityUpToTTAI(interaction);
652
625
  const segments = config.killswitchNestedSegments ? [] : knownSegments;
626
+ const segmentTree = buildSegmentTree(segments.map(segment => segment.labelStack));
653
627
  const isDetailedPayload = pageVisibilityAtTTAI === 'visible';
654
628
  const isPageLoad = type === 'page_load';
655
629
  const calculatePageVisibilityFromTheStartOfPageLoad = config.enableBetterPageVisibilityApi && isPageLoad;
@@ -764,7 +738,7 @@ function createInteractionMetricsPayload(interaction, interactionId) {
764
738
  apdex: optimizeApdex(interaction.apdex),
765
739
  end: Math.round(end),
766
740
  start: Math.round(start),
767
- segments: segments.map(({
741
+ segments: REACT_UFO_VERSION === '2.0.0' ? segmentTree : segments.map(({
768
742
  labelStack,
769
743
  ...others
770
744
  }) => ({
@@ -1,8 +1,7 @@
1
1
  import { VCObserver } from './vc-observer';
2
- let instance = null;
3
2
  export const getVCObserver = (opts = {}) => {
4
- if (instance === null) {
5
- instance = new VCObserver(opts);
3
+ if (!globalThis.__vcObserver) {
4
+ globalThis.__vcObserver = new VCObserver(opts);
6
5
  }
7
- return instance;
6
+ return globalThis.__vcObserver;
8
7
  };
@@ -441,6 +441,9 @@ export class VCObserver {
441
441
  setReactRootRenderStop(stopTime = performance.now()) {
442
442
  this.observers.setReactRootRenderStop(stopTime);
443
443
  }
444
+ abortObservation(abortReason = 'custom') {
445
+ this.setAbortReason(abortReason, performance.now());
446
+ }
444
447
  setAbortReason(abort, timestamp, info = '') {
445
448
  if (this.abortReason.reason === null || this.abortReason.blocking === false) {
446
449
  this.abortReason.reason = abort;
@@ -1 +1,2 @@
1
- export var REACT_UFO_VERSION = '1.0.1';
1
+ import { fg } from '@atlaskit/platform-feature-flags';
2
+ export var REACT_UFO_VERSION = fg('react-ufo-payload-segment-compressed') ? '2.0.0' : '1.0.1';
@@ -1,8 +1,63 @@
1
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
+ 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; }
3
+ 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) { _defineProperty(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; }
4
+ /* eslint-disable @typescript-eslint/no-non-null-asserted-optional-chain */
5
+ import { REACT_UFO_VERSION } from '../../../common/constants';
1
6
  export var sanitizeUfoName = function sanitizeUfoName(name) {
2
7
  return name.replace(/_/g, '-');
3
8
  };
4
-
5
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
6
9
  export function isSegmentLabel(obj) {
7
10
  return obj && typeof obj.name === 'string' && typeof obj.segmentId === 'string';
11
+ }
12
+ export function buildSegmentTree(labelStacks) {
13
+ var r = {
14
+ n: 'segment-tree-root',
15
+ c: {}
16
+ };
17
+ labelStacks.forEach(function (labelStack) {
18
+ var currentNode = r;
19
+ labelStack.forEach(function (label, index) {
20
+ var _currentNode$c;
21
+ var name = label.name;
22
+ var id = isSegmentLabel(label) ? label.segmentId : undefined;
23
+ var key = id !== undefined ? id.toString() : name;
24
+ if (currentNode.c && !currentNode.c[key]) {
25
+ currentNode.c[key] = {
26
+ n: name
27
+ };
28
+ }
29
+ currentNode = (_currentNode$c = currentNode.c) === null || _currentNode$c === void 0 ? void 0 : _currentNode$c[key];
30
+ if (index < labelStack.length - 1) {
31
+ currentNode.c = _objectSpread({}, currentNode.c || {});
32
+ }
33
+ });
34
+ });
35
+ return {
36
+ r: r
37
+ };
38
+ }
39
+ export function stringifyLabelStackFully(labelStack) {
40
+ return labelStack.map(function (l) {
41
+ if (isSegmentLabel(l)) {
42
+ return "".concat(l.name, ":").concat(l.segmentId);
43
+ }
44
+ return l.name;
45
+ }).join('/');
46
+ }
47
+ function getLabelStackReference(labelStack) {
48
+ return labelStack.map(function (l) {
49
+ return isSegmentLabel(l) ? l.segmentId : l.name;
50
+ }).join('/');
51
+ }
52
+ export function labelStackStartWith(labelStack, startWith) {
53
+ return stringifyLabelStackFully(labelStack).startsWith(stringifyLabelStackFully(startWith));
54
+ }
55
+ export function optimizeLabelStack(labelStack) {
56
+ return REACT_UFO_VERSION === '2.0.0' ? getLabelStackReference(labelStack) : labelStack.map(function (ls) {
57
+ return _objectSpread({
58
+ n: ls.name
59
+ }, ls.segmentId ? {
60
+ s: ls.segmentId
61
+ } : {});
62
+ });
8
63
  }