ngx-extended-pdf-viewer
ngx-extended-pdf-viewer copied to clipboard
PDFScriptLoaderService fails to properly load the pdfjs viewer after destroyed.
Here is a tricky one.... I noticed that when running >v21, component tests started breaking. After quick a bit of investigation I'm pretty sure I've narrowed down the issue to the changes introduced in 21.0.0-alpha.0. Here is the breakdown:
21.0.0-alpha.0 introduces PDFScriptLoaderService
which loads the pdfjs viewer inside the loadViewer
method. The loadViewer
method relies on the ngxViewerFileHasBeenLoaded
event being triggered when loading the viewer mjs
file. This works fine on initial load since the mjs
file includes the event trigger. However, in unit/component testing the Angular app is destroyed and the PDFScriptLoaderService#destroy
method is called to cleanup. The Angular app is then "rebooted" in the same window. But since the viewer is loaded as a module, it is not executed again (ES modules are loaded once and reused). The ngxViewerFileHasBeenLoaded
event is never triggered and therefore the pdfjs is never initailzed.
Seams like we need a different way to trigger the listener inside loadViewer
that doesn't rely on side effects inside the module.
I've only seen this in testing; since a app usually has the same lifecycle as the document/window.