@atlaskit/smart-card 40.7.3 → 40.8.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @atlaskit/smart-card
2
2
 
3
+ ## 40.8.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#198611](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/pull-requests/198611)
8
+ [`a608f23cb3d4e`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/a608f23cb3d4e) -
9
+ [https://product-fabric.atlassian.net/browse/ED-28628](ED-28628) - add SSR support for smart cards
10
+
11
+ ### Patch Changes
12
+
13
+ - Updated dependencies
14
+
3
15
  ## 40.7.3
4
16
 
5
17
  ### Patch Changes
@@ -11,7 +11,7 @@ var ANALYTICS_CHANNEL = exports.ANALYTICS_CHANNEL = 'media';
11
11
  var context = exports.context = {
12
12
  componentName: 'smart-cards',
13
13
  packageName: "@atlaskit/smart-card",
14
- packageVersion: "40.7.2"
14
+ packageVersion: "40.7.3"
15
15
  };
16
16
  var TrackQuickActionType = exports.TrackQuickActionType = /*#__PURE__*/function (TrackQuickActionType) {
17
17
  TrackQuickActionType["StatusUpdate"] = "StatusUpdate";
@@ -10,6 +10,7 @@ var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/sli
10
10
  var _react = _interopRequireWildcard(require("react"));
11
11
  var _state = require("../../../state");
12
12
  var _ufoExperiences = require("../../../state/analytics/ufoExperiences");
13
+ var _store = require("../../../state/store");
13
14
  var _shouldSample = require("../../../utils/shouldSample");
14
15
  var _component = require("../component");
15
16
  var _LoadingCardLink = require("./LoadingCardLink");
@@ -19,18 +20,25 @@ function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r
19
20
  // being compared to. Since the default container is the `document`, we set this
20
21
  // up to check once a Smart Link is within `X` px from the bottom of the viewport.
21
22
  var ROOT_MARGIN_VERTICAL = '360px';
23
+ // Returns true on SSR and SPA if page was SSR'd
24
+ var isPageSSRd = function isPageSSRd() {
25
+ return Boolean(process.env.REACT_SSR || window.__SSR_RENDERED__);
26
+ };
22
27
  function LazyIntersectionObserverCard(props) {
28
+ var appearance = props.appearance,
29
+ url = props.url,
30
+ id = props.id;
23
31
  var ref = (0, _react.useRef)(null);
24
- var _useState = (0, _react.useState)(false),
32
+ var state = (0, _store.useSmartCardState)(url);
33
+ // If page was SSR we don't need to enable intersection for already resolved cards,
34
+ // to avoid flickering.
35
+ var _useState = (0, _react.useState)(isPageSSRd() && state.status === 'resolved'),
25
36
  _useState2 = (0, _slicedToArray2.default)(_useState, 2),
26
37
  isIntersecting = _useState2[0],
27
38
  setIsIntersecting = _useState2[1];
28
39
  var _useState3 = (0, _react.useState)((0, _shouldSample.shouldSample)()),
29
40
  _useState4 = (0, _slicedToArray2.default)(_useState3, 1),
30
41
  shouldSendRenderedUFOEvent = _useState4[0];
31
- var appearance = props.appearance,
32
- url = props.url,
33
- id = props.id;
34
42
  var prefetch = (0, _state.usePrefetch)(url);
35
43
  var Component = appearance === 'inline' ? 'span' : 'div';
36
44
  var ComponentObserver = Component;
@@ -39,15 +47,23 @@ function LazyIntersectionObserverCard(props) {
39
47
  return entry.isIntersecting;
40
48
  });
41
49
  if (isVisible) {
42
- if (shouldSendRenderedUFOEvent) {
43
- (0, _ufoExperiences.startUfoExperience)('smart-link-rendered', id);
44
- }
45
50
  setIsIntersecting(true);
46
51
  observer.disconnect();
47
52
  } else {
48
53
  prefetch();
49
54
  }
50
- }, [id, prefetch, shouldSendRenderedUFOEvent]);
55
+ }, [prefetch]);
56
+ var isSartUfoExperienceSend = (0, _react.useRef)(false);
57
+ // We need to use `useLayoutEffect` here to ensure that the UFO start event is sent
58
+ // before another component is rendered.
59
+ (0, _react.useLayoutEffect)(function () {
60
+ if (isIntersecting && !isSartUfoExperienceSend.current) {
61
+ isSartUfoExperienceSend.current = true;
62
+ if (shouldSendRenderedUFOEvent) {
63
+ (0, _ufoExperiences.startUfoExperience)('smart-link-rendered', id);
64
+ }
65
+ }
66
+ }, [id, isIntersecting, shouldSendRenderedUFOEvent]);
51
67
  (0, _react.useEffect)(function () {
52
68
  if (!ref.current) {
53
69
  return;
@@ -19,7 +19,7 @@ var _excluded = ["href", "children", "checkSafety", "onClick", "testId", "isLink
19
19
  _excluded2 = ["isLinkSafe", "showSafetyWarningModal"];
20
20
  var PACKAGE_DATA = {
21
21
  packageName: "@atlaskit/smart-card",
22
- packageVersion: "40.7.2",
22
+ packageVersion: "40.7.3",
23
23
  componentName: 'linkUrl'
24
24
  };
25
25
  var Anchor = (0, _click.withLinkClickedEvent)('a');
@@ -2,7 +2,7 @@ export const ANALYTICS_CHANNEL = 'media';
2
2
  export const context = {
3
3
  componentName: 'smart-cards',
4
4
  packageName: "@atlaskit/smart-card",
5
- packageVersion: "40.7.2"
5
+ packageVersion: "40.7.3"
6
6
  };
7
7
  export let TrackQuickActionType = /*#__PURE__*/function (TrackQuickActionType) {
8
8
  TrackQuickActionType["StatusUpdate"] = "StatusUpdate";
@@ -1,6 +1,7 @@
1
- import React, { useCallback, useEffect, useRef, useState } from 'react';
1
+ import React, { useCallback, useEffect, useLayoutEffect, useRef, useState } from 'react';
2
2
  import { usePrefetch } from '../../../state';
3
3
  import { startUfoExperience } from '../../../state/analytics/ufoExperiences';
4
+ import { useSmartCardState } from '../../../state/store';
4
5
  import { shouldSample } from '../../../utils/shouldSample';
5
6
  import { CardWithUrlContent } from '../component';
6
7
  import { LoadingCardLink } from './LoadingCardLink';
@@ -10,30 +11,45 @@ import { LoadingCardLink } from './LoadingCardLink';
10
11
  // being compared to. Since the default container is the `document`, we set this
11
12
  // up to check once a Smart Link is within `X` px from the bottom of the viewport.
12
13
  const ROOT_MARGIN_VERTICAL = '360px';
14
+ // Returns true on SSR and SPA if page was SSR'd
15
+ const isPageSSRd = () => {
16
+ return Boolean(process.env.REACT_SSR || window.__SSR_RENDERED__);
17
+ };
13
18
  export function LazyIntersectionObserverCard(props) {
14
- const ref = useRef(null);
15
- const [isIntersecting, setIsIntersecting] = useState(false);
16
- const [shouldSendRenderedUFOEvent] = useState(shouldSample());
17
19
  const {
18
20
  appearance,
19
21
  url,
20
22
  id
21
23
  } = props;
24
+ const ref = useRef(null);
25
+ const state = useSmartCardState(url);
26
+ // If page was SSR we don't need to enable intersection for already resolved cards,
27
+ // to avoid flickering.
28
+ const [isIntersecting, setIsIntersecting] = useState(isPageSSRd() && state.status === 'resolved');
29
+ const [shouldSendRenderedUFOEvent] = useState(shouldSample());
22
30
  const prefetch = usePrefetch(url);
23
31
  const Component = appearance === 'inline' ? 'span' : 'div';
24
32
  const ComponentObserver = Component;
25
33
  const onIntersection = useCallback((entries, observer) => {
26
34
  const isVisible = entries.some(entry => entry.isIntersecting);
27
35
  if (isVisible) {
28
- if (shouldSendRenderedUFOEvent) {
29
- startUfoExperience('smart-link-rendered', id);
30
- }
31
36
  setIsIntersecting(true);
32
37
  observer.disconnect();
33
38
  } else {
34
39
  prefetch();
35
40
  }
36
- }, [id, prefetch, shouldSendRenderedUFOEvent]);
41
+ }, [prefetch]);
42
+ const isSartUfoExperienceSend = useRef(false);
43
+ // We need to use `useLayoutEffect` here to ensure that the UFO start event is sent
44
+ // before another component is rendered.
45
+ useLayoutEffect(() => {
46
+ if (isIntersecting && !isSartUfoExperienceSend.current) {
47
+ isSartUfoExperienceSend.current = true;
48
+ if (shouldSendRenderedUFOEvent) {
49
+ startUfoExperience('smart-link-rendered', id);
50
+ }
51
+ }
52
+ }, [id, isIntersecting, shouldSendRenderedUFOEvent]);
37
53
  useEffect(() => {
38
54
  if (!ref.current) {
39
55
  return;
@@ -9,7 +9,7 @@ import LinkWarningModal from './LinkWarningModal';
9
9
  import { useLinkWarningModal } from './LinkWarningModal/hooks/use-link-warning-modal';
10
10
  const PACKAGE_DATA = {
11
11
  packageName: "@atlaskit/smart-card",
12
- packageVersion: "40.7.2",
12
+ packageVersion: "40.7.3",
13
13
  componentName: 'linkUrl'
14
14
  };
15
15
  const Anchor = withLinkClickedEvent('a');
@@ -4,7 +4,7 @@ export var ANALYTICS_CHANNEL = 'media';
4
4
  export var context = {
5
5
  componentName: 'smart-cards',
6
6
  packageName: "@atlaskit/smart-card",
7
- packageVersion: "40.7.2"
7
+ packageVersion: "40.7.3"
8
8
  };
9
9
  export var TrackQuickActionType = /*#__PURE__*/function (TrackQuickActionType) {
10
10
  TrackQuickActionType["StatusUpdate"] = "StatusUpdate";
@@ -1,7 +1,8 @@
1
1
  import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
2
- import React, { useCallback, useEffect, useRef, useState } from 'react';
2
+ import React, { useCallback, useEffect, useLayoutEffect, useRef, useState } from 'react';
3
3
  import { usePrefetch } from '../../../state';
4
4
  import { startUfoExperience } from '../../../state/analytics/ufoExperiences';
5
+ import { useSmartCardState } from '../../../state/store';
5
6
  import { shouldSample } from '../../../utils/shouldSample';
6
7
  import { CardWithUrlContent } from '../component';
7
8
  import { LoadingCardLink } from './LoadingCardLink';
@@ -11,18 +12,25 @@ import { LoadingCardLink } from './LoadingCardLink';
11
12
  // being compared to. Since the default container is the `document`, we set this
12
13
  // up to check once a Smart Link is within `X` px from the bottom of the viewport.
13
14
  var ROOT_MARGIN_VERTICAL = '360px';
15
+ // Returns true on SSR and SPA if page was SSR'd
16
+ var isPageSSRd = function isPageSSRd() {
17
+ return Boolean(process.env.REACT_SSR || window.__SSR_RENDERED__);
18
+ };
14
19
  export function LazyIntersectionObserverCard(props) {
20
+ var appearance = props.appearance,
21
+ url = props.url,
22
+ id = props.id;
15
23
  var ref = useRef(null);
16
- var _useState = useState(false),
24
+ var state = useSmartCardState(url);
25
+ // If page was SSR we don't need to enable intersection for already resolved cards,
26
+ // to avoid flickering.
27
+ var _useState = useState(isPageSSRd() && state.status === 'resolved'),
17
28
  _useState2 = _slicedToArray(_useState, 2),
18
29
  isIntersecting = _useState2[0],
19
30
  setIsIntersecting = _useState2[1];
20
31
  var _useState3 = useState(shouldSample()),
21
32
  _useState4 = _slicedToArray(_useState3, 1),
22
33
  shouldSendRenderedUFOEvent = _useState4[0];
23
- var appearance = props.appearance,
24
- url = props.url,
25
- id = props.id;
26
34
  var prefetch = usePrefetch(url);
27
35
  var Component = appearance === 'inline' ? 'span' : 'div';
28
36
  var ComponentObserver = Component;
@@ -31,15 +39,23 @@ export function LazyIntersectionObserverCard(props) {
31
39
  return entry.isIntersecting;
32
40
  });
33
41
  if (isVisible) {
34
- if (shouldSendRenderedUFOEvent) {
35
- startUfoExperience('smart-link-rendered', id);
36
- }
37
42
  setIsIntersecting(true);
38
43
  observer.disconnect();
39
44
  } else {
40
45
  prefetch();
41
46
  }
42
- }, [id, prefetch, shouldSendRenderedUFOEvent]);
47
+ }, [prefetch]);
48
+ var isSartUfoExperienceSend = useRef(false);
49
+ // We need to use `useLayoutEffect` here to ensure that the UFO start event is sent
50
+ // before another component is rendered.
51
+ useLayoutEffect(function () {
52
+ if (isIntersecting && !isSartUfoExperienceSend.current) {
53
+ isSartUfoExperienceSend.current = true;
54
+ if (shouldSendRenderedUFOEvent) {
55
+ startUfoExperience('smart-link-rendered', id);
56
+ }
57
+ }
58
+ }, [id, isIntersecting, shouldSendRenderedUFOEvent]);
43
59
  useEffect(function () {
44
60
  if (!ref.current) {
45
61
  return;
@@ -12,7 +12,7 @@ import LinkWarningModal from './LinkWarningModal';
12
12
  import { useLinkWarningModal } from './LinkWarningModal/hooks/use-link-warning-modal';
13
13
  var PACKAGE_DATA = {
14
14
  packageName: "@atlaskit/smart-card",
15
- packageVersion: "40.7.2",
15
+ packageVersion: "40.7.3",
16
16
  componentName: 'linkUrl'
17
17
  };
18
18
  var Anchor = withLinkClickedEvent('a');
@@ -1,3 +1,8 @@
1
1
  import React from 'react';
2
2
  import { type CardWithUrlContentProps } from '../types';
3
+ declare global {
4
+ interface Window {
5
+ __SSR_RENDERED__?: boolean;
6
+ }
7
+ }
3
8
  export declare function LazyIntersectionObserverCard(props: CardWithUrlContentProps): React.JSX.Element;
@@ -1,3 +1,8 @@
1
1
  import React from 'react';
2
2
  import { type CardWithUrlContentProps } from '../types';
3
+ declare global {
4
+ interface Window {
5
+ __SSR_RENDERED__?: boolean;
6
+ }
7
+ }
3
8
  export declare function LazyIntersectionObserverCard(props: CardWithUrlContentProps): React.JSX.Element;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/smart-card",
3
- "version": "40.7.3",
3
+ "version": "40.8.0",
4
4
  "description": "Smart card component",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"
@@ -29,7 +29,7 @@
29
29
  "@atlaskit/analytics-gas-types": "^5.1.0",
30
30
  "@atlaskit/analytics-next": "^11.1.0",
31
31
  "@atlaskit/avatar": "^25.1.0",
32
- "@atlaskit/avatar-group": "^12.1.0",
32
+ "@atlaskit/avatar-group": "^12.2.0",
33
33
  "@atlaskit/badge": "^18.1.0",
34
34
  "@atlaskit/button": "^23.3.0",
35
35
  "@atlaskit/checkbox": "^17.1.0",