Skip to content

Commit df50ff5

Browse files
committed
Allow for disabling the preview screenshot
1 parent 7442227 commit df50ff5

File tree

2 files changed

+16
-11
lines changed

2 files changed

+16
-11
lines changed

packages/app/src/embed/components/Content/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,7 @@ export default class Content extends React.PureComponent<Props, State> {
454454
onToggleProjectView={this.onToggleProjectView}
455455
onResize={this.handleResize}
456456
dragging={this.state.dragging}
457+
showScreenshotOverlay
457458
/>
458459
),
459460
actions: [],

packages/common/src/components/Preview/index.tsx

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@ export type Props = {
4949
delay?: number;
5050
className?: string;
5151
overlayMessage?: string;
52+
/**
53+
* Whether to show a screenshot in the preview as a "placeholder" while loading
54+
* to reduce perceived loading time
55+
*/
56+
showScreenshotOverlay?: boolean;
5257
};
5358

5459
type State = {
@@ -90,7 +95,7 @@ class BasePreview extends React.Component<Props, State> {
9095
url: initialUrl,
9196
forward: false,
9297
back: false,
93-
showScreenshot: true,
98+
showScreenshot: props.showScreenshotOverlay,
9499
useFallbackDomain: false,
95100
};
96101

@@ -104,7 +109,14 @@ class BasePreview extends React.Component<Props, State> {
104109
// Remove screenshot after specific time, so the loading container spinner can still show
105110
this.setState({ showScreenshot: false });
106111
}, 100);
112+
} else {
113+
setTimeout(() => {
114+
if (this.state.showScreenshot) {
115+
this.setState({ showScreenshot: false });
116+
}
117+
}, 800);
107118
}
119+
108120
this.listener = listen(this.handleMessage);
109121

110122
if (props.delay) {
@@ -114,12 +126,6 @@ class BasePreview extends React.Component<Props, State> {
114126
(window as any).openNewWindow = this.openNewWindow;
115127

116128
this.testFallbackDomainIfNeeded();
117-
118-
setTimeout(() => {
119-
if (this.state.showScreenshot) {
120-
this.setState({ showScreenshot: false });
121-
}
122-
}, 800);
123129
}
124130

125131
UNSAFE_componentWillUpdate(nextProps: Props, nextState: State) {
@@ -556,7 +562,7 @@ class BasePreview extends React.Component<Props, State> {
556562
{overlayMessage && <Loading>{overlayMessage}</Loading>}
557563

558564
<AnySpring
559-
from={{ opacity: 0 }}
565+
from={{ opacity: this.props.showScreenshotOverlay ? 0 : 1 }}
560566
to={{
561567
opacity: this.state.showScreenshot ? 0 : 1,
562568
}}
@@ -602,9 +608,7 @@ class BasePreview extends React.Component<Props, State> {
602608
height: '100%',
603609
filter: `blur(2px)`,
604610
transform: 'scale(1.025, 1.025)',
605-
backgroundImage: `url("${
606-
this.props.sandbox.screenshotUrl
607-
}")`,
611+
backgroundImage: `url("${this.props.sandbox.screenshotUrl}")`,
608612
backgroundRepeat: 'no-repeat',
609613
backgroundPositionX: 'center',
610614
}}

0 commit comments

Comments
 (0)