@atlaskit/react-ufo 3.13.17 → 3.13.19

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 (42) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/dist/cjs/ssr/index.js +8 -2
  3. package/dist/cjs/vc/index.js +2 -0
  4. package/dist/cjs/vc/vc-observer/getVCRevisionDebugDetails.js +109 -11
  5. package/dist/cjs/vc/vc-observer/index.js +56 -43
  6. package/dist/cjs/vc/vc-observer/observers/index.js +4 -0
  7. package/dist/cjs/vc/vc-observer/observers/rll-placeholders/index.js +208 -0
  8. package/dist/cjs/vc/vc-observer-new/metric-calculator/abstract-base-vc-calculator.js +129 -16
  9. package/dist/cjs/vc/vc-observer-new/viewport-observer/index.js +16 -0
  10. package/dist/es2019/ssr/index.js +5 -1
  11. package/dist/es2019/vc/index.js +2 -0
  12. package/dist/es2019/vc/vc-observer/getVCRevisionDebugDetails.js +71 -9
  13. package/dist/es2019/vc/vc-observer/index.js +39 -22
  14. package/dist/es2019/vc/vc-observer/observers/index.js +4 -0
  15. package/dist/es2019/vc/vc-observer/observers/rll-placeholders/index.js +182 -0
  16. package/dist/es2019/vc/vc-observer-new/metric-calculator/abstract-base-vc-calculator.js +102 -11
  17. package/dist/es2019/vc/vc-observer-new/viewport-observer/index.js +16 -0
  18. package/dist/esm/ssr/index.js +8 -2
  19. package/dist/esm/vc/index.js +2 -0
  20. package/dist/esm/vc/vc-observer/getVCRevisionDebugDetails.js +108 -11
  21. package/dist/esm/vc/vc-observer/index.js +56 -43
  22. package/dist/esm/vc/vc-observer/observers/index.js +4 -0
  23. package/dist/esm/vc/vc-observer/observers/rll-placeholders/index.js +201 -0
  24. package/dist/esm/vc/vc-observer-new/metric-calculator/abstract-base-vc-calculator.js +130 -16
  25. package/dist/esm/vc/vc-observer-new/viewport-observer/index.js +16 -0
  26. package/dist/types/common/vc/types.d.ts +1 -1
  27. package/dist/types/ssr/index.d.ts +1 -0
  28. package/dist/types/vc/index.d.ts +1 -0
  29. package/dist/types/vc/vc-observer/getVCRevisionDebugDetails.d.ts +19 -18
  30. package/dist/types/vc/vc-observer/index.d.ts +7 -0
  31. package/dist/types/vc/vc-observer/observers/rll-placeholders/index.d.ts +49 -0
  32. package/dist/types/vc/vc-observer-new/metric-calculator/abstract-base-vc-calculator.d.ts +7 -0
  33. package/dist/types/vc/vc-observer-new/types.d.ts +1 -1
  34. package/dist/types-ts4.5/common/vc/types.d.ts +1 -1
  35. package/dist/types-ts4.5/ssr/index.d.ts +1 -0
  36. package/dist/types-ts4.5/vc/index.d.ts +1 -0
  37. package/dist/types-ts4.5/vc/vc-observer/getVCRevisionDebugDetails.d.ts +19 -18
  38. package/dist/types-ts4.5/vc/vc-observer/index.d.ts +7 -0
  39. package/dist/types-ts4.5/vc/vc-observer/observers/rll-placeholders/index.d.ts +49 -0
  40. package/dist/types-ts4.5/vc/vc-observer-new/metric-calculator/abstract-base-vc-calculator.d.ts +7 -0
  41. package/dist/types-ts4.5/vc/vc-observer-new/types.d.ts +1 -1
  42. package/package.json +10 -1
@@ -9,6 +9,7 @@ var _excluded = ["__debug__element"];
9
9
  import _regeneratorRuntime from "@babel/runtime/regenerator";
10
10
  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; }
11
11
  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; }
12
+ import { fg } from '@atlaskit/platform-feature-flags';
12
13
  import { isVCRevisionEnabled } from '../../config';
13
14
  import { getActiveInteraction } from '../../interaction-metrics';
14
15
  import { attachAbortListeners } from './attachAbortListeners';
@@ -95,7 +96,7 @@ export var VCObserver = /*#__PURE__*/function () {
95
96
  });
96
97
  _defineProperty(this, "getVCResult", /*#__PURE__*/function () {
97
98
  var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(_ref3) {
98
- var start, stop, tti, prefix, ssr, vc, isEventAborted, experienceKey, interactionId, includeSSRRatio, startTime, fullPrefix, rawData, abortReason, abortReasonInfo, heatmap, heatmapNext, outOfBoundaryInfo, totalTime, componentsLog, viewport, devToolsEnabled, ratios, isTTVCv1Disabled, vcAbortedResultWithRevisions, ttvcV1Result, VC, VCBox, VCEntries, totalPainted, _componentsLog, vcNext, outOfBoundary, stopTime, ttvcV1DevToolInfo, ttvcV2DevToolInfo, _ufo_devtool_onVCRev2, _ref9, _ufo_devtool_onVCRev, _ref8, isVCClean, revisionsData, speedIndex, SSRRatio, SSRRatioNext, SSRRatioPayload, isTTVCv3Enabled;
99
+ var start, stop, tti, prefix, ssr, vc, isEventAborted, experienceKey, interactionId, includeSSRRatio, startTime, fullPrefix, rawData, abortReason, abortReasonInfo, heatmap, heatmapNext, outOfBoundaryInfo, totalTime, componentsLog, viewport, devToolsEnabled, ratios, isTTVCv1Disabled, vcAbortedResultWithRevisions, ttvcV1Result, VC, VCBox, VCEntries, totalPainted, _componentsLog, vcNext, outOfBoundary, stopTime, ttvcV1DevToolInfo, ttvcV2DevToolInfo, shouldCreateDebugDetails, v1RevisionDebugDetails, v2RevisionDebugDetails, _window$__ufo_devtool2, _window2, _window$__ufo_devtool, _window, _window$__on_ufo_vc_d2, _window4, _window$__on_ufo_vc_d, _window3, isVCClean, revisionsData, speedIndex, SSRRatio, SSRRatioNext, SSRRatioPayload, isTTVCv3Enabled;
99
100
  return _regeneratorRuntime.wrap(function _callee$(_context) {
100
101
  while (1) switch (_context.prev = _context.next) {
101
102
  case 0:
@@ -264,30 +265,42 @@ export var VCObserver = /*#__PURE__*/function () {
264
265
  entries: isTTVCv1Disabled ? vcNext.VCEntries.rel : VCEntries.rel
265
266
  }
266
267
  }));
267
-
268
- // Add devtool callback for both v1 and v2
269
- if (typeof window.__ufo_devtool_onVCRevisionReady__ === 'function') {
270
- // Handle v1 if not disabled
271
- if (!isTTVCv1Disabled) {
272
- (_ufo_devtool_onVCRev = (_ref8 = window).__ufo_devtool_onVCRevisionReady__) === null || _ufo_devtool_onVCRev === void 0 || _ufo_devtool_onVCRev.call(_ref8, getVCRevisionDebugDetails({
273
- revision: 'fy25.01',
274
- isClean: !abortReasonInfo,
275
- abortReason: abortReason.reason,
276
- VCEntries: VCEntries.rel,
277
- componentsLog: componentsLog,
278
- interactionId: interactionId
279
- }));
280
- }
281
-
282
- // Handle v2
283
- (_ufo_devtool_onVCRev2 = (_ref9 = window).__ufo_devtool_onVCRevisionReady__) === null || _ufo_devtool_onVCRev2 === void 0 || _ufo_devtool_onVCRev2.call(_ref9, getVCRevisionDebugDetails({
268
+ }
269
+ if (!_this.isPostInteraction) {
270
+ // Only create revision debug details if callbacks exist
271
+ shouldCreateDebugDetails = typeof window.__ufo_devtool_onVCRevisionReady__ === 'function' || typeof window.__on_ufo_vc_debug_data_ready === 'function' && fg('platform_ufo_emit_vc_debug_data');
272
+ if (shouldCreateDebugDetails) {
273
+ v1RevisionDebugDetails = getVCRevisionDebugDetails({
274
+ revision: 'fy25.01',
275
+ isClean: !abortReasonInfo,
276
+ abortReason: abortReason.reason,
277
+ VCEntries: VCEntries.rel,
278
+ componentsLog: componentsLog,
279
+ interactionId: interactionId
280
+ });
281
+ v2RevisionDebugDetails = getVCRevisionDebugDetails({
284
282
  revision: 'fy25.02',
285
283
  isClean: !abortReasonInfo,
286
284
  abortReason: abortReason.reason,
287
285
  VCEntries: vcNext.VCEntries.rel,
288
286
  componentsLog: componentsLog,
289
287
  interactionId: interactionId
290
- }));
288
+ }); // Add devtool callback for both v1 and v2
289
+ if (typeof window.__ufo_devtool_onVCRevisionReady__ === 'function') {
290
+ // Handle v1 if not disabled
291
+ if (!isTTVCv1Disabled) {
292
+ (_window$__ufo_devtool = (_window = window).__ufo_devtool_onVCRevisionReady__) === null || _window$__ufo_devtool === void 0 || _window$__ufo_devtool.call(_window, v1RevisionDebugDetails);
293
+ }
294
+
295
+ // Handle v2
296
+ (_window$__ufo_devtool2 = (_window2 = window).__ufo_devtool_onVCRevisionReady__) === null || _window$__ufo_devtool2 === void 0 || _window$__ufo_devtool2.call(_window2, v2RevisionDebugDetails);
297
+ }
298
+ if (typeof window.__on_ufo_vc_debug_data_ready === 'function' && fg('platform_ufo_emit_vc_debug_data')) {
299
+ if (!isTTVCv1Disabled) {
300
+ (_window$__on_ufo_vc_d = (_window3 = window).__on_ufo_vc_debug_data_ready) === null || _window$__on_ufo_vc_d === void 0 || _window$__on_ufo_vc_d.call(_window3, v1RevisionDebugDetails);
301
+ }
302
+ (_window$__on_ufo_vc_d2 = (_window4 = window).__on_ufo_vc_debug_data_ready) === null || _window$__on_ufo_vc_d2 === void 0 || _window$__on_ufo_vc_d2.call(_window4, v2RevisionDebugDetails);
303
+ }
291
304
  }
292
305
  }
293
306
  } catch (e) {
@@ -416,14 +429,14 @@ export var VCObserver = /*#__PURE__*/function () {
416
429
  }
417
430
  });
418
431
  _defineProperty(this, "attachAbortListeners", function () {
419
- var _window;
432
+ var _window5;
420
433
  _this.detachAbortListeners();
421
434
  var unbinds = attachAbortListeners(window, _this.viewport, _this.abortReasonCallback);
422
- if ((_window = window) !== null && _window !== void 0 && _window.__SSR_ABORT_LISTENERS__) {
423
- Object.entries(window.__SSR_ABORT_LISTENERS__.aborts).forEach(function (_ref1) {
424
- var _ref10 = _slicedToArray(_ref1, 2),
425
- key = _ref10[0],
426
- time = _ref10[1];
435
+ if ((_window5 = window) !== null && _window5 !== void 0 && _window5.__SSR_ABORT_LISTENERS__) {
436
+ Object.entries(window.__SSR_ABORT_LISTENERS__.aborts).forEach(function (_ref9) {
437
+ var _ref0 = _slicedToArray(_ref9, 2),
438
+ key = _ref0[0],
439
+ time = _ref0[1];
427
440
  if (time) {
428
441
  _this.abortReasonCallback(key, time);
429
442
  }
@@ -453,8 +466,8 @@ export var VCObserver = /*#__PURE__*/function () {
453
466
  }
454
467
  return _createClass(VCObserver, [{
455
468
  key: "start",
456
- value: function start(_ref11) {
457
- var startTime = _ref11.startTime;
469
+ value: function start(_ref1) {
470
+ var startTime = _ref1.startTime;
458
471
  this.active = true;
459
472
  if (this.observers.isBrowserSupported()) {
460
473
  this.setViewportSize();
@@ -476,12 +489,12 @@ export var VCObserver = /*#__PURE__*/function () {
476
489
  }, {
477
490
  key: "getIgnoredElements",
478
491
  value: function getIgnoredElements(componentsLog) {
479
- return Object.values(componentsLog).flat().filter(function (_ref12) {
480
- var ignoreReason = _ref12.ignoreReason;
492
+ return Object.values(componentsLog).flat().filter(function (_ref10) {
493
+ var ignoreReason = _ref10.ignoreReason;
481
494
  return Boolean(ignoreReason);
482
- }).map(function (_ref13) {
483
- var targetName = _ref13.targetName,
484
- ignoreReason = _ref13.ignoreReason;
495
+ }).map(function (_ref11) {
496
+ var targetName = _ref11.targetName,
497
+ ignoreReason = _ref11.ignoreReason;
485
498
  return {
486
499
  targetName: targetName,
487
500
  ignoreReason: ignoreReason
@@ -611,13 +624,13 @@ export var VCObserver = /*#__PURE__*/function () {
611
624
  }
612
625
  }, {
613
626
  key: "calculateVC",
614
- value: function calculateVC(_ref14) {
615
- var heatmap = _ref14.heatmap,
616
- _ref14$ssr = _ref14.ssr,
617
- ssr = _ref14$ssr === void 0 ? UNUSED_SECTOR : _ref14$ssr,
618
- componentsLog = _ref14.componentsLog,
619
- viewport = _ref14.viewport,
620
- fixSSRAttribution = _ref14.fixSSRAttribution;
627
+ value: function calculateVC(_ref12) {
628
+ var heatmap = _ref12.heatmap,
629
+ _ref12$ssr = _ref12.ssr,
630
+ ssr = _ref12$ssr === void 0 ? UNUSED_SECTOR : _ref12$ssr,
631
+ componentsLog = _ref12.componentsLog,
632
+ viewport = _ref12.viewport,
633
+ fixSSRAttribution = _ref12.fixSSRAttribution;
621
634
  var lastUpdate = {};
622
635
  var totalPainted = 0;
623
636
  var ssrTime = fixSSRAttribution ? Math.floor(ssr) : ssr;
@@ -684,11 +697,11 @@ export var VCObserver = /*#__PURE__*/function () {
684
697
  });
685
698
  return VCRatio;
686
699
  }, 0);
687
- var VCEntries = entries.reduce(function (acc, _ref15, i) {
700
+ var VCEntries = entries.reduce(function (acc, _ref13, i) {
688
701
  var _acc$abs, _componentsLog$timest, _acc$rel$vc, _acc$rel;
689
- var _ref16 = _slicedToArray(_ref15, 2),
690
- timestamp = _ref16[0],
691
- entryPainted = _ref16[1];
702
+ var _ref14 = _slicedToArray(_ref13, 2),
703
+ timestamp = _ref14[0],
704
+ entryPainted = _ref14[1];
692
705
  var currentlyPainted = entryPainted + (((_acc$abs = acc.abs[i - 1]) === null || _acc$abs === void 0 ? void 0 : _acc$abs[1]) || 0);
693
706
  var currentlyPaintedRatio = Math.round(currentlyPainted / totalPainted * 1000) / 10;
694
707
  var logEntry = _toConsumableArray(new Set((_componentsLog$timest = componentsLog[timestamp]) === null || _componentsLog$timest === void 0 ? void 0 : _componentsLog$timest.filter(function (v) {
@@ -5,6 +5,7 @@ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbol
5
5
  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; }
6
6
  import { isContainedWithinMediaWrapper } from '../media-wrapper/vc-utils';
7
7
  import isNonVisualStyleMutation from './non-visual-styles/is-non-visual-style-mutation';
8
+ import { RLLPlaceholderHandlers } from './rll-placeholders';
8
9
  import { SSRPlaceholderHandlers } from './ssr-placeholders';
9
10
  var state = {
10
11
  normal: 1,
@@ -272,6 +273,9 @@ export var Observers = /*#__PURE__*/function () {
272
273
  if (!isElementVisible(target)) {
273
274
  data.ignoreReason = 'not-visible';
274
275
  }
276
+ if (RLLPlaceholderHandlers.getInstance().isRLLPlaceholderHydration(ir)) {
277
+ data.ignoreReason = 'rll-placeholder';
278
+ }
275
279
  _this3.callbacks.forEach(function (callback) {
276
280
  var elementName;
277
281
  try {
@@ -0,0 +1,201 @@
1
+ import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
2
+ import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
3
+ import _createClass from "@babel/runtime/helpers/createClass";
4
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
5
+ import { fg } from '@atlaskit/platform-feature-flags';
6
+ var GLOBAL_RLL_HANDLERS_KEY = '__REACT_UFO_RLL_PLACEHOLDER_HANDLERS__';
7
+ export var RLLPlaceholderHandlers = /*#__PURE__*/function () {
8
+ function RLLPlaceholderHandlers() {
9
+ _classCallCheck(this, RLLPlaceholderHandlers);
10
+ _defineProperty(this, "placeholders", []);
11
+ if (typeof window !== 'undefined' && typeof document !== 'undefined' && typeof window.document !== 'undefined') {
12
+ this.collectRLLPlaceholders();
13
+ }
14
+ }
15
+
16
+ /**
17
+ * Gets the global singleton instance of RLLPlaceholderHandlers.
18
+ * Creates the instance if it doesn't exist and stores it in globalThis.
19
+ * @returns The singleton instance of RLLPlaceholderHandlers
20
+ */
21
+ return _createClass(RLLPlaceholderHandlers, [{
22
+ key: "reset",
23
+ value: function reset() {
24
+ this.placeholders = [];
25
+ }
26
+
27
+ /**
28
+ * Collects all React Loosely Lazy (RLL) placeholders from the DOM and caches their viewport intersecting rectangles.
29
+ * RLL placeholders are marked with data-lazy-begin and data-lazy-end attributes on hidden input elements.
30
+ * Performance optimized to batch getBoundingClientRect calls and minimize layout thrashing.
31
+ * Only stores the intersecting portions of rectangles that are currently visible in the viewport.
32
+ */
33
+ }, {
34
+ key: "collectRLLPlaceholders",
35
+ value: function collectRLLPlaceholders() {
36
+ if (typeof window === 'undefined' || typeof document === 'undefined' || typeof window.document === 'undefined') {
37
+ return;
38
+ }
39
+ if (!fg('platform_ufo_rll_placeholder_ignore')) {
40
+ return;
41
+ }
42
+ var beginElements = document.querySelectorAll('input[data-lazy-begin]');
43
+ var beginCount = beginElements.length;
44
+ if (beginCount === 0) {
45
+ return;
46
+ }
47
+
48
+ // Performance optimization: pre-allocate array with estimated size
49
+ var allElements = [];
50
+
51
+ // Performance optimization: use traditional for loop instead of forEach
52
+ for (var i = 0; i < beginCount; i++) {
53
+ var beginEl = beginElements[i];
54
+ var id = beginEl.getAttribute('data-lazy-begin');
55
+ if (!id) {
56
+ continue;
57
+ }
58
+ var elements = this.refElements(beginEl, id);
59
+ if (elements.length > 0) {
60
+ allElements.push.apply(allElements, _toConsumableArray(elements));
61
+ }
62
+ }
63
+
64
+ // Second pass: batch all getBoundingClientRect calls to minimize reflow cycles
65
+ var allElementsLength = allElements.length;
66
+ if (allElementsLength > 0) {
67
+ // Performance optimization: pre-allocate array with exact size
68
+ var intersectingRects = [];
69
+ var windowWidth = window.innerWidth;
70
+ var windowHeight = window.innerHeight;
71
+ for (var _i = 0; _i < allElementsLength; _i++) {
72
+ var rect = allElements[_i].getBoundingClientRect();
73
+
74
+ // Performance optimization: inline intersection calculation to avoid function call overhead
75
+ var left = Math.max(rect.left, 0);
76
+ var top = Math.max(rect.top, 0);
77
+ var right = Math.min(rect.right, windowWidth);
78
+ var bottom = Math.min(rect.bottom, windowHeight);
79
+
80
+ // Check if there's a valid intersection with non-zero width and height
81
+ if (left < right && top < bottom) {
82
+ intersectingRects.push(new DOMRect(left, top, right - left, bottom - top));
83
+ }
84
+ }
85
+ this.placeholders = intersectingRects;
86
+ }
87
+ }
88
+
89
+ /**
90
+ * Traverses DOM siblings to find all elements between RLL begin and end markers.
91
+ * Based on the refElements pattern from react-loosely-lazy's platform/packages/async/react-loosely-lazy/src/collect/hydrate.ts
92
+ * Performance optimized to minimize iterations and early exit conditions.
93
+ *
94
+ * @param fromEl - The input element with data-lazy-begin attribute
95
+ * @param id - The placeholder ID to match against data-lazy-end
96
+ * @returns Array of DOM elements between the begin/end markers
97
+ */
98
+ }, {
99
+ key: "refElements",
100
+ value: function refElements(fromEl, id) {
101
+ var result = [];
102
+ var el = fromEl.nextSibling;
103
+
104
+ // Performance optimization: use while loop instead of recursive calls
105
+ while (el) {
106
+ var _el$dataset;
107
+ if (((_el$dataset = el.dataset) === null || _el$dataset === void 0 ? void 0 : _el$dataset.lazyEnd) === id) {
108
+ break;
109
+ }
110
+ if (el.nodeType === Node.ELEMENT_NODE) {
111
+ result.push(el);
112
+ }
113
+ el = el.nextSibling;
114
+ }
115
+ return result;
116
+ }
117
+
118
+ /**
119
+ * Returns the cached intersecting viewport rectangles for all RLL placeholder elements.
120
+ * @returns Array of DOMRect objects representing the intersecting portions of placeholders within the viewport
121
+ */
122
+ }, {
123
+ key: "getPlaceholders",
124
+ value: function getPlaceholders() {
125
+ return this.placeholders;
126
+ }
127
+
128
+ /**
129
+ * Checks if the given intersecting rectangle matches any of the cached RLL placeholder intersecting rectangles.
130
+ * This is designed to be called from IntersectionObserver with the intersectionRect.
131
+ * Performance optimized with early exits and minimal calculations.
132
+ * @param intersectingRect - The intersecting rectangle from IntersectionObserver
133
+ * @returns true if the intersecting rectangle matches a cached placeholder rectangle and hasn't exceeded match limit, false otherwise
134
+ */
135
+ }, {
136
+ key: "isRLLPlaceholderHydration",
137
+ value: function isRLLPlaceholderHydration(intersectingRect) {
138
+ var placeholdersLength = this.placeholders.length;
139
+ if (placeholdersLength === 0) {
140
+ return false;
141
+ }
142
+
143
+ // Performance optimization: cache array length and use traditional for loop
144
+ for (var i = 0; i < placeholdersLength; i++) {
145
+ var placeholderRect = this.placeholders[i];
146
+ if (this.areRectsEqual(intersectingRect, placeholderRect)) {
147
+ return true;
148
+ }
149
+ }
150
+ return false;
151
+ }
152
+
153
+ /**
154
+ * Compares two DOMRect objects for equality with ±1 pixel tolerance.
155
+ * Performance optimized to minimize calculations and early exit on major differences.
156
+ * @param rect1 - First rectangle to compare
157
+ * @param rect2 - Second rectangle to compare
158
+ * @returns true if rectangles are within 1 pixel tolerance for all properties
159
+ */
160
+ }, {
161
+ key: "areRectsEqual",
162
+ value: function areRectsEqual(rect1, rect2) {
163
+ // Early exit for exact matches (most common case)
164
+ if (rect1.left === rect2.left && rect1.top === rect2.top && rect1.right === rect2.right && rect1.bottom === rect2.bottom) {
165
+ return true;
166
+ }
167
+
168
+ // Performance optimization: check largest differences first for early exit
169
+ var leftDiff = rect1.left - rect2.left;
170
+ if (leftDiff > 1 || leftDiff < -1) {
171
+ return false;
172
+ }
173
+ var rightDiff = rect1.right - rect2.right;
174
+ if (rightDiff > 1 || rightDiff < -1) {
175
+ return false;
176
+ }
177
+ var topDiff = rect1.top - rect2.top;
178
+ if (topDiff > 1 || topDiff < -1) {
179
+ return false;
180
+ }
181
+ var bottomDiff = rect1.bottom - rect2.bottom;
182
+ if (bottomDiff > 1 || bottomDiff < -1) {
183
+ return false;
184
+ }
185
+ return true;
186
+ }
187
+ }], [{
188
+ key: "getInstance",
189
+ value: function getInstance() {
190
+ if (typeof globalThis !== 'undefined') {
191
+ if (!globalThis[GLOBAL_RLL_HANDLERS_KEY]) {
192
+ globalThis[GLOBAL_RLL_HANDLERS_KEY] = new RLLPlaceholderHandlers();
193
+ }
194
+ return globalThis[GLOBAL_RLL_HANDLERS_KEY];
195
+ }
196
+
197
+ // Fallback for environments without globalThis (should be rare)
198
+ return new RLLPlaceholderHandlers();
199
+ }
200
+ }]);
201
+ }();
@@ -1,8 +1,12 @@
1
+ import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
2
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
1
3
  import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
2
4
  import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
3
5
  import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
4
6
  import _createClass from "@babel/runtime/helpers/createClass";
5
7
  import _regeneratorRuntime from "@babel/runtime/regenerator";
8
+ 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; }
9
+ 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; }
6
10
  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; } } }; }
7
11
  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; } }
8
12
  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; }
@@ -10,6 +14,8 @@ import { fg } from '@atlaskit/platform-feature-flags';
10
14
  import { calculateTTVCPercentilesWithDebugInfo } from './percentile-calc';
11
15
  import getViewportHeight from './utils/get-viewport-height';
12
16
  import getViewportWidth from './utils/get-viewport-width';
17
+
18
+ // Create comprehensive debug details including ignored entries
13
19
  var AbstractVCCalculatorBase = /*#__PURE__*/function () {
14
20
  function AbstractVCCalculatorBase(revisionNo) {
15
21
  _classCallCheck(this, AbstractVCCalculatorBase);
@@ -72,8 +78,9 @@ var AbstractVCCalculatorBase = /*#__PURE__*/function () {
72
78
  }, {
73
79
  key: "calculateWithDebugInfo",
74
80
  value: function () {
75
- var _calculateWithDebugInfo = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(filteredEntries, startTime, stopTime, isPostInteraction, isVCClean, interactionId, dirtyReason) {
76
- var percentiles, viewportEntries, vcLogs, vcDetails, percentileIndex, entryDataBuffer, _iterator3, _step3, _entry2, time, viewportPercentage, entries, elementNames, previousResult, i, percentile, _ufo_devtool_onVCRev, _ref;
81
+ var _calculateWithDebugInfo = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(filteredEntries, startTime, stopTime, isPostInteraction, isVCClean, interactionId, dirtyReason, allEntries) {
82
+ var _window, _window2, _window3, _window5;
83
+ var percentiles, viewportEntries, vcLogs, vcDetails, percentileIndex, entryDataBuffer, _iterator3, _step3, _entry2, time, viewportPercentage, entries, elementNames, previousResult, i, percentile, enhancedVcLogs, shouldCalculateDebugDetails, sortedVcLogs, maxViewportPercentageAtTime, maxSoFar, _iterator4, _step4, log, getBiggestPreviousViewportPercentage, ignoredEntriesByTime, _iterator5, _step5, _entry3, _ignoredEntriesByTime, viewportData, timestamp, additionalVcLogs, _iterator6, _step6, _step6$value, _timestamp, ignoredEntries, _viewportPercentage, v3RevisionDebugDetails, _window4, _window4$__ufo_devtoo, _window6, _window6$__on_ufo_vc_;
77
84
  return _regeneratorRuntime.wrap(function _callee$(_context) {
78
85
  while (1) switch (_context.prev = _context.next) {
79
86
  case 0:
@@ -163,31 +170,138 @@ var AbstractVCCalculatorBase = /*#__PURE__*/function () {
163
170
  previousResult = vcDetails["".concat(percentile)];
164
171
  }
165
172
  }
173
+ enhancedVcLogs = vcLogs ? vcLogs.map(function (log) {
174
+ return _objectSpread(_objectSpread({}, log), {}, {
175
+ viewportPercentage: log.viewportPercentage
176
+ });
177
+ }) : []; // Only calculate enhanced debug details if devtool callbacks exist
178
+ shouldCalculateDebugDetails = !isPostInteraction && (typeof ((_window = window) === null || _window === void 0 ? void 0 : _window.__ufo_devtool_onVCRevisionReady__) === 'function' || typeof ((_window2 = window) === null || _window2 === void 0 ? void 0 : _window2.__on_ufo_vc_debug_data_ready) === 'function' && fg('platform_ufo_emit_vc_debug_data'));
179
+ if (shouldCalculateDebugDetails && allEntries && vcLogs) {
180
+ // Pre-sort vcLogs by time for efficient lookups
181
+ sortedVcLogs = _toConsumableArray(vcLogs).sort(function (a, b) {
182
+ return a.time - b.time;
183
+ }); // Pre-calculate max viewport percentage up to each time for efficient lookups
184
+ maxViewportPercentageAtTime = new Map();
185
+ maxSoFar = 0;
186
+ _iterator4 = _createForOfIteratorHelper(sortedVcLogs);
187
+ try {
188
+ for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
189
+ log = _step4.value;
190
+ if (log.viewportPercentage !== null) {
191
+ maxSoFar = Math.max(maxSoFar, log.viewportPercentage);
192
+ maxViewportPercentageAtTime.set(log.time, maxSoFar);
193
+ }
194
+ }
195
+
196
+ // Helper function to find the biggest previous viewport percentage
197
+ } catch (err) {
198
+ _iterator4.e(err);
199
+ } finally {
200
+ _iterator4.f();
201
+ }
202
+ getBiggestPreviousViewportPercentage = function getBiggestPreviousViewportPercentage(targetTime) {
203
+ // Binary search for the largest time <= targetTime
204
+ var left = 0;
205
+ var right = sortedVcLogs.length - 1;
206
+ var result = -1;
207
+ while (left <= right) {
208
+ var mid = Math.floor((left + right) / 2);
209
+ if (sortedVcLogs[mid].time <= targetTime) {
210
+ result = mid;
211
+ left = mid + 1;
212
+ } else {
213
+ right = mid - 1;
214
+ }
215
+ }
216
+ return result >= 0 ? maxViewportPercentageAtTime.get(sortedVcLogs[result].time) || null : null;
217
+ }; // Group ignored entries by timestamp
218
+ ignoredEntriesByTime = new Map();
219
+ _iterator5 = _createForOfIteratorHelper(allEntries);
220
+ try {
221
+ for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
222
+ _entry3 = _step5.value;
223
+ if ('rect' in _entry3.data && !this.isEntryIncluded(_entry3)) {
224
+ viewportData = _entry3.data;
225
+ timestamp = Math.round(_entry3.time);
226
+ if (!ignoredEntriesByTime.has(timestamp)) {
227
+ ignoredEntriesByTime.set(timestamp, []);
228
+ }
229
+ (_ignoredEntriesByTime = ignoredEntriesByTime.get(timestamp)) === null || _ignoredEntriesByTime === void 0 || _ignoredEntriesByTime.push(_objectSpread(_objectSpread({}, viewportData), {}, {
230
+ ignoreReason: viewportData.visible ? viewportData.type : 'not-visible'
231
+ }));
232
+ }
233
+ }
234
+
235
+ // Add ignored entries to vcLogs
236
+ } catch (err) {
237
+ _iterator5.e(err);
238
+ } finally {
239
+ _iterator5.f();
240
+ }
241
+ additionalVcLogs = [];
242
+ _iterator6 = _createForOfIteratorHelper(ignoredEntriesByTime);
243
+ try {
244
+ for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
245
+ _step6$value = _slicedToArray(_step6.value, 2), _timestamp = _step6$value[0], ignoredEntries = _step6$value[1];
246
+ if (ignoredEntries.length > 0) {
247
+ _viewportPercentage = getBiggestPreviousViewportPercentage(_timestamp);
248
+ additionalVcLogs.push({
249
+ time: _timestamp,
250
+ viewportPercentage: _viewportPercentage,
251
+ entries: ignoredEntries
252
+ });
253
+ }
254
+ }
255
+
256
+ // Combine and sort all vcLogs
257
+ } catch (err) {
258
+ _iterator6.e(err);
259
+ } finally {
260
+ _iterator6.f();
261
+ }
262
+ enhancedVcLogs = [].concat(_toConsumableArray(enhancedVcLogs), additionalVcLogs).sort(function (a, b) {
263
+ return a.time - b.time;
264
+ });
265
+ }
266
+
267
+ // Only create debug details if callbacks exist
268
+ v3RevisionDebugDetails = null;
269
+ if (shouldCalculateDebugDetails) {
270
+ v3RevisionDebugDetails = {
271
+ revision: this.revisionNo,
272
+ isClean: isVCClean,
273
+ abortReason: dirtyReason,
274
+ vcLogs: enhancedVcLogs,
275
+ interactionId: interactionId
276
+ };
277
+ }
166
278
 
167
279
  // Handle devtool callback
168
- if (!isPostInteraction && typeof window !== 'undefined' && typeof window.__ufo_devtool_onVCRevisionReady__ === 'function') {
280
+ if (v3RevisionDebugDetails && typeof ((_window3 = window) === null || _window3 === void 0 ? void 0 : _window3.__ufo_devtool_onVCRevisionReady__) === 'function') {
169
281
  try {
170
- (_ufo_devtool_onVCRev = (_ref = window).__ufo_devtool_onVCRevisionReady__) === null || _ufo_devtool_onVCRev === void 0 || _ufo_devtool_onVCRev.call(_ref, {
171
- revision: this.revisionNo,
172
- isClean: isVCClean,
173
- abortReason: dirtyReason,
174
- vcLogs: vcLogs,
175
- interactionId: interactionId
176
- });
282
+ (_window4 = window) === null || _window4 === void 0 || (_window4$__ufo_devtoo = _window4.__ufo_devtool_onVCRevisionReady__) === null || _window4$__ufo_devtoo === void 0 || _window4$__ufo_devtoo.call(_window4, v3RevisionDebugDetails);
177
283
  } catch (e) {
178
284
  // if any error communicating with devtool, we don't want to break the app
179
285
  // eslint-disable-next-line no-console
180
286
  console.error('Error in onVCRevisionReady', e);
181
287
  }
182
288
  }
289
+ if (v3RevisionDebugDetails && typeof ((_window5 = window) === null || _window5 === void 0 ? void 0 : _window5.__on_ufo_vc_debug_data_ready) === 'function' && fg('platform_ufo_emit_vc_debug_data')) {
290
+ try {
291
+ (_window6 = window) === null || _window6 === void 0 || (_window6$__on_ufo_vc_ = _window6.__on_ufo_vc_debug_data_ready) === null || _window6$__on_ufo_vc_ === void 0 || _window6$__on_ufo_vc_.call(_window6, v3RevisionDebugDetails);
292
+ } catch (e) {
293
+ // eslint-disable-next-line no-console
294
+ console.error('Error in onVCRevisionReady', e);
295
+ }
296
+ }
183
297
  return _context.abrupt("return", vcDetails);
184
- case 32:
298
+ case 38:
185
299
  case "end":
186
300
  return _context.stop();
187
301
  }
188
302
  }, _callee, this, [[10, 22, 25, 28]]);
189
303
  }));
190
- function calculateWithDebugInfo(_x, _x2, _x3, _x4, _x5, _x6, _x7) {
304
+ function calculateWithDebugInfo(_x, _x2, _x3, _x4, _x5, _x6, _x7, _x8) {
191
305
  return _calculateWithDebugInfo.apply(this, arguments);
192
306
  }
193
307
  return calculateWithDebugInfo;
@@ -195,7 +309,7 @@ var AbstractVCCalculatorBase = /*#__PURE__*/function () {
195
309
  }, {
196
310
  key: "calculate",
197
311
  value: function () {
198
- var _calculate = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(_ref2) {
312
+ var _calculate = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(_ref) {
199
313
  var _this = this,
200
314
  _vcDetails$90$t,
201
315
  _vcDetails$;
@@ -203,7 +317,7 @@ var AbstractVCCalculatorBase = /*#__PURE__*/function () {
203
317
  return _regeneratorRuntime.wrap(function _callee2$(_context2) {
204
318
  while (1) switch (_context2.prev = _context2.next) {
205
319
  case 0:
206
- startTime = _ref2.startTime, stopTime = _ref2.stopTime, orderedEntries = _ref2.orderedEntries, interactionId = _ref2.interactionId, isPostInteraction = _ref2.isPostInteraction;
320
+ startTime = _ref.startTime, stopTime = _ref.stopTime, orderedEntries = _ref.orderedEntries, interactionId = _ref.interactionId, isPostInteraction = _ref.isPostInteraction;
207
321
  filteredEntries = orderedEntries.filter(function (entry) {
208
322
  return _this.isEntryIncluded(entry);
209
323
  });
@@ -222,7 +336,7 @@ var AbstractVCCalculatorBase = /*#__PURE__*/function () {
222
336
  });
223
337
  case 7:
224
338
  _context2.next = 9;
225
- return this.calculateWithDebugInfo(filteredEntries, startTime, stopTime, isPostInteraction, isVCClean, interactionId, dirtyReason);
339
+ return this.calculateWithDebugInfo(filteredEntries, startTime, stopTime, isPostInteraction, isVCClean, interactionId, dirtyReason, orderedEntries);
226
340
  case 9:
227
341
  vcDetails = _context2.sent;
228
342
  result = {
@@ -241,7 +355,7 @@ var AbstractVCCalculatorBase = /*#__PURE__*/function () {
241
355
  }
242
356
  }, _callee2, this);
243
357
  }));
244
- function calculate(_x8) {
358
+ function calculate(_x9) {
245
359
  return _calculate.apply(this, arguments);
246
360
  }
247
361
  return calculate;
@@ -6,6 +6,7 @@ function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r)
6
6
  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; }
7
7
  import { isContainedWithinMediaWrapper } from '../../vc-observer/media-wrapper/vc-utils';
8
8
  import isNonVisualStyleMutation from '../../vc-observer/observers/non-visual-styles/is-non-visual-style-mutation';
9
+ import { RLLPlaceholderHandlers } from '../../vc-observer/observers/rll-placeholders';
9
10
  import { createIntersectionObserver } from './intersection-observer';
10
11
  import createMutationObserver from './mutation-observer';
11
12
  import createPerformanceObserver from './performance-observer';
@@ -41,6 +42,10 @@ function sameRectDimensions(a, b) {
41
42
  var createElementMutationsWatcher = function createElementMutationsWatcher(removedNodeRects) {
42
43
  return function (_ref) {
43
44
  var rect = _ref.rect;
45
+ var isRLLPlaceholder = RLLPlaceholderHandlers.getInstance().isRLLPlaceholderHydration(rect);
46
+ if (isRLLPlaceholder) {
47
+ return 'mutation:rll-placeholder';
48
+ }
44
49
  var wasDeleted = removedNodeRects.some(function (nr) {
45
50
  return sameRectDimensions(nr, rect);
46
51
  });
@@ -146,6 +151,17 @@ var ViewportObserver = /*#__PURE__*/function () {
146
151
  }
147
152
  };
148
153
  }
154
+ var isRLLPlaceholder = RLLPlaceholderHandlers.getInstance().isRLLPlaceholderHydration(rect);
155
+ if (isRLLPlaceholder) {
156
+ return {
157
+ type: 'mutation:rll-placeholder',
158
+ mutationData: {
159
+ attributeName: attributeName,
160
+ oldValue: oldValue,
161
+ newValue: newValue
162
+ }
163
+ };
164
+ }
149
165
  var lastElementRect = _this.mapVisibleNodeRects.get(target);
150
166
  if (lastElementRect && sameRectSize(rect, lastElementRect)) {
151
167
  return {
@@ -35,7 +35,7 @@ export type VCEntryType = {
35
35
  vc: number;
36
36
  elements: string[];
37
37
  };
38
- export type VCIgnoreReason = 'image' | 'ssr-hydration' | 'not-visible' | 'non-visual-style' | '';
38
+ export type VCIgnoreReason = 'image' | 'ssr-hydration' | 'not-visible' | 'non-visual-style' | 'rll-placeholder' | '';
39
39
  export type ComponentsLogEntry = {
40
40
  type?: string;
41
41
  targetName: string;