@atlaskit/media-viewer 48.2.13 → 48.2.15

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,18 @@
1
1
  # @atlaskit/media-viewer
2
2
 
3
+ ## 48.2.15
4
+
5
+ ### Patch Changes
6
+
7
+ - [#72472](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/72472) [`575bba0b9bbf`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/575bba0b9bbf) - Fixed issue where quickly switching between images in Media Viewer would result in broken preview.
8
+
9
+ ## 48.2.14
10
+
11
+ ### Patch Changes
12
+
13
+ - [#69045](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/69045) [`284fc8e26be1`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/284fc8e26be1) - Fixed potential memory leak by checking for mounting before updating state
14
+ - Updated dependencies
15
+
3
16
  ## 48.2.13
4
17
 
5
18
  ### Patch Changes
@@ -10,7 +10,7 @@ exports.packageVersion = exports.packageName = void 0;
10
10
  var _mediaCommon = require("@atlaskit/media-common");
11
11
  var componentName = exports.component = exports.componentName = 'mediaViewer';
12
12
  var packageName = exports.packageName = "@atlaskit/media-viewer";
13
- var packageVersion = exports.packageVersion = "48.2.13";
13
+ var packageVersion = exports.packageVersion = "48.2.15";
14
14
  function getFileAttributes(fileState) {
15
15
  if (!fileState) {
16
16
  return {
@@ -12,7 +12,7 @@ var _mediaCommon = require("@atlaskit/media-common");
12
12
  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; }
13
13
  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; }
14
14
  var packageName = "@atlaskit/media-viewer";
15
- var packageVersion = "48.2.13";
15
+ var packageVersion = "48.2.15";
16
16
  var ufoExperience;
17
17
  var getExperience = function getExperience() {
18
18
  if (!ufoExperience) {
@@ -32,6 +32,7 @@ var AsyncMediaViewer = exports.AsyncMediaViewer = /*#__PURE__*/function (_React$
32
32
  args[_key] = arguments[_key];
33
33
  }
34
34
  _this = _super.call.apply(_super, [this].concat(args));
35
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "isMounted", false);
35
36
  (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "state", {
36
37
  // Set state value to equal to current static value of this class.
37
38
  MediaViewer: AsyncMediaViewer.MediaViewer,
@@ -69,10 +70,12 @@ var AsyncMediaViewer = exports.AsyncMediaViewer = /*#__PURE__*/function (_React$
69
70
  MediaViewerWithClient = mediaClient.withMediaClient(mediaViewerModule.MediaViewer);
70
71
  AsyncMediaViewer.MediaViewer = MediaViewerWithClient;
71
72
  AsyncMediaViewer.MediaViewerErrorBoundary = mediaViewerErrorBoundaryModule.default;
72
- this.setState({
73
- MediaViewer: MediaViewerWithClient,
74
- MediaViewerErrorBoundary: AsyncMediaViewer.MediaViewerErrorBoundary
75
- });
73
+ if (this.isMounted) {
74
+ this.setState({
75
+ MediaViewer: MediaViewerWithClient,
76
+ MediaViewerErrorBoundary: AsyncMediaViewer.MediaViewerErrorBoundary
77
+ });
78
+ }
76
79
  _context.next = 17;
77
80
  break;
78
81
  case 15:
@@ -89,6 +92,16 @@ var AsyncMediaViewer = exports.AsyncMediaViewer = /*#__PURE__*/function (_React$
89
92
  }
90
93
  return UNSAFE_componentWillMount;
91
94
  }()
95
+ }, {
96
+ key: "componentDidMount",
97
+ value: function componentDidMount() {
98
+ this.isMounted = true;
99
+ }
100
+ }, {
101
+ key: "componentWillUnmount",
102
+ value: function componentWillUnmount() {
103
+ this.isMounted = false;
104
+ }
92
105
  }, {
93
106
  key: "render",
94
107
  value: function render() {
@@ -123,9 +123,15 @@ var ItemViewerBase = exports.ItemViewerBase = /*#__PURE__*/function (_React$Comp
123
123
  wasStatusUploading: false,
124
124
  wasStatusProcessing: false
125
125
  });
126
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "isMounted", false);
126
127
  (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "traceContext", {
127
128
  traceId: (0, _mediaCommon.getRandomHex)(8)
128
129
  });
130
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "safeSetState", function (newState) {
131
+ if (_this.isMounted) {
132
+ _this.setState(newState);
133
+ }
134
+ });
129
135
  (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "onSuccess", function () {
130
136
  var item = _this.state.item;
131
137
  item.whenSuccessful(function (fileItem) {
@@ -140,7 +146,7 @@ var ItemViewerBase = exports.ItemViewerBase = /*#__PURE__*/function (_React$Comp
140
146
  });
141
147
  });
142
148
  (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "onLoadFail", function (mediaViewerError) {
143
- _this.setState({
149
+ _this.safeSetState({
144
150
  item: _domain.Outcome.failed(mediaViewerError)
145
151
  });
146
152
  });
@@ -156,7 +162,7 @@ var ItemViewerBase = exports.ItemViewerBase = /*#__PURE__*/function (_React$Comp
156
162
  });
157
163
  });
158
164
  (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "onExternalImgError", function () {
159
- _this.setState({
165
+ _this.safeSetState({
160
166
  item: _domain.Outcome.failed(new _errors.MediaViewerError('imageviewer-external-onerror'))
161
167
  });
162
168
  });
@@ -167,7 +173,7 @@ var ItemViewerBase = exports.ItemViewerBase = /*#__PURE__*/function (_React$Comp
167
173
  value: function UNSAFE_componentWillReceiveProps(nextProps) {
168
174
  if (this.needsReset(this.props, nextProps)) {
169
175
  this.release();
170
- this.setState(initialState);
176
+ this.safeSetState(initialState);
171
177
  }
172
178
  }
173
179
  }, {
@@ -180,11 +186,13 @@ var ItemViewerBase = exports.ItemViewerBase = /*#__PURE__*/function (_React$Comp
180
186
  }, {
181
187
  key: "componentWillUnmount",
182
188
  value: function componentWillUnmount() {
189
+ this.isMounted = false;
183
190
  this.release();
184
191
  }
185
192
  }, {
186
193
  key: "componentDidMount",
187
194
  value: function componentDidMount() {
195
+ this.isMounted = true;
188
196
  this.init(this.props);
189
197
  }
190
198
  }, {
@@ -358,7 +366,7 @@ var ItemViewerBase = exports.ItemViewerBase = /*#__PURE__*/function (_React$Comp
358
366
  // external images do not need to talk to our backend,
359
367
  // so therefore no need for media-client subscriptions.
360
368
  // just set a successful outcome of type "external-image".
361
- this.setState({
369
+ this.safeSetState({
362
370
  item: _domain.Outcome.successful('external-image')
363
371
  });
364
372
  return;
@@ -371,12 +379,12 @@ var ItemViewerBase = exports.ItemViewerBase = /*#__PURE__*/function (_React$Comp
371
379
  }).subscribe({
372
380
  next: function next(file) {
373
381
  _this3.updateFileStateFlag(file);
374
- _this3.setState({
382
+ _this3.safeSetState({
375
383
  item: _domain.Outcome.successful(file)
376
384
  });
377
385
  },
378
386
  error: function error(_error) {
379
- _this3.setState({
387
+ _this3.safeSetState({
380
388
  item: _domain.Outcome.failed(new _errors.MediaViewerError('itemviewer-fetch-metadata', _error))
381
389
  });
382
390
  }
@@ -62,7 +62,7 @@ var ImageViewer = exports.ImageViewer = /*#__PURE__*/function (_BaseViewer) {
62
62
  key: "init",
63
63
  value: function () {
64
64
  var _init = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee() {
65
- var _this$props, fileState, mediaClient, collectionName, traceContext, orientation, objectUrl, originalBinaryImageUrl, isLocalFileReference, preview, _yield$preview, value, origin, item, controller, response, imgError;
65
+ var _this$props, fileState, mediaClient, collectionName, traceContext, controller, orientation, objectUrl, originalBinaryImageUrl, isLocalFileReference, preview, _yield$preview, value, origin, item, response, imgError;
66
66
  return _regenerator.default.wrap(function _callee$(_context) {
67
67
  while (1) switch (_context.prev = _context.next) {
68
68
  case 0:
@@ -73,50 +73,50 @@ var ImageViewer = exports.ImageViewer = /*#__PURE__*/function (_BaseViewer) {
73
73
  }
74
74
  return _context.abrupt("return");
75
75
  case 3:
76
- _context.prev = 3;
76
+ controller = typeof AbortController !== 'undefined' ? new AbortController() : undefined;
77
+ _context.prev = 4;
77
78
  orientation = 1;
78
79
  isLocalFileReference = false;
79
80
  preview = fileState.preview;
80
81
  if (!preview) {
81
- _context.next = 24;
82
+ _context.next = 25;
82
83
  break;
83
84
  }
84
- _context.next = 10;
85
+ _context.next = 11;
85
86
  return preview;
86
- case 10:
87
+ case 11:
87
88
  _yield$preview = _context.sent;
88
89
  value = _yield$preview.value;
89
90
  origin = _yield$preview.origin;
90
91
  if (!(value instanceof Blob)) {
91
- _context.next = 21;
92
+ _context.next = 22;
92
93
  break;
93
94
  }
94
- _context.next = 16;
95
+ _context.next = 17;
95
96
  return (0, _mediaUi.getOrientation)(value);
96
- case 16:
97
+ case 17:
97
98
  orientation = _context.sent;
98
99
  objectUrl = URL.createObjectURL(value);
99
100
  isLocalFileReference = origin === 'local';
100
- _context.next = 22;
101
+ _context.next = 23;
101
102
  break;
102
- case 21:
103
- objectUrl = value;
104
103
  case 22:
104
+ objectUrl = value;
105
+ case 23:
105
106
  _context.next = 38;
106
107
  break;
107
- case 24:
108
+ case 25:
108
109
  if (!(0, _mediaClient.isImageRepresentationReady)(fileState)) {
109
110
  _context.next = 36;
110
111
  break;
111
112
  }
112
113
  item = processedFileStateToMediaItem(fileState);
113
- controller = typeof AbortController !== 'undefined' ? new AbortController() : undefined;
114
114
  response = mediaClient.getImage(item.details.id, {
115
115
  collection: collectionName,
116
116
  mode: 'fit'
117
117
  }, controller, true, traceContext);
118
118
  this.cancelImageFetch = function () {
119
- return controller && controller.abort();
119
+ return controller === null || controller === void 0 ? void 0 : controller.abort();
120
120
  };
121
121
  _context.t0 = URL;
122
122
  _context.next = 32;
@@ -154,9 +154,9 @@ var ImageViewer = exports.ImageViewer = /*#__PURE__*/function (_BaseViewer) {
154
154
  break;
155
155
  case 45:
156
156
  _context.prev = 45;
157
- _context.t2 = _context["catch"](3);
157
+ _context.t2 = _context["catch"](4);
158
158
  // TODO : properly handle aborted requests (MS-2843)
159
- if (!(0, _mediaClient.isAbortedRequestError)(_context.t2)) {
159
+ if (!(controller !== null && controller !== void 0 && controller.signal.aborted)) {
160
160
  imgError = new _errors.MediaViewerError('imageviewer-fetch-url', _context.t2 instanceof Error ? _context.t2 : undefined);
161
161
  this.setState({
162
162
  content: _domain.Outcome.failed(imgError)
@@ -167,7 +167,7 @@ var ImageViewer = exports.ImageViewer = /*#__PURE__*/function (_BaseViewer) {
167
167
  case "end":
168
168
  return _context.stop();
169
169
  }
170
- }, _callee, this, [[3, 45]]);
170
+ }, _callee, this, [[4, 45]]);
171
171
  }));
172
172
  function init() {
173
173
  return _init.apply(this, arguments);
@@ -1,7 +1,7 @@
1
1
  import { ANALYTICS_MEDIA_CHANNEL } from '@atlaskit/media-common';
2
2
  const componentName = 'mediaViewer';
3
3
  const packageName = "@atlaskit/media-viewer";
4
- const packageVersion = "48.2.13";
4
+ const packageVersion = "48.2.15";
5
5
  export { packageName, packageVersion, componentName, componentName as component };
6
6
  export function getFileAttributes(fileState) {
7
7
  if (!fileState) {
@@ -2,7 +2,7 @@ import { UFOExperience, ExperiencePerformanceTypes, ExperienceTypes } from '@atl
2
2
  import { getMediaEnvironment, getMediaRegion } from '@atlaskit/media-client';
3
3
  import { getFeatureFlagKeysAllProducts } from '@atlaskit/media-common';
4
4
  const packageName = "@atlaskit/media-viewer";
5
- const packageVersion = "48.2.13";
5
+ const packageVersion = "48.2.15";
6
6
  let ufoExperience;
7
7
  const getExperience = () => {
8
8
  if (!ufoExperience) {
@@ -4,6 +4,7 @@ import ModalSpinner from '../viewers/modalSpinner';
4
4
  export class AsyncMediaViewer extends React.PureComponent {
5
5
  constructor(...args) {
6
6
  super(...args);
7
+ _defineProperty(this, "isMounted", false);
7
8
  _defineProperty(this, "state", {
8
9
  // Set state value to equal to current static value of this class.
9
10
  MediaViewer: AsyncMediaViewer.MediaViewer,
@@ -17,15 +18,23 @@ export class AsyncMediaViewer extends React.PureComponent {
17
18
  const MediaViewerWithClient = mediaClient.withMediaClient(mediaViewerModule.MediaViewer);
18
19
  AsyncMediaViewer.MediaViewer = MediaViewerWithClient;
19
20
  AsyncMediaViewer.MediaViewerErrorBoundary = mediaViewerErrorBoundaryModule.default;
20
- this.setState({
21
- MediaViewer: MediaViewerWithClient,
22
- MediaViewerErrorBoundary: AsyncMediaViewer.MediaViewerErrorBoundary
23
- });
21
+ if (this.isMounted) {
22
+ this.setState({
23
+ MediaViewer: MediaViewerWithClient,
24
+ MediaViewerErrorBoundary: AsyncMediaViewer.MediaViewerErrorBoundary
25
+ });
26
+ }
24
27
  } catch (error) {
25
28
  // TODO [MS-2277]: Add operational error to catch async import error
26
29
  }
27
30
  }
28
31
  }
32
+ componentDidMount() {
33
+ this.isMounted = true;
34
+ }
35
+ componentWillUnmount() {
36
+ this.isMounted = false;
37
+ }
29
38
  render() {
30
39
  const {
31
40
  MediaViewer,
@@ -54,9 +54,15 @@ export class ItemViewerBase extends React.Component {
54
54
  wasStatusUploading: false,
55
55
  wasStatusProcessing: false
56
56
  });
57
+ _defineProperty(this, "isMounted", false);
57
58
  _defineProperty(this, "traceContext", {
58
59
  traceId: getRandomHex(8)
59
60
  });
61
+ _defineProperty(this, "safeSetState", newState => {
62
+ if (this.isMounted) {
63
+ this.setState(newState);
64
+ }
65
+ });
60
66
  _defineProperty(this, "onSuccess", () => {
61
67
  const {
62
68
  item
@@ -73,7 +79,7 @@ export class ItemViewerBase extends React.Component {
73
79
  });
74
80
  });
75
81
  _defineProperty(this, "onLoadFail", mediaViewerError => {
76
- this.setState({
82
+ this.safeSetState({
77
83
  item: Outcome.failed(mediaViewerError)
78
84
  });
79
85
  });
@@ -89,7 +95,7 @@ export class ItemViewerBase extends React.Component {
89
95
  });
90
96
  });
91
97
  _defineProperty(this, "onExternalImgError", () => {
92
- this.setState({
98
+ this.safeSetState({
93
99
  item: Outcome.failed(new MediaViewerError('imageviewer-external-onerror'))
94
100
  });
95
101
  });
@@ -97,7 +103,7 @@ export class ItemViewerBase extends React.Component {
97
103
  UNSAFE_componentWillReceiveProps(nextProps) {
98
104
  if (this.needsReset(this.props, nextProps)) {
99
105
  this.release();
100
- this.setState(initialState);
106
+ this.safeSetState(initialState);
101
107
  }
102
108
  }
103
109
  componentDidUpdate(oldProps) {
@@ -106,9 +112,11 @@ export class ItemViewerBase extends React.Component {
106
112
  }
107
113
  }
108
114
  componentWillUnmount() {
115
+ this.isMounted = false;
109
116
  this.release();
110
117
  }
111
118
  componentDidMount() {
119
+ this.isMounted = true;
112
120
  this.init(this.props);
113
121
  }
114
122
  renderItem(fileState) {
@@ -277,7 +285,7 @@ export class ItemViewerBase extends React.Component {
277
285
  // external images do not need to talk to our backend,
278
286
  // so therefore no need for media-client subscriptions.
279
287
  // just set a successful outcome of type "external-image".
280
- this.setState({
288
+ this.safeSetState({
281
289
  item: Outcome.successful('external-image')
282
290
  });
283
291
  return;
@@ -292,12 +300,12 @@ export class ItemViewerBase extends React.Component {
292
300
  }).subscribe({
293
301
  next: file => {
294
302
  this.updateFileStateFlag(file);
295
- this.setState({
303
+ this.safeSetState({
296
304
  item: Outcome.successful(file)
297
305
  });
298
306
  },
299
307
  error: error => {
300
- this.setState({
308
+ this.safeSetState({
301
309
  item: Outcome.failed(new MediaViewerError('itemviewer-fetch-metadata', error))
302
310
  });
303
311
  }
@@ -1,6 +1,6 @@
1
1
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
2
  import React from 'react';
3
- import { isAbortedRequestError, isImageRepresentationReady, isErrorFileState, addFileAttrsToUrl } from '@atlaskit/media-client';
3
+ import { isImageRepresentationReady, isErrorFileState, addFileAttrsToUrl } from '@atlaskit/media-client';
4
4
  import { isImageMimeTypeSupportedByBrowser } from '@atlaskit/media-common';
5
5
  import { getOrientation } from '@atlaskit/media-ui';
6
6
  import { Outcome } from '../../domain';
@@ -41,6 +41,7 @@ export class ImageViewer extends BaseViewer {
41
41
  if (fileState.status === 'error') {
42
42
  return;
43
43
  }
44
+ const controller = typeof AbortController !== 'undefined' ? new AbortController() : undefined;
44
45
  try {
45
46
  let orientation = 1;
46
47
  let objectUrl;
@@ -63,12 +64,11 @@ export class ImageViewer extends BaseViewer {
63
64
  }
64
65
  } else if (isImageRepresentationReady(fileState)) {
65
66
  const item = processedFileStateToMediaItem(fileState);
66
- const controller = typeof AbortController !== 'undefined' ? new AbortController() : undefined;
67
67
  const response = mediaClient.getImage(item.details.id, {
68
68
  collection: collectionName,
69
69
  mode: 'fit'
70
70
  }, controller, true, traceContext);
71
- this.cancelImageFetch = () => controller && controller.abort();
71
+ this.cancelImageFetch = () => controller === null || controller === void 0 ? void 0 : controller.abort();
72
72
  objectUrl = URL.createObjectURL(await response);
73
73
  } else {
74
74
  this.setState({
@@ -90,7 +90,7 @@ export class ImageViewer extends BaseViewer {
90
90
  });
91
91
  } catch (err) {
92
92
  // TODO : properly handle aborted requests (MS-2843)
93
- if (!isAbortedRequestError(err)) {
93
+ if (!(controller !== null && controller !== void 0 && controller.signal.aborted)) {
94
94
  const imgError = new MediaViewerError('imageviewer-fetch-url', err instanceof Error ? err : undefined);
95
95
  this.setState({
96
96
  content: Outcome.failed(imgError)
@@ -1,7 +1,7 @@
1
1
  import { ANALYTICS_MEDIA_CHANNEL } from '@atlaskit/media-common';
2
2
  var componentName = 'mediaViewer';
3
3
  var packageName = "@atlaskit/media-viewer";
4
- var packageVersion = "48.2.13";
4
+ var packageVersion = "48.2.15";
5
5
  export { packageName, packageVersion, componentName, componentName as component };
6
6
  export function getFileAttributes(fileState) {
7
7
  if (!fileState) {
@@ -5,7 +5,7 @@ import { UFOExperience, ExperiencePerformanceTypes, ExperienceTypes } from '@atl
5
5
  import { getMediaEnvironment, getMediaRegion } from '@atlaskit/media-client';
6
6
  import { getFeatureFlagKeysAllProducts } from '@atlaskit/media-common';
7
7
  var packageName = "@atlaskit/media-viewer";
8
- var packageVersion = "48.2.13";
8
+ var packageVersion = "48.2.15";
9
9
  var ufoExperience;
10
10
  var getExperience = function getExperience() {
11
11
  if (!ufoExperience) {
@@ -22,6 +22,7 @@ export var AsyncMediaViewer = /*#__PURE__*/function (_React$PureComponent) {
22
22
  args[_key] = arguments[_key];
23
23
  }
24
24
  _this = _super.call.apply(_super, [this].concat(args));
25
+ _defineProperty(_assertThisInitialized(_this), "isMounted", false);
25
26
  _defineProperty(_assertThisInitialized(_this), "state", {
26
27
  // Set state value to equal to current static value of this class.
27
28
  MediaViewer: AsyncMediaViewer.MediaViewer,
@@ -53,10 +54,12 @@ export var AsyncMediaViewer = /*#__PURE__*/function (_React$PureComponent) {
53
54
  MediaViewerWithClient = mediaClient.withMediaClient(mediaViewerModule.MediaViewer);
54
55
  AsyncMediaViewer.MediaViewer = MediaViewerWithClient;
55
56
  AsyncMediaViewer.MediaViewerErrorBoundary = mediaViewerErrorBoundaryModule.default;
56
- this.setState({
57
- MediaViewer: MediaViewerWithClient,
58
- MediaViewerErrorBoundary: AsyncMediaViewer.MediaViewerErrorBoundary
59
- });
57
+ if (this.isMounted) {
58
+ this.setState({
59
+ MediaViewer: MediaViewerWithClient,
60
+ MediaViewerErrorBoundary: AsyncMediaViewer.MediaViewerErrorBoundary
61
+ });
62
+ }
60
63
  _context.next = 17;
61
64
  break;
62
65
  case 15:
@@ -73,6 +76,16 @@ export var AsyncMediaViewer = /*#__PURE__*/function (_React$PureComponent) {
73
76
  }
74
77
  return UNSAFE_componentWillMount;
75
78
  }()
79
+ }, {
80
+ key: "componentDidMount",
81
+ value: function componentDidMount() {
82
+ this.isMounted = true;
83
+ }
84
+ }, {
85
+ key: "componentWillUnmount",
86
+ value: function componentWillUnmount() {
87
+ this.isMounted = false;
88
+ }
76
89
  }, {
77
90
  key: "render",
78
91
  value: function render() {
@@ -103,9 +103,15 @@ export var ItemViewerBase = /*#__PURE__*/function (_React$Component) {
103
103
  wasStatusUploading: false,
104
104
  wasStatusProcessing: false
105
105
  });
106
+ _defineProperty(_assertThisInitialized(_this), "isMounted", false);
106
107
  _defineProperty(_assertThisInitialized(_this), "traceContext", {
107
108
  traceId: getRandomHex(8)
108
109
  });
110
+ _defineProperty(_assertThisInitialized(_this), "safeSetState", function (newState) {
111
+ if (_this.isMounted) {
112
+ _this.setState(newState);
113
+ }
114
+ });
109
115
  _defineProperty(_assertThisInitialized(_this), "onSuccess", function () {
110
116
  var item = _this.state.item;
111
117
  item.whenSuccessful(function (fileItem) {
@@ -120,7 +126,7 @@ export var ItemViewerBase = /*#__PURE__*/function (_React$Component) {
120
126
  });
121
127
  });
122
128
  _defineProperty(_assertThisInitialized(_this), "onLoadFail", function (mediaViewerError) {
123
- _this.setState({
129
+ _this.safeSetState({
124
130
  item: Outcome.failed(mediaViewerError)
125
131
  });
126
132
  });
@@ -136,7 +142,7 @@ export var ItemViewerBase = /*#__PURE__*/function (_React$Component) {
136
142
  });
137
143
  });
138
144
  _defineProperty(_assertThisInitialized(_this), "onExternalImgError", function () {
139
- _this.setState({
145
+ _this.safeSetState({
140
146
  item: Outcome.failed(new MediaViewerError('imageviewer-external-onerror'))
141
147
  });
142
148
  });
@@ -147,7 +153,7 @@ export var ItemViewerBase = /*#__PURE__*/function (_React$Component) {
147
153
  value: function UNSAFE_componentWillReceiveProps(nextProps) {
148
154
  if (this.needsReset(this.props, nextProps)) {
149
155
  this.release();
150
- this.setState(initialState);
156
+ this.safeSetState(initialState);
151
157
  }
152
158
  }
153
159
  }, {
@@ -160,11 +166,13 @@ export var ItemViewerBase = /*#__PURE__*/function (_React$Component) {
160
166
  }, {
161
167
  key: "componentWillUnmount",
162
168
  value: function componentWillUnmount() {
169
+ this.isMounted = false;
163
170
  this.release();
164
171
  }
165
172
  }, {
166
173
  key: "componentDidMount",
167
174
  value: function componentDidMount() {
175
+ this.isMounted = true;
168
176
  this.init(this.props);
169
177
  }
170
178
  }, {
@@ -338,7 +346,7 @@ export var ItemViewerBase = /*#__PURE__*/function (_React$Component) {
338
346
  // external images do not need to talk to our backend,
339
347
  // so therefore no need for media-client subscriptions.
340
348
  // just set a successful outcome of type "external-image".
341
- this.setState({
349
+ this.safeSetState({
342
350
  item: Outcome.successful('external-image')
343
351
  });
344
352
  return;
@@ -351,12 +359,12 @@ export var ItemViewerBase = /*#__PURE__*/function (_React$Component) {
351
359
  }).subscribe({
352
360
  next: function next(file) {
353
361
  _this3.updateFileStateFlag(file);
354
- _this3.setState({
362
+ _this3.safeSetState({
355
363
  item: Outcome.successful(file)
356
364
  });
357
365
  },
358
366
  error: function error(_error) {
359
- _this3.setState({
367
+ _this3.safeSetState({
360
368
  item: Outcome.failed(new MediaViewerError('itemviewer-fetch-metadata', _error))
361
369
  });
362
370
  }
@@ -10,7 +10,7 @@ import _regeneratorRuntime from "@babel/runtime/regenerator";
10
10
  function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
11
11
  function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
12
12
  import React from 'react';
13
- import { isAbortedRequestError, isImageRepresentationReady, isErrorFileState, addFileAttrsToUrl } from '@atlaskit/media-client';
13
+ import { isImageRepresentationReady, isErrorFileState, addFileAttrsToUrl } from '@atlaskit/media-client';
14
14
  import { isImageMimeTypeSupportedByBrowser } from '@atlaskit/media-common';
15
15
  import { getOrientation } from '@atlaskit/media-ui';
16
16
  import { Outcome } from '../../domain';
@@ -55,7 +55,7 @@ export var ImageViewer = /*#__PURE__*/function (_BaseViewer) {
55
55
  key: "init",
56
56
  value: function () {
57
57
  var _init = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
58
- var _this$props, fileState, mediaClient, collectionName, traceContext, orientation, objectUrl, originalBinaryImageUrl, isLocalFileReference, preview, _yield$preview, value, origin, item, controller, response, imgError;
58
+ var _this$props, fileState, mediaClient, collectionName, traceContext, controller, orientation, objectUrl, originalBinaryImageUrl, isLocalFileReference, preview, _yield$preview, value, origin, item, response, imgError;
59
59
  return _regeneratorRuntime.wrap(function _callee$(_context) {
60
60
  while (1) switch (_context.prev = _context.next) {
61
61
  case 0:
@@ -66,50 +66,50 @@ export var ImageViewer = /*#__PURE__*/function (_BaseViewer) {
66
66
  }
67
67
  return _context.abrupt("return");
68
68
  case 3:
69
- _context.prev = 3;
69
+ controller = typeof AbortController !== 'undefined' ? new AbortController() : undefined;
70
+ _context.prev = 4;
70
71
  orientation = 1;
71
72
  isLocalFileReference = false;
72
73
  preview = fileState.preview;
73
74
  if (!preview) {
74
- _context.next = 24;
75
+ _context.next = 25;
75
76
  break;
76
77
  }
77
- _context.next = 10;
78
+ _context.next = 11;
78
79
  return preview;
79
- case 10:
80
+ case 11:
80
81
  _yield$preview = _context.sent;
81
82
  value = _yield$preview.value;
82
83
  origin = _yield$preview.origin;
83
84
  if (!(value instanceof Blob)) {
84
- _context.next = 21;
85
+ _context.next = 22;
85
86
  break;
86
87
  }
87
- _context.next = 16;
88
+ _context.next = 17;
88
89
  return getOrientation(value);
89
- case 16:
90
+ case 17:
90
91
  orientation = _context.sent;
91
92
  objectUrl = URL.createObjectURL(value);
92
93
  isLocalFileReference = origin === 'local';
93
- _context.next = 22;
94
+ _context.next = 23;
94
95
  break;
95
- case 21:
96
- objectUrl = value;
97
96
  case 22:
97
+ objectUrl = value;
98
+ case 23:
98
99
  _context.next = 38;
99
100
  break;
100
- case 24:
101
+ case 25:
101
102
  if (!isImageRepresentationReady(fileState)) {
102
103
  _context.next = 36;
103
104
  break;
104
105
  }
105
106
  item = processedFileStateToMediaItem(fileState);
106
- controller = typeof AbortController !== 'undefined' ? new AbortController() : undefined;
107
107
  response = mediaClient.getImage(item.details.id, {
108
108
  collection: collectionName,
109
109
  mode: 'fit'
110
110
  }, controller, true, traceContext);
111
111
  this.cancelImageFetch = function () {
112
- return controller && controller.abort();
112
+ return controller === null || controller === void 0 ? void 0 : controller.abort();
113
113
  };
114
114
  _context.t0 = URL;
115
115
  _context.next = 32;
@@ -147,9 +147,9 @@ export var ImageViewer = /*#__PURE__*/function (_BaseViewer) {
147
147
  break;
148
148
  case 45:
149
149
  _context.prev = 45;
150
- _context.t2 = _context["catch"](3);
150
+ _context.t2 = _context["catch"](4);
151
151
  // TODO : properly handle aborted requests (MS-2843)
152
- if (!isAbortedRequestError(_context.t2)) {
152
+ if (!(controller !== null && controller !== void 0 && controller.signal.aborted)) {
153
153
  imgError = new MediaViewerError('imageviewer-fetch-url', _context.t2 instanceof Error ? _context.t2 : undefined);
154
154
  this.setState({
155
155
  content: Outcome.failed(imgError)
@@ -160,7 +160,7 @@ export var ImageViewer = /*#__PURE__*/function (_BaseViewer) {
160
160
  case "end":
161
161
  return _context.stop();
162
162
  }
163
- }, _callee, this, [[3, 45]]);
163
+ }, _callee, this, [[4, 45]]);
164
164
  }));
165
165
  function init() {
166
166
  return _init.apply(this, arguments);
@@ -13,8 +13,11 @@ export declare class AsyncMediaViewer extends React.PureComponent<MediaViewerWit
13
13
  static displayName: string;
14
14
  static MediaViewer?: MediaViewerWithMediaClientConfigComponent;
15
15
  static MediaViewerErrorBoundary?: MediaViewerErrorBoundaryComponent;
16
+ isMounted: boolean;
16
17
  state: AsyncMediaViewerState;
17
18
  UNSAFE_componentWillMount(): Promise<void>;
19
+ componentDidMount(): void;
20
+ componentWillUnmount(): void;
18
21
  render(): JSX.Element;
19
22
  }
20
23
  export default AsyncMediaViewer;
@@ -24,7 +24,9 @@ export declare class ItemViewerBase extends React.Component<Props, State> {
24
24
  state: State;
25
25
  private subscription?;
26
26
  private fileStateFlags;
27
+ isMounted: boolean;
27
28
  private traceContext;
29
+ safeSetState: (newState: State) => void;
28
30
  UNSAFE_componentWillReceiveProps(nextProps: Props): void;
29
31
  componentDidUpdate(oldProps: Props): void;
30
32
  componentWillUnmount(): void;
@@ -13,8 +13,11 @@ export declare class AsyncMediaViewer extends React.PureComponent<MediaViewerWit
13
13
  static displayName: string;
14
14
  static MediaViewer?: MediaViewerWithMediaClientConfigComponent;
15
15
  static MediaViewerErrorBoundary?: MediaViewerErrorBoundaryComponent;
16
+ isMounted: boolean;
16
17
  state: AsyncMediaViewerState;
17
18
  UNSAFE_componentWillMount(): Promise<void>;
19
+ componentDidMount(): void;
20
+ componentWillUnmount(): void;
18
21
  render(): JSX.Element;
19
22
  }
20
23
  export default AsyncMediaViewer;
@@ -24,7 +24,9 @@ export declare class ItemViewerBase extends React.Component<Props, State> {
24
24
  state: State;
25
25
  private subscription?;
26
26
  private fileStateFlags;
27
+ isMounted: boolean;
27
28
  private traceContext;
29
+ safeSetState: (newState: State) => void;
28
30
  UNSAFE_componentWillReceiveProps(nextProps: Props): void;
29
31
  componentDidUpdate(oldProps: Props): void;
30
32
  componentWillUnmount(): void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/media-viewer",
3
- "version": "48.2.13",
3
+ "version": "48.2.15",
4
4
  "description": "MediaViewer is Atlassian's powerful solution for viewing files on the web. It's both powerful and extendable yet easy-to-integrate",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"
@@ -35,20 +35,20 @@
35
35
  }
36
36
  },
37
37
  "dependencies": {
38
- "@atlaskit/analytics-next": "^9.1.0",
39
- "@atlaskit/button": "^17.2.0",
38
+ "@atlaskit/analytics-next": "^9.2.0",
39
+ "@atlaskit/button": "^17.3.0",
40
40
  "@atlaskit/code": "^15.1.0",
41
41
  "@atlaskit/icon": "^22.0.0",
42
42
  "@atlaskit/icon-file-type": "^6.4.0",
43
- "@atlaskit/media-client": "^26.1.0",
43
+ "@atlaskit/media-client": "^26.2.0",
44
44
  "@atlaskit/media-client-react": "^2.0.0",
45
45
  "@atlaskit/media-common": "^11.0.0",
46
- "@atlaskit/media-ui": "^25.0.0",
46
+ "@atlaskit/media-ui": "^25.1.0",
47
47
  "@atlaskit/platform-feature-flags": "^0.2.4",
48
48
  "@atlaskit/side-navigation": "^3.0.0",
49
49
  "@atlaskit/spinner": "^16.0.0",
50
50
  "@atlaskit/theme": "^12.6.0",
51
- "@atlaskit/tokens": "^1.33.0",
51
+ "@atlaskit/tokens": "^1.37.0",
52
52
  "@atlaskit/ufo": "^0.2.0",
53
53
  "@babel/runtime": "^7.0.0",
54
54
  "@kenjiuno/msgreader": "^1.2.6",
@@ -70,10 +70,10 @@
70
70
  },
71
71
  "devDependencies": {
72
72
  "@af/integration-testing": "*",
73
- "@atlaskit/media-core": "^34.1.0",
73
+ "@atlaskit/media-core": "^34.2.0",
74
74
  "@atlaskit/media-integration-test-helpers": "^3.0.0",
75
75
  "@atlaskit/media-state": "^1.0.0",
76
- "@atlaskit/media-test-data": "^1.1.0",
76
+ "@atlaskit/media-test-data": "^1.2.0",
77
77
  "@atlaskit/media-test-helpers": "^33.0.0",
78
78
  "@atlaskit/ssr": "*",
79
79
  "@atlaskit/visual-regression": "*",