Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pdfjs black flicker #1279

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion src/Page/PageCanvas.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,22 @@ export class PageCanvasInternal extends PureComponent {
}
}

hideCanvas = () => {
this.setCanvasVisible(false);
};

showCanvas = () => {
this.setCanvasVisible(true);
};

setCanvasVisible = (visible) => {
const { current: canvas } = this.canvasElement;

if (canvas) {
canvas.style.visibility = visible ? 'visible' : 'hidden';
}
};

/**
* Called when a page is rendered successfully.
*/
Expand Down Expand Up @@ -109,6 +125,9 @@ export class PageCanvasInternal extends PureComponent {
const { renderViewport, viewport } = this;
const { canvasBackground, page, renderForms } = this.props;

// Hiding the canvas on redraw ensures we get rid of black flickering
this.hideCanvas();

canvas.width = renderViewport.width;
canvas.height = renderViewport.height;

Expand All @@ -132,7 +151,13 @@ export class PageCanvasInternal extends PureComponent {
const cancellable = page.render(renderContext);
this.renderer = cancellable;

return cancellable.promise.then(this.onRenderSuccess).catch(this.onRenderError);
return (
cancellable.promise
// Show the canvas on success and on errors
.then(this.onRenderSuccess)
.catch(this.onRenderError)
.finally(this.showCanvas)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In our fork we actually implemented the following and can confirm it works. However I noticed it failed a test so I changed it to finally, which I believe should have the same effect barring a little different timing.

.then(this.showCanvas, this.showCanvas)
.then(this.onRenderSuccess)
.catch(this.onRenderError)

);
};

render() {
Expand All @@ -144,6 +169,7 @@ export class PageCanvasInternal extends PureComponent {
dir="ltr"
ref={mergeRefs(canvasRef, this.canvasElement)}
style={{
visibility: 'hidden',
display: 'block',
userSelect: 'none',
}}
Expand Down