@atlaskit/media-file-preview 0.14.0 → 0.14.1
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 +8 -0
- package/dist/cjs/helpers.js +9 -1
- package/dist/cjs/useFilePreview.js +3 -2
- package/dist/es2019/helpers.js +8 -0
- package/dist/es2019/useFilePreview.js +4 -3
- package/dist/esm/helpers.js +8 -0
- package/dist/esm/useFilePreview.js +4 -3
- package/dist/types/helpers.d.ts +1 -0
- package/dist/types-ts4.5/helpers.d.ts +1 -0
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# @atlaskit/media-file-preview
|
|
2
2
|
|
|
3
|
+
## 0.14.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [`a0a262f68a1ec`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/a0a262f68a1ec) -
|
|
8
|
+
Fixed the issue with SSR previews not refeching higher resolution images when the SSR preview is
|
|
9
|
+
less wide then the hydration dimensions
|
|
10
|
+
|
|
3
11
|
## 0.14.0
|
|
4
12
|
|
|
5
13
|
### Minor Changes
|
package/dist/cjs/helpers.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.isBigger = exports.createRequestDimensions = void 0;
|
|
6
|
+
exports.isWider = exports.isBigger = exports.createRequestDimensions = void 0;
|
|
7
7
|
exports.useCurrentValueRef = useCurrentValueRef;
|
|
8
8
|
var _react = require("react");
|
|
9
9
|
/**
|
|
@@ -25,6 +25,14 @@ var isBigger = exports.isBigger = function isBigger(current, next) {
|
|
|
25
25
|
return false;
|
|
26
26
|
}
|
|
27
27
|
};
|
|
28
|
+
var isWider = exports.isWider = function isWider(current, next) {
|
|
29
|
+
if (current === undefined && next !== undefined) {
|
|
30
|
+
return true;
|
|
31
|
+
}
|
|
32
|
+
var currentWidth = (current === null || current === void 0 ? void 0 : current.width) || 0;
|
|
33
|
+
var nextWidth = (next === null || next === void 0 ? void 0 : next.width) || 0;
|
|
34
|
+
return currentWidth < nextWidth;
|
|
35
|
+
};
|
|
28
36
|
|
|
29
37
|
/** Verifies if the current screen is retina display */
|
|
30
38
|
function isRetina() {
|
|
@@ -269,7 +269,8 @@ var useFilePreview = exports.useFilePreview = function useFilePreview(_ref) {
|
|
|
269
269
|
// We always refetch SSR preview to be able to browser-cache a version without the token in the query parameters
|
|
270
270
|
(0, _getPreview.isSSRPreview)(preview)) && !skipRemote && upfrontPreviewStatus === 'resolved' && isBackendPreviewReady) {
|
|
271
271
|
// If the preview is SSR, we can skip the refetch as it will be handled by the global scope promise
|
|
272
|
-
|
|
272
|
+
// If the preview is not wider than the requested dimensions, we can skip the refetch
|
|
273
|
+
if (preview && (0, _getPreview.isSSRPreview)(preview) && !(0, _helpers.isWider)(preview.dimensions, dimensions) && (0, _platformFeatureFlags.fg)('media-perf-uplift-mutation-fix')) {
|
|
273
274
|
return;
|
|
274
275
|
}
|
|
275
276
|
setIsLoading(true);
|
|
@@ -286,7 +287,7 @@ var useFilePreview = exports.useFilePreview = function useFilePreview(_ref) {
|
|
|
286
287
|
setIsLoading(false);
|
|
287
288
|
});
|
|
288
289
|
}
|
|
289
|
-
}, [error, nonCriticalError, getAndCacheRemotePreviewRef, identifier.id, resizeMode, isBannedLocalPreview, mediaBlobUrlAttrsRef, preview, requestDimensions, skipRemote, isBackendPreviewReady, localBinary, mediaType, mimeType, upfrontPreviewStatus]);
|
|
290
|
+
}, [error, nonCriticalError, getAndCacheRemotePreviewRef, identifier.id, resizeMode, isBannedLocalPreview, mediaBlobUrlAttrsRef, preview, requestDimensions, skipRemote, isBackendPreviewReady, localBinary, mediaType, mimeType, upfrontPreviewStatus, dimensions]);
|
|
290
291
|
|
|
291
292
|
//----------------------------------------------------------------
|
|
292
293
|
// RETURN
|
package/dist/es2019/helpers.js
CHANGED
|
@@ -20,6 +20,14 @@ export const isBigger = (current, next) => {
|
|
|
20
20
|
return false;
|
|
21
21
|
}
|
|
22
22
|
};
|
|
23
|
+
export const isWider = (current, next) => {
|
|
24
|
+
if (current === undefined && next !== undefined) {
|
|
25
|
+
return true;
|
|
26
|
+
}
|
|
27
|
+
const currentWidth = (current === null || current === void 0 ? void 0 : current.width) || 0;
|
|
28
|
+
const nextWidth = (next === null || next === void 0 ? void 0 : next.width) || 0;
|
|
29
|
+
return currentWidth < nextWidth;
|
|
30
|
+
};
|
|
23
31
|
|
|
24
32
|
/** Verifies if the current screen is retina display */
|
|
25
33
|
function isRetina() {
|
|
@@ -8,7 +8,7 @@ import { createFailedSSRObject, extractErrorInfo } from './analytics';
|
|
|
8
8
|
import { ensureMediaFilePreviewError, ImageLoadError, MediaFilePreviewError } from './errors';
|
|
9
9
|
import { getAndCacheLocalPreview, getAndCacheRemotePreview, getSSRPreview, isLocalPreview, isRemotePreview, isSSRClientPreview, isSSRDataPreview, isSSRPreview, isSupportedLocalPreview, mediaFilePreviewCache } from './getPreview';
|
|
10
10
|
import { generateScriptProps, getSSRData } from './globalScope';
|
|
11
|
-
import { createRequestDimensions, isBigger, useCurrentValueRef } from './helpers';
|
|
11
|
+
import { createRequestDimensions, isBigger, isWider, useCurrentValueRef } from './helpers';
|
|
12
12
|
// invisible gif for SSR preview to show the underlying spinner until the src is replaced by
|
|
13
13
|
// the actual image src in the inline script
|
|
14
14
|
const DEFAULT_SSR_PREVIEW = {
|
|
@@ -240,7 +240,8 @@ export const useFilePreview = ({
|
|
|
240
240
|
// We always refetch SSR preview to be able to browser-cache a version without the token in the query parameters
|
|
241
241
|
isSSRPreview(preview)) && !skipRemote && upfrontPreviewStatus === 'resolved' && isBackendPreviewReady) {
|
|
242
242
|
// If the preview is SSR, we can skip the refetch as it will be handled by the global scope promise
|
|
243
|
-
|
|
243
|
+
// If the preview is not wider than the requested dimensions, we can skip the refetch
|
|
244
|
+
if (preview && isSSRPreview(preview) && !isWider(preview.dimensions, dimensions) && fg('media-perf-uplift-mutation-fix')) {
|
|
244
245
|
return;
|
|
245
246
|
}
|
|
246
247
|
setIsLoading(true);
|
|
@@ -257,7 +258,7 @@ export const useFilePreview = ({
|
|
|
257
258
|
setIsLoading(false);
|
|
258
259
|
});
|
|
259
260
|
}
|
|
260
|
-
}, [error, nonCriticalError, getAndCacheRemotePreviewRef, identifier.id, resizeMode, isBannedLocalPreview, mediaBlobUrlAttrsRef, preview, requestDimensions, skipRemote, isBackendPreviewReady, localBinary, mediaType, mimeType, upfrontPreviewStatus]);
|
|
261
|
+
}, [error, nonCriticalError, getAndCacheRemotePreviewRef, identifier.id, resizeMode, isBannedLocalPreview, mediaBlobUrlAttrsRef, preview, requestDimensions, skipRemote, isBackendPreviewReady, localBinary, mediaType, mimeType, upfrontPreviewStatus, dimensions]);
|
|
261
262
|
|
|
262
263
|
//----------------------------------------------------------------
|
|
263
264
|
// RETURN
|
package/dist/esm/helpers.js
CHANGED
|
@@ -18,6 +18,14 @@ export var isBigger = function isBigger(current, next) {
|
|
|
18
18
|
return false;
|
|
19
19
|
}
|
|
20
20
|
};
|
|
21
|
+
export var isWider = function isWider(current, next) {
|
|
22
|
+
if (current === undefined && next !== undefined) {
|
|
23
|
+
return true;
|
|
24
|
+
}
|
|
25
|
+
var currentWidth = (current === null || current === void 0 ? void 0 : current.width) || 0;
|
|
26
|
+
var nextWidth = (next === null || next === void 0 ? void 0 : next.width) || 0;
|
|
27
|
+
return currentWidth < nextWidth;
|
|
28
|
+
};
|
|
21
29
|
|
|
22
30
|
/** Verifies if the current screen is retina display */
|
|
23
31
|
function isRetina() {
|
|
@@ -12,7 +12,7 @@ import { createFailedSSRObject, extractErrorInfo } from './analytics';
|
|
|
12
12
|
import { ensureMediaFilePreviewError, ImageLoadError, MediaFilePreviewError } from './errors';
|
|
13
13
|
import { getAndCacheLocalPreview, getAndCacheRemotePreview, getSSRPreview, isLocalPreview, isRemotePreview, isSSRClientPreview, isSSRDataPreview, isSSRPreview, isSupportedLocalPreview, mediaFilePreviewCache } from './getPreview';
|
|
14
14
|
import { generateScriptProps, getSSRData } from './globalScope';
|
|
15
|
-
import { createRequestDimensions, isBigger, useCurrentValueRef } from './helpers';
|
|
15
|
+
import { createRequestDimensions, isBigger, isWider, useCurrentValueRef } from './helpers';
|
|
16
16
|
// invisible gif for SSR preview to show the underlying spinner until the src is replaced by
|
|
17
17
|
// the actual image src in the inline script
|
|
18
18
|
var DEFAULT_SSR_PREVIEW = {
|
|
@@ -262,7 +262,8 @@ export var useFilePreview = function useFilePreview(_ref) {
|
|
|
262
262
|
// We always refetch SSR preview to be able to browser-cache a version without the token in the query parameters
|
|
263
263
|
isSSRPreview(preview)) && !skipRemote && upfrontPreviewStatus === 'resolved' && isBackendPreviewReady) {
|
|
264
264
|
// If the preview is SSR, we can skip the refetch as it will be handled by the global scope promise
|
|
265
|
-
|
|
265
|
+
// If the preview is not wider than the requested dimensions, we can skip the refetch
|
|
266
|
+
if (preview && isSSRPreview(preview) && !isWider(preview.dimensions, dimensions) && fg('media-perf-uplift-mutation-fix')) {
|
|
266
267
|
return;
|
|
267
268
|
}
|
|
268
269
|
setIsLoading(true);
|
|
@@ -279,7 +280,7 @@ export var useFilePreview = function useFilePreview(_ref) {
|
|
|
279
280
|
setIsLoading(false);
|
|
280
281
|
});
|
|
281
282
|
}
|
|
282
|
-
}, [error, nonCriticalError, getAndCacheRemotePreviewRef, identifier.id, resizeMode, isBannedLocalPreview, mediaBlobUrlAttrsRef, preview, requestDimensions, skipRemote, isBackendPreviewReady, localBinary, mediaType, mimeType, upfrontPreviewStatus]);
|
|
283
|
+
}, [error, nonCriticalError, getAndCacheRemotePreviewRef, identifier.id, resizeMode, isBannedLocalPreview, mediaBlobUrlAttrsRef, preview, requestDimensions, skipRemote, isBackendPreviewReady, localBinary, mediaType, mimeType, upfrontPreviewStatus, dimensions]);
|
|
283
284
|
|
|
284
285
|
//----------------------------------------------------------------
|
|
285
286
|
// RETURN
|
package/dist/types/helpers.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ import { type MediaFilePreviewDimensions } from './types';
|
|
|
5
5
|
* If a single dimension is undefined, returns false
|
|
6
6
|
*/
|
|
7
7
|
export declare const isBigger: (current?: MediaFilePreviewDimensions, next?: MediaFilePreviewDimensions) => boolean;
|
|
8
|
+
export declare const isWider: (current?: MediaFilePreviewDimensions, next?: MediaFilePreviewDimensions) => boolean;
|
|
8
9
|
export declare const createRequestDimensions: (dimensions: Partial<MediaFilePreviewDimensions>) => Partial<MediaFilePreviewDimensions> | undefined;
|
|
9
10
|
/** Stores the provided value in a ref object to avoid "component rerenders" when the value is used as a hook dependency */
|
|
10
11
|
export declare function useCurrentValueRef<T>(value: T): MutableRefObject<T>;
|
|
@@ -5,6 +5,7 @@ import { type MediaFilePreviewDimensions } from './types';
|
|
|
5
5
|
* If a single dimension is undefined, returns false
|
|
6
6
|
*/
|
|
7
7
|
export declare const isBigger: (current?: MediaFilePreviewDimensions, next?: MediaFilePreviewDimensions) => boolean;
|
|
8
|
+
export declare const isWider: (current?: MediaFilePreviewDimensions, next?: MediaFilePreviewDimensions) => boolean;
|
|
8
9
|
export declare const createRequestDimensions: (dimensions: Partial<MediaFilePreviewDimensions>) => Partial<MediaFilePreviewDimensions> | undefined;
|
|
9
10
|
/** Stores the provided value in a ref object to avoid "component rerenders" when the value is used as a hook dependency */
|
|
10
11
|
export declare function useCurrentValueRef<T>(value: T): MutableRefObject<T>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/media-file-preview",
|
|
3
|
-
"version": "0.14.
|
|
3
|
+
"version": "0.14.1",
|
|
4
4
|
"description": "A React Hook to fetch and render file previews. It's overloaded with fancy features like SSR, lazy loading, memory cache and local preview.",
|
|
5
5
|
"author": "Atlassian Pty Ltd",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
"@atlaskit/media-common": "^12.3.0",
|
|
36
36
|
"@atlaskit/media-ui": "^28.7.0",
|
|
37
37
|
"@atlaskit/platform-feature-flags": "^1.1.0",
|
|
38
|
-
"@atlaskit/react-ufo": "^4.
|
|
38
|
+
"@atlaskit/react-ufo": "^4.15.0",
|
|
39
39
|
"@babel/runtime": "^7.0.0",
|
|
40
40
|
"eventemitter2": "^4.1.0",
|
|
41
41
|
"lru_map": "^0.4.1"
|