Bug 1618371 Comment 9 Edit History

Note: The actual edited comment in the bug view page will always show the original commenter’s name and original timestamp.

We got a report in https://github.com/webcompat/web-bugs/issues/49932 

When attempting to print pdfJsPrint() is called in PreviewPane component:
```js
 function PreviewPane(props: PreviewPaneProps, ref: React.Ref<PreviewPaneHandle>) {
        React.useImperativeHandle(
            ref,
            () => ({
                ...
                ...
                pdfJsPrint() {
                    if (pdfJsPreview.current) {
                        pdfJsPreview.current.print();
                    }
                },
            }),
            []
        );
```
Doesn't seem like pdfJsPreview ref is working as expected as pdfJsPreview.current is undefined
in this condition:
```js
if (pdfJsPreview.current) {
     pdfJsPreview.current.print();
}
```
This component is getting the ref:

```js
const imagePreview = React.useRef<ImagePreviewHandle>();
const pdfJsPreview = React.useRef<PdfJsPreviewPrintable>();
const renderPreviewContent = () => {
            const className = styles.contentPreview;
            switch (props.viewState.previewPane.mode) {
              ...
                case PreviewPaneMode.PdfJs:
                    return (
                        <PdfJsPreview
                            className={className}
                            onError={onError}
                            onLoad={onLoad}
                            viewState={props.viewState.previewPane}
                            ref={pdfJsPreview}
                        />
                    );
            ...
            }
        };
```
and the following function is responsible for initiating printing, however it never gets here:

```js
    function PdfJsPreview(props: PdfJsPreviewProps, ref: React.Ref<PdfJsPreviewPrintable>) {
        React.useImperativeHandle(
            ref,
            () => ({
                print() {
                    printPdf(currentPdf.current, viewer.current);
                },
            }),
            []
        );
```
Seems to be that missing ref is the reason, I'll investigate further
We've got a report in https://github.com/webcompat/web-bugs/issues/49932 

When attempting to print pdfJsPrint() is called in PreviewPane component:
```js
 function PreviewPane(props: PreviewPaneProps, ref: React.Ref<PreviewPaneHandle>) {
        React.useImperativeHandle(
            ref,
            () => ({
                ...
                ...
                pdfJsPrint() {
                    if (pdfJsPreview.current) {
                        pdfJsPreview.current.print();
                    }
                },
            }),
            []
        );
```
Doesn't seem like pdfJsPreview ref is working as expected as pdfJsPreview.current is undefined
in this condition:
```js
if (pdfJsPreview.current) {
     pdfJsPreview.current.print();
}
```
This component is getting the ref:

```js
const imagePreview = React.useRef<ImagePreviewHandle>();
const pdfJsPreview = React.useRef<PdfJsPreviewPrintable>();
const renderPreviewContent = () => {
            const className = styles.contentPreview;
            switch (props.viewState.previewPane.mode) {
              ...
                case PreviewPaneMode.PdfJs:
                    return (
                        <PdfJsPreview
                            className={className}
                            onError={onError}
                            onLoad={onLoad}
                            viewState={props.viewState.previewPane}
                            ref={pdfJsPreview}
                        />
                    );
            ...
            }
        };
```
and the following function is responsible for initiating printing, however it never gets here:

```js
    function PdfJsPreview(props: PdfJsPreviewProps, ref: React.Ref<PdfJsPreviewPrintable>) {
        React.useImperativeHandle(
            ref,
            () => ({
                print() {
                    printPdf(currentPdf.current, viewer.current);
                },
            }),
            []
        );
```
Seems to be that missing ref is the reason, I'll investigate further

Back to Bug 1618371 Comment 9