@atlaskit/react-ufo 3.14.6 → 3.14.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/dist/cjs/vc/index.js +39 -6
  3. package/dist/cjs/vc/vc-observer/index.js +10 -2
  4. package/dist/cjs/vc/vc-observer/observers/index.js +12 -7
  5. package/dist/cjs/vc/vc-observer/observers/ssr-placeholders/index.js +76 -40
  6. package/dist/cjs/vc/vc-observer-new/index.js +84 -0
  7. package/dist/cjs/vc/vc-observer-new/viewport-observer/index.js +214 -71
  8. package/dist/cjs/vc/vc-observer-new/viewport-observer/mutation-observer/index.js +97 -59
  9. package/dist/es2019/vc/index.js +37 -5
  10. package/dist/es2019/vc/vc-observer/index.js +8 -2
  11. package/dist/es2019/vc/vc-observer/observers/index.js +11 -5
  12. package/dist/es2019/vc/vc-observer/observers/ssr-placeholders/index.js +57 -26
  13. package/dist/es2019/vc/vc-observer-new/index.js +67 -1
  14. package/dist/es2019/vc/vc-observer-new/viewport-observer/index.js +87 -22
  15. package/dist/es2019/vc/vc-observer-new/viewport-observer/mutation-observer/index.js +50 -34
  16. package/dist/esm/vc/index.js +39 -6
  17. package/dist/esm/vc/vc-observer/index.js +10 -2
  18. package/dist/esm/vc/vc-observer/observers/index.js +12 -7
  19. package/dist/esm/vc/vc-observer/observers/ssr-placeholders/index.js +76 -40
  20. package/dist/esm/vc/vc-observer-new/index.js +84 -0
  21. package/dist/esm/vc/vc-observer-new/viewport-observer/index.js +214 -71
  22. package/dist/esm/vc/vc-observer-new/viewport-observer/mutation-observer/index.js +97 -59
  23. package/dist/types/vc/index.d.ts +2 -0
  24. package/dist/types/vc/types.d.ts +2 -0
  25. package/dist/types/vc/vc-observer/index.d.ts +1 -0
  26. package/dist/types/vc/vc-observer/observers/index.d.ts +2 -0
  27. package/dist/types/vc/vc-observer/observers/ssr-placeholders/index.d.ts +6 -0
  28. package/dist/types/vc/vc-observer-new/index.d.ts +30 -0
  29. package/dist/types/vc/vc-observer-new/types.d.ts +1 -1
  30. package/dist/types/vc/vc-observer-new/viewport-observer/index.d.ts +5 -1
  31. package/dist/types/vc/vc-observer-new/viewport-observer/mutation-observer/index.d.ts +2 -0
  32. package/dist/types-ts4.5/vc/index.d.ts +2 -0
  33. package/dist/types-ts4.5/vc/types.d.ts +2 -0
  34. package/dist/types-ts4.5/vc/vc-observer/index.d.ts +1 -0
  35. package/dist/types-ts4.5/vc/vc-observer/observers/index.d.ts +2 -0
  36. package/dist/types-ts4.5/vc/vc-observer/observers/ssr-placeholders/index.d.ts +6 -0
  37. package/dist/types-ts4.5/vc/vc-observer-new/index.d.ts +30 -0
  38. package/dist/types-ts4.5/vc/vc-observer-new/types.d.ts +1 -1
  39. package/dist/types-ts4.5/vc/vc-observer-new/viewport-observer/index.d.ts +5 -1
  40. package/dist/types-ts4.5/vc/vc-observer-new/viewport-observer/mutation-observer/index.d.ts +2 -0
  41. package/package.json +5 -3
@@ -25,9 +25,7 @@ function isElementVisible(target) {
25
25
  }
26
26
  export var Observers = /*#__PURE__*/function () {
27
27
  function Observers(opts) {
28
- var _this = this,
29
- _opts$SSRConfig,
30
- _opts$SSRConfig2;
28
+ var _this = this;
31
29
  _classCallCheck(this, Observers);
32
30
  _defineProperty(this, "observedMutations", new WeakMap());
33
31
  _defineProperty(this, "elementsInView", new Set());
@@ -67,10 +65,17 @@ export var Observers = /*#__PURE__*/function () {
67
65
  this.selectorConfig = _objectSpread(_objectSpread({}, this.selectorConfig), opts.selectorConfig);
68
66
  this.intersectionObserver = this.getIntersectionObserver();
69
67
  this.mutationObserver = this.getMutationObserver();
70
- this.ssrPlaceholderHandler = new SSRPlaceholderHandlers({
71
- enablePageLayoutPlaceholder: (_opts$SSRConfig = opts.SSRConfig) === null || _opts$SSRConfig === void 0 ? void 0 : _opts$SSRConfig.enablePageLayoutPlaceholder,
72
- disableSizeAndPositionCheck: (_opts$SSRConfig2 = opts.SSRConfig) === null || _opts$SSRConfig2 === void 0 ? void 0 : _opts$SSRConfig2.disableSizeAndPositionCheck
73
- });
68
+
69
+ // Use shared SSR placeholder handler if provided, otherwise create new one
70
+ if (opts.ssrPlaceholderHandler) {
71
+ this.ssrPlaceholderHandler = opts.ssrPlaceholderHandler;
72
+ } else {
73
+ var _opts$SSRConfig, _opts$SSRConfig2;
74
+ this.ssrPlaceholderHandler = new SSRPlaceholderHandlers({
75
+ enablePageLayoutPlaceholder: (_opts$SSRConfig = opts.SSRConfig) === null || _opts$SSRConfig === void 0 ? void 0 : _opts$SSRConfig.enablePageLayoutPlaceholder,
76
+ disableSizeAndPositionCheck: (_opts$SSRConfig2 = opts.SSRConfig) === null || _opts$SSRConfig2 === void 0 ? void 0 : _opts$SSRConfig2.disableSizeAndPositionCheck
77
+ });
78
+ }
74
79
  }
75
80
  return _createClass(Observers, [{
76
81
  key: "isBrowserSupported",
@@ -104,32 +104,8 @@ export var SSRPlaceholderHandlers = /*#__PURE__*/function () {
104
104
  this.disableSizeAndPositionCheck = disableSizeAndPositionCheck;
105
105
  if (window.document) {
106
106
  try {
107
- var selector = this.enablePageLayoutPlaceholder ? '[data-ssr-placeholder],[data-testid="page-layout.root"]' : '[data-ssr-placeholder]';
108
- var existingElements = document.querySelectorAll(selector);
109
- existingElements.forEach(function (el) {
110
- var placeholderId = el instanceof HTMLElement && _this.getPlaceholderId(el);
111
- if (placeholderId) {
112
- var _window$__SSR_PLACEHO, _this$intersectionObs2;
113
- var width = -1;
114
- var height = -1;
115
- var x = -1;
116
- var y = -1;
117
- var boundingClientRect = (_window$__SSR_PLACEHO = window.__SSR_PLACEHOLDERS_DIMENSIONS__) === null || _window$__SSR_PLACEHO === void 0 ? void 0 : _window$__SSR_PLACEHO[placeholderId];
118
- if (boundingClientRect) {
119
- width = boundingClientRect.width;
120
- height = boundingClientRect.height;
121
- x = boundingClientRect.x;
122
- y = boundingClientRect.y;
123
- }
124
- _this.staticPlaceholders.set(placeholderId, {
125
- width: width,
126
- height: height,
127
- x: x,
128
- y: y
129
- });
130
- (_this$intersectionObs2 = _this.intersectionObserver) === null || _this$intersectionObs2 === void 0 || _this$intersectionObs2.observe(el);
131
- }
132
- });
107
+ // Collect initial placeholders using SSR dimensions
108
+ this.collectPlaceholdersInternal();
133
109
  } catch (e) {} finally {
134
110
  delete window.__SSR_PLACEHOLDERS_DIMENSIONS__;
135
111
  }
@@ -143,6 +119,66 @@ export var SSRPlaceholderHandlers = /*#__PURE__*/function () {
143
119
  this.getSizeCallbacks = new Map();
144
120
  this.reactValidateCallbacks = new Map();
145
121
  }
122
+ }, {
123
+ key: "collectPlaceholdersInternal",
124
+ value: function collectPlaceholdersInternal() {
125
+ var _this2 = this;
126
+ var selector = this.enablePageLayoutPlaceholder ? '[data-ssr-placeholder],[data-testid="page-layout.root"]' : '[data-ssr-placeholder]';
127
+ var existingElements = document.querySelectorAll(selector);
128
+ existingElements.forEach(function (el) {
129
+ var placeholderId = el instanceof HTMLElement && _this2.getPlaceholderId(el);
130
+ if (placeholderId && !_this2.staticPlaceholders.has(placeholderId)) {
131
+ var _window$__SSR_PLACEHO, _this2$intersectionOb;
132
+ var width = -1;
133
+ var height = -1;
134
+ var x = -1;
135
+ var y = -1;
136
+
137
+ // Use SSR dimensions from window global if available
138
+ var boundingClientRect = (_window$__SSR_PLACEHO = window.__SSR_PLACEHOLDERS_DIMENSIONS__) === null || _window$__SSR_PLACEHO === void 0 ? void 0 : _window$__SSR_PLACEHO[placeholderId];
139
+ if (boundingClientRect) {
140
+ width = boundingClientRect.width;
141
+ height = boundingClientRect.height;
142
+ x = boundingClientRect.x;
143
+ y = boundingClientRect.y;
144
+ } else {
145
+ // Fallback to current bounding rect if SSR dimensions not available
146
+ var rect = el.getBoundingClientRect();
147
+ width = rect.width;
148
+ height = rect.height;
149
+ x = rect.x;
150
+ y = rect.y;
151
+ }
152
+ _this2.staticPlaceholders.set(placeholderId, {
153
+ width: width,
154
+ height: height,
155
+ x: x,
156
+ y: y
157
+ });
158
+ (_this2$intersectionOb = _this2.intersectionObserver) === null || _this2$intersectionOb === void 0 || _this2$intersectionOb.observe(el);
159
+ }
160
+ });
161
+ }
162
+
163
+ /**
164
+ * Added this method to be utilised for testing purposes.
165
+ * In production it collection placeholder should only happens on constructor
166
+ */
167
+ }, {
168
+ key: "collectExistingPlaceholders",
169
+ value: function collectExistingPlaceholders() {
170
+ if (!window.document) {
171
+ return;
172
+ }
173
+ try {
174
+ // Collect placeholders using SSR dimensions or fallback to live dimensions
175
+ this.collectPlaceholdersInternal();
176
+ } catch (e) {
177
+ // Silently fail if there are any issues
178
+ } finally {
179
+ delete window.__SSR_PLACEHOLDERS_DIMENSIONS__;
180
+ }
181
+ }
146
182
  }, {
147
183
  key: "isPlaceholder",
148
184
  value: function isPlaceholder(element) {
@@ -179,44 +215,44 @@ export var SSRPlaceholderHandlers = /*#__PURE__*/function () {
179
215
  }, {
180
216
  key: "checkIfExistedAndSizeMatching",
181
217
  value: function checkIfExistedAndSizeMatching(el) {
182
- var _this2 = this;
218
+ var _this3 = this;
183
219
  el = this.findNearestPlaceholderContainerIfIgnored(el);
184
220
  var id = this.getPlaceholderId(el);
185
221
  return new Promise(function (resolve) {
186
- if (!_this2.staticPlaceholders.has(id)) {
222
+ if (!_this3.staticPlaceholders.has(id)) {
187
223
  resolve(false);
188
224
  return;
189
225
  } else {
190
- var _this2$intersectionOb;
191
- _this2.callbacks.set(id, resolve);
192
- (_this2$intersectionOb = _this2.intersectionObserver) === null || _this2$intersectionOb === void 0 || _this2$intersectionOb.observe(el);
226
+ var _this3$intersectionOb;
227
+ _this3.callbacks.set(id, resolve);
228
+ (_this3$intersectionOb = _this3.intersectionObserver) === null || _this3$intersectionOb === void 0 || _this3$intersectionOb.observe(el);
193
229
  }
194
230
  });
195
231
  }
196
232
  }, {
197
233
  key: "getSize",
198
234
  value: function getSize(el) {
199
- var _this3 = this;
235
+ var _this4 = this;
200
236
  return new Promise(function (resolve) {
201
- var _this3$intersectionOb;
202
- _this3.getSizeCallbacks.set(_this3.getPlaceholderId(el), resolve);
203
- (_this3$intersectionOb = _this3.intersectionObserver) === null || _this3$intersectionOb === void 0 || _this3$intersectionOb.observe(el);
237
+ var _this4$intersectionOb;
238
+ _this4.getSizeCallbacks.set(_this4.getPlaceholderId(el), resolve);
239
+ (_this4$intersectionOb = _this4.intersectionObserver) === null || _this4$intersectionOb === void 0 || _this4$intersectionOb.observe(el);
204
240
  });
205
241
  }
206
242
  }, {
207
243
  key: "validateReactComponentMatchToPlaceholder",
208
244
  value: function validateReactComponentMatchToPlaceholder(el) {
209
- var _this4 = this;
245
+ var _this5 = this;
210
246
  el = this.findNearestPlaceholderContainerIfIgnored(el);
211
247
  var id = this.getPlaceholderReplacementId(el);
212
248
  return new Promise(function (resolve) {
213
- if (!_this4.staticPlaceholders.has(id)) {
249
+ if (!_this5.staticPlaceholders.has(id)) {
214
250
  resolve(false);
215
251
  return;
216
252
  } else {
217
- var _this4$intersectionOb;
218
- _this4.reactValidateCallbacks.set(id, resolve);
219
- (_this4$intersectionOb = _this4.intersectionObserver) === null || _this4$intersectionOb === void 0 || _this4$intersectionOb.observe(el);
253
+ var _this5$intersectionOb;
254
+ _this5.reactValidateCallbacks.set(id, resolve);
255
+ (_this5$intersectionOb = _this5.intersectionObserver) === null || _this5$intersectionOb === void 0 || _this5$intersectionOb.observe(el);
220
256
  }
221
257
  });
222
258
  }
@@ -6,6 +6,7 @@ import _createClass from "@babel/runtime/helpers/createClass";
6
6
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
7
7
  import _regeneratorRuntime from "@babel/runtime/regenerator";
8
8
  import { fg } from '@atlaskit/platform-feature-flags';
9
+ import { SSRPlaceholderHandlers } from '../vc-observer/observers/ssr-placeholders';
9
10
  import EntriesTimeline from './entries-timeline';
10
11
  import _getElementName from './get-element-name';
11
12
  import VCCalculator_FY25_03 from './metric-calculator/fy25_03';
@@ -13,6 +14,11 @@ import getViewportHeight from './metric-calculator/utils/get-viewport-height';
13
14
  import getViewportWidth from './metric-calculator/utils/get-viewport-width';
14
15
  import ViewportObserver from './viewport-observer';
15
16
  import WindowEventObserver from './window-event-observer';
17
+ var SSRState = {
18
+ normal: 1,
19
+ waitingForFirstRender: 2,
20
+ ignoring: 3
21
+ };
16
22
  var DEFAULT_SELECTOR_CONFIG = {
17
23
  id: false,
18
24
  testId: true,
@@ -28,9 +34,31 @@ var VCObserverNew = /*#__PURE__*/function () {
28
34
  _classCallCheck(this, VCObserverNew);
29
35
  _defineProperty(this, "viewportObserver", null);
30
36
  _defineProperty(this, "windowEventObserver", null);
37
+ // SSR related properties
38
+ _defineProperty(this, "ssrPlaceholderHandler", null);
39
+ _defineProperty(this, "ssr", {
40
+ state: SSRState.normal,
41
+ reactRootElement: null,
42
+ renderStart: -1,
43
+ renderStop: -1
44
+ });
31
45
  this.entriesTimeline = new EntriesTimeline();
32
46
  this.isPostInteraction = (_config$isPostInterac = config.isPostInteraction) !== null && _config$isPostInterac !== void 0 ? _config$isPostInterac : false;
33
47
  this.selectorConfig = (_config$selectorConfi = config.selectorConfig) !== null && _config$selectorConfi !== void 0 ? _config$selectorConfi : DEFAULT_SELECTOR_CONFIG;
48
+
49
+ // Use shared SSR placeholder handler if provided, otherwise create new one if feature flag is enabled
50
+ if (config.ssrPlaceholderHandler) {
51
+ this.ssrPlaceholderHandler = config.ssrPlaceholderHandler;
52
+ } else {
53
+ var _config$SSRConfig$ena, _config$SSRConfig, _config$SSRConfig$dis, _config$SSRConfig2;
54
+ this.ssrPlaceholderHandler = new SSRPlaceholderHandlers({
55
+ enablePageLayoutPlaceholder: (_config$SSRConfig$ena = (_config$SSRConfig = config.SSRConfig) === null || _config$SSRConfig === void 0 ? void 0 : _config$SSRConfig.enablePageLayoutPlaceholder) !== null && _config$SSRConfig$ena !== void 0 ? _config$SSRConfig$ena : false,
56
+ disableSizeAndPositionCheck: (_config$SSRConfig$dis = (_config$SSRConfig2 = config.SSRConfig) === null || _config$SSRConfig2 === void 0 ? void 0 : _config$SSRConfig2.disableSizeAndPositionCheck) !== null && _config$SSRConfig$dis !== void 0 ? _config$SSRConfig$dis : {
57
+ v: false,
58
+ h: false
59
+ }
60
+ });
61
+ }
34
62
  this.viewportObserver = new ViewportObserver({
35
63
  onChange: function onChange(onChangeArg) {
36
64
  var time = onChangeArg.time,
@@ -58,6 +86,13 @@ var VCObserverNew = /*#__PURE__*/function () {
58
86
  newValue: mutationData === null || mutationData === void 0 ? void 0 : mutationData.newValue
59
87
  }
60
88
  });
89
+ },
90
+ // Pass SSR context to ViewportObserver
91
+ getSSRState: function getSSRState() {
92
+ return _this.getSSRState();
93
+ },
94
+ getSSRPlaceholderHandler: function getSSRPlaceholderHandler() {
95
+ return _this.getSSRPlaceholderHandler();
61
96
  }
62
97
  });
63
98
  this.windowEventObserver = new WindowEventObserver({
@@ -82,6 +117,14 @@ var VCObserverNew = /*#__PURE__*/function () {
82
117
  _this2 = this,
83
118
  _this$windowEventObse;
84
119
  var startTime = _ref2.startTime;
120
+ // Reset SSR state on start (matches old VCObserver behavior)
121
+ this.ssr = {
122
+ state: SSRState.normal,
123
+ reactRootElement: null,
124
+ // Reset to null (matches old VCObserver)
125
+ renderStart: -1,
126
+ renderStop: -1
127
+ };
85
128
  (_this$viewportObserve = this.viewportObserver) === null || _this$viewportObserve === void 0 || _this$viewportObserve.start();
86
129
  if ((_window = window) !== null && _window !== void 0 && _window.__SSR_ABORT_LISTENERS__ && fg('platform_ufo_vc_observer_new_ssr_abort_listener')) {
87
130
  var abortListeners = window.__SSR_ABORT_LISTENERS__;
@@ -112,6 +155,47 @@ var VCObserverNew = /*#__PURE__*/function () {
112
155
  var _this$viewportObserve2, _this$windowEventObse2;
113
156
  (_this$viewportObserve2 = this.viewportObserver) === null || _this$viewportObserve2 === void 0 || _this$viewportObserve2.stop();
114
157
  (_this$windowEventObse2 = this.windowEventObserver) === null || _this$windowEventObse2 === void 0 || _this$windowEventObse2.stop();
158
+
159
+ // Clear SSR state on stop (matches old VCObserver behavior)
160
+ this.ssr.reactRootElement = null;
161
+ }
162
+
163
+ // SSR related methods
164
+ }, {
165
+ key: "setReactRootElement",
166
+ value: function setReactRootElement(element) {
167
+ this.ssr.reactRootElement = element;
168
+ }
169
+ }, {
170
+ key: "setReactRootRenderStart",
171
+ value: function setReactRootRenderStart() {
172
+ var startTime = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : performance.now();
173
+ this.ssr.renderStart = startTime;
174
+ this.ssr.state = SSRState.waitingForFirstRender;
175
+ }
176
+ }, {
177
+ key: "setReactRootRenderStop",
178
+ value: function setReactRootRenderStop() {
179
+ var stopTime = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : performance.now();
180
+ this.ssr.renderStop = stopTime;
181
+ }
182
+ }, {
183
+ key: "collectSSRPlaceholders",
184
+ value: function collectSSRPlaceholders() {
185
+ // This is handled by the shared SSRPlaceholderHandlers in VCObserverWrapper
186
+ // Individual observers don't need to implement this
187
+ }
188
+
189
+ // Internal methods for ViewportObserver to access SSR state
190
+ }, {
191
+ key: "getSSRState",
192
+ value: function getSSRState() {
193
+ return this.ssr;
194
+ }
195
+ }, {
196
+ key: "getSSRPlaceholderHandler",
197
+ value: function getSSRPlaceholderHandler() {
198
+ return this.ssrPlaceholderHandler;
115
199
  }
116
200
  }, {
117
201
  key: "addSSR",