@atlaskit/react-ufo 4.15.16 → 4.15.17

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.
@@ -8,31 +8,12 @@ import { createIntersectionObserver } from './intersection-observer';
8
8
  import createMutationObserver from './mutation-observer';
9
9
  import createPerformanceObserver from './performance-observer';
10
10
  import checkWithinComponent, { cleanupCaches } from './utils/check-within-component';
11
- import { getMutatedElements } from './utils/get-mutated-elements';
12
11
  import { isElementVisible } from './utils/is-element-visible';
13
12
  import isInVCIgnoreIfNoLayoutShiftMarker from './utils/is-in-vc-ignore-if-no-layout-shift-marker';
14
13
  import { isInputNameMutation } from './utils/is-input-name-mutation';
15
14
  import { isSameRectDimensions } from './utils/is-same-rect-dimensions';
16
15
  import { isSameRectSize } from './utils/is-same-rect-size';
17
- const createElementMutationsWatcher = removedNodeRects => ({
18
- target,
19
- rect
20
- }) => {
21
- const isInIgnoreLsMarker = isInVCIgnoreIfNoLayoutShiftMarker(target);
22
- if (!isInIgnoreLsMarker) {
23
- return 'mutation:element';
24
- }
25
- const isRLLPlaceholder = RLLPlaceholderHandlers.getInstance().isRLLPlaceholderHydration(rect);
26
- if (isRLLPlaceholder && isInIgnoreLsMarker) {
27
- return 'mutation:rll-placeholder';
28
- }
29
- const wasDeleted = removedNodeRects.some(nr => isSameRectDimensions(nr, rect));
30
- if (wasDeleted && isInIgnoreLsMarker) {
31
- return 'mutation:element-replacement';
32
- }
33
- return 'mutation:element';
34
- };
35
- const createElementMutationsWatcherV4 = (removedNodeRects, isWithinThirdPartySegment, hasSameDeletedNode, timestamp, isTargetReactRoot, getSSRState, getSSRPlaceholderHandler) => ({
16
+ const createElementMutationsWatcher = (removedNodeRects, isWithinThirdPartySegment, hasSameDeletedNode, timestamp, isTargetReactRoot, getSSRState, getSSRPlaceholderHandler) => ({
36
17
  target,
37
18
  rect
38
19
  }) => {
@@ -139,118 +120,23 @@ export default class ViewportObserver {
139
120
  });
140
121
  const targetNode = target.deref();
141
122
  for (const addedNodeRef of addedNodes) {
123
+ var _this$getSSRState, _this$getSSRState$cal, _this$intersectionObs;
142
124
  const addedNode = addedNodeRef.deref();
143
125
  if (!addedNode) {
144
126
  continue;
145
127
  }
146
- if (fg('platform_ufo_detect_zero_dimension_rectangles')) {
147
- var _this$getSSRState, _this$getSSRState$cal, _this$intersectionObs;
148
- const hasSameDeletedNode = removedNodes.find(ref => {
149
- const n = ref.deref();
150
- if (!n || !addedNode) {
151
- return false;
152
- }
153
- return n.isEqualNode(addedNode);
154
- });
155
- const {
156
- isWithin: isWithinThirdPartySegment
157
- } = checkWithinComponent(addedNode, 'UFOThirdPartySegment', this.mapIs3pResult);
158
- const isTargetReactRoot = targetNode === ((_this$getSSRState = this.getSSRState) === null || _this$getSSRState === void 0 ? void 0 : (_this$getSSRState$cal = _this$getSSRState.call(this)) === null || _this$getSSRState$cal === void 0 ? void 0 : _this$getSSRState$cal.reactRootElement);
159
- (_this$intersectionObs = this.intersectionObserver) === null || _this$intersectionObs === void 0 ? void 0 : _this$intersectionObs.watchAndTag(addedNode, createElementMutationsWatcherV4(removedNodeRects, isWithinThirdPartySegment, !!hasSameDeletedNode, timestamp, isTargetReactRoot, this.getSSRState, this.getSSRPlaceholderHandler));
160
- } else {
161
- for (const {
162
- isDisplayContentsElementChildren,
163
- element
164
- } of getMutatedElements(addedNode)) {
165
- // SSR hydration logic
166
- if (this.getSSRState) {
167
- const ssrState = this.getSSRState();
168
- const SSRStateEnum = {
169
- normal: 1,
170
- waitingForFirstRender: 2,
171
- ignoring: 3
172
- };
173
- if (ssrState.state === SSRStateEnum.waitingForFirstRender && timestamp > ssrState.renderStart && targetNode === ssrState.reactRootElement) {
174
- var _this$intersectionObs2;
175
- ssrState.state = SSRStateEnum.ignoring;
176
- if (ssrState.renderStop === -1) {
177
- // arbitrary 500ms DOM update window
178
- ssrState.renderStop = timestamp + 500;
179
- }
180
- (_this$intersectionObs2 = this.intersectionObserver) === null || _this$intersectionObs2 === void 0 ? void 0 : _this$intersectionObs2.watchAndTag(element, 'ssr-hydration');
181
- continue;
182
- }
183
- if (ssrState.state === SSRStateEnum.ignoring && timestamp > ssrState.renderStart && targetNode === ssrState.reactRootElement) {
184
- if (timestamp <= ssrState.renderStop) {
185
- var _this$intersectionObs3;
186
- (_this$intersectionObs3 = this.intersectionObserver) === null || _this$intersectionObs3 === void 0 ? void 0 : _this$intersectionObs3.watchAndTag(element, 'ssr-hydration');
187
- continue;
188
- } else {
189
- ssrState.state = SSRStateEnum.normal;
190
- }
191
- }
192
- }
193
-
194
- // SSR placeholder logic - check and handle with await
195
- if (this.getSSRPlaceholderHandler) {
196
- const ssrPlaceholderHandler = this.getSSRPlaceholderHandler();
197
- if (ssrPlaceholderHandler) {
198
- if (ssrPlaceholderHandler.isPlaceholder(element) || ssrPlaceholderHandler.isPlaceholderIgnored(element)) {
199
- if (ssrPlaceholderHandler.checkIfExistedAndSizeMatchingV3(element)) {
200
- var _this$intersectionObs4;
201
- (_this$intersectionObs4 = this.intersectionObserver) === null || _this$intersectionObs4 === void 0 ? void 0 : _this$intersectionObs4.watchAndTag(element, 'mutation:ssr-placeholder');
202
- continue;
203
- }
204
- // If result is false, continue to normal mutation logic below
205
- }
206
- if (ssrPlaceholderHandler.isPlaceholderReplacement(element) || ssrPlaceholderHandler.isPlaceholderIgnored(element)) {
207
- const result = await ssrPlaceholderHandler.validateReactComponentMatchToPlaceholder(element);
208
- if (result !== false) {
209
- var _this$intersectionObs5;
210
- (_this$intersectionObs5 = this.intersectionObserver) === null || _this$intersectionObs5 === void 0 ? void 0 : _this$intersectionObs5.watchAndTag(element, 'mutation:ssr-placeholder');
211
- continue;
212
- }
213
- // If result is false, continue to normal mutation logic below
214
- }
215
- }
216
- }
217
- const sameDeletedNode = removedNodes.find(ref => {
218
- const n = ref.deref();
219
- if (!n || !element) {
220
- return false;
221
- }
222
- return n.isEqualNode(element);
223
- });
224
- const isInIgnoreLsMarker = element instanceof HTMLElement ? isInVCIgnoreIfNoLayoutShiftMarker(element) : false;
225
- if (sameDeletedNode && isInIgnoreLsMarker) {
226
- var _this$intersectionObs6;
227
- (_this$intersectionObs6 = this.intersectionObserver) === null || _this$intersectionObs6 === void 0 ? void 0 : _this$intersectionObs6.watchAndTag(element, 'mutation:remount');
228
- continue;
229
- }
230
- if (isContainedWithinMediaWrapper(element)) {
231
- var _this$intersectionObs7;
232
- (_this$intersectionObs7 = this.intersectionObserver) === null || _this$intersectionObs7 === void 0 ? void 0 : _this$intersectionObs7.watchAndTag(element, 'mutation:media');
233
- continue;
234
- }
235
- const {
236
- isWithin: isWithinThirdPartySegment
237
- } = element instanceof HTMLElement ? checkWithinComponent(element, 'UFOThirdPartySegment', this.mapIs3pResult) : {
238
- isWithin: false
239
- };
240
- if (isWithinThirdPartySegment) {
241
- var _this$intersectionObs8;
242
- (_this$intersectionObs8 = this.intersectionObserver) === null || _this$intersectionObs8 === void 0 ? void 0 : _this$intersectionObs8.watchAndTag(element, 'mutation:third-party-element');
243
- continue;
244
- }
245
- if (isDisplayContentsElementChildren) {
246
- var _this$intersectionObs9;
247
- (_this$intersectionObs9 = this.intersectionObserver) === null || _this$intersectionObs9 === void 0 ? void 0 : _this$intersectionObs9.watchAndTag(element, 'mutation:display-contents-children-element');
248
- } else {
249
- var _this$intersectionObs0;
250
- (_this$intersectionObs0 = this.intersectionObserver) === null || _this$intersectionObs0 === void 0 ? void 0 : _this$intersectionObs0.watchAndTag(element, createElementMutationsWatcher(removedNodeRects));
251
- }
128
+ const hasSameDeletedNode = removedNodes.find(ref => {
129
+ const n = ref.deref();
130
+ if (!n || !addedNode) {
131
+ return false;
252
132
  }
253
- }
133
+ return n.isEqualNode(addedNode);
134
+ });
135
+ const {
136
+ isWithin: isWithinThirdPartySegment
137
+ } = checkWithinComponent(addedNode, 'UFOThirdPartySegment', this.mapIs3pResult);
138
+ const isTargetReactRoot = targetNode === ((_this$getSSRState = this.getSSRState) === null || _this$getSSRState === void 0 ? void 0 : (_this$getSSRState$cal = _this$getSSRState.call(this)) === null || _this$getSSRState$cal === void 0 ? void 0 : _this$getSSRState$cal.reactRootElement);
139
+ (_this$intersectionObs = this.intersectionObserver) === null || _this$intersectionObs === void 0 ? void 0 : _this$intersectionObs.watchAndTag(addedNode, createElementMutationsWatcher(removedNodeRects, isWithinThirdPartySegment, !!hasSameDeletedNode, timestamp, isTargetReactRoot, this.getSSRState, this.getSSRPlaceholderHandler));
254
140
  }
255
141
  });
256
142
  _defineProperty(this, "handleAttributeMutation", ({
@@ -259,8 +145,8 @@ export default class ViewportObserver {
259
145
  oldValue,
260
146
  newValue
261
147
  }) => {
262
- var _this$intersectionObs1;
263
- (_this$intersectionObs1 = this.intersectionObserver) === null || _this$intersectionObs1 === void 0 ? void 0 : _this$intersectionObs1.watchAndTag(target, ({
148
+ var _this$intersectionObs2;
149
+ (_this$intersectionObs2 = this.intersectionObserver) === null || _this$intersectionObs2 === void 0 ? void 0 : _this$intersectionObs2.watchAndTag(target, ({
264
150
  target,
265
151
  rect
266
152
  }) => {
@@ -432,12 +318,12 @@ export default class ViewportObserver {
432
318
  this.isStarted = true;
433
319
  }
434
320
  stop() {
435
- var _this$mutationObserve2, _this$intersectionObs10, _this$performanceObse2;
321
+ var _this$mutationObserve2, _this$intersectionObs3, _this$performanceObse2;
436
322
  if (!this.isStarted) {
437
323
  return;
438
324
  }
439
325
  (_this$mutationObserve2 = this.mutationObserver) === null || _this$mutationObserve2 === void 0 ? void 0 : _this$mutationObserve2.disconnect();
440
- (_this$intersectionObs10 = this.intersectionObserver) === null || _this$intersectionObs10 === void 0 ? void 0 : _this$intersectionObs10.disconnect();
326
+ (_this$intersectionObs3 = this.intersectionObserver) === null || _this$intersectionObs3 === void 0 ? void 0 : _this$intersectionObs3.disconnect();
441
327
  (_this$performanceObse2 = this.performanceObserver) === null || _this$performanceObse2 === void 0 ? void 0 : _this$performanceObse2.disconnect();
442
328
  this.isStarted = false;
443
329
  // Clean up caches when stopping
@@ -1,4 +1,3 @@
1
- import { fg } from '@atlaskit/platform-feature-flags';
2
1
  import { isZeroDimensionRectangle } from '../utils/is-zero-dimension-rectangle';
3
2
  function isValidEntry(entry) {
4
3
  return entry.isIntersecting && entry.intersectionRect.width > 0 && entry.intersectionRect.height > 0;
@@ -20,31 +19,29 @@ export function createIntersectionObserver({
20
19
  return;
21
20
  }
22
21
  const tagOrCallback = callbacksPerElement.get(entry.target);
23
- if (fg('platform_ufo_detect_zero_dimension_rectangles')) {
24
- if (isZeroDimensionRectangle(entry.intersectionRect)) {
25
- const zeroDimensionRectangleTagCallback = props => {
26
- const tagOrCallbackResult = typeof tagOrCallback === 'function' ? tagOrCallback(props) : tagOrCallback;
22
+ if (isZeroDimensionRectangle(entry.intersectionRect)) {
23
+ const zeroDimensionRectangleTagCallback = props => {
24
+ const tagOrCallbackResult = typeof tagOrCallback === 'function' ? tagOrCallback(props) : tagOrCallback;
27
25
 
28
- // override as display-contents mutation
29
- if (tagOrCallbackResult === 'mutation:element') {
30
- return 'mutation:display-contents-children-element';
31
- }
26
+ // override as display-contents mutation
27
+ if (tagOrCallbackResult === 'mutation:element') {
28
+ return 'mutation:display-contents-children-element';
29
+ }
32
30
 
33
- // override as display-contents mutation
34
- if (tagOrCallbackResult && typeof tagOrCallbackResult !== 'string' && tagOrCallbackResult.type === 'mutation:attribute') {
35
- return {
36
- type: 'mutation:display-contents-children-attribute',
37
- mutationData: tagOrCallbackResult.mutationData
38
- };
39
- }
40
- return tagOrCallbackResult;
41
- };
42
- for (const child of entry.target.children) {
43
- observer.observe(child);
44
- callbacksPerElement.set(child, zeroDimensionRectangleTagCallback);
31
+ // override as display-contents mutation
32
+ if (tagOrCallbackResult && typeof tagOrCallbackResult !== 'string' && tagOrCallbackResult.type === 'mutation:attribute') {
33
+ return {
34
+ type: 'mutation:display-contents-children-attribute',
35
+ mutationData: tagOrCallbackResult.mutationData
36
+ };
45
37
  }
46
- return;
38
+ return tagOrCallbackResult;
39
+ };
40
+ for (const child of entry.target.children) {
41
+ observer.observe(child);
42
+ callbacksPerElement.set(child, zeroDimensionRectangleTagCallback);
47
43
  }
44
+ return;
48
45
  }
49
46
  if (!isValidEntry(entry)) {
50
47
  return;
@@ -15,9 +15,7 @@ var getConsideredEntryTypes = function getConsideredEntryTypes() {
15
15
  if (fg('platform_ufo_remove_ssr_placeholder_in_ttvc_v4')) {
16
16
  consideredEntryTypes.push('mutation:ssr-placeholder');
17
17
  }
18
- if (fg('platform_ufo_detect_zero_dimension_rectangles')) {
19
- consideredEntryTypes.push('mutation:display-contents-children-attribute');
20
- }
18
+ consideredEntryTypes.push('mutation:display-contents-children-attribute');
21
19
  return consideredEntryTypes;
22
20
  };
23
21
  var getExcludedEntryTypes = function getExcludedEntryTypes() {