Skip to content

Commit fc2ac76

Browse files
committed
Fix black flicker when rendering canvas
See #1279
1 parent 240150a commit fc2ac76

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

src/Page.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,7 @@ export default function Page(props: PageProps) {
381381
ref={mergeRefs(inputRef, pageElement)}
382382
style={{
383383
['--scale-factor' as string]: `${scale}`,
384+
backgroundColor: canvasBackground || 'white',
384385
position: 'relative',
385386
minWidth: 'min-content',
386387
minHeight: 'min-content',

src/Page/PageCanvas.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ export default function PageCanvas(props: PageCanvasProps) {
105105

106106
canvas.style.width = `${Math.floor(viewport.width)}px`;
107107
canvas.style.height = `${Math.floor(viewport.height)}px`;
108+
canvas.style.visibility = 'hidden';
108109

109110
const renderContext: RenderParameters = {
110111
annotationMode: renderForms ? ANNOTATION_MODE.ENABLE_FORMS : ANNOTATION_MODE.ENABLE,
@@ -120,7 +121,13 @@ export default function PageCanvas(props: PageCanvasProps) {
120121
const cancellable = page.render(renderContext);
121122
const runningTask = cancellable;
122123

123-
cancellable.promise.then(onRenderSuccess).catch(onRenderError);
124+
cancellable.promise
125+
.then(() => {
126+
canvas.style.visibility = '';
127+
128+
onRenderSuccess();
129+
})
130+
.catch(onRenderError);
124131

125132
return () => cancelRunningTask(runningTask);
126133
}

0 commit comments

Comments
 (0)