Skip to content

Commit c5e10aa

Browse files
committed
[Bugfix] viewer freezes when switching document (#8820)
1 parent bee7dd6 commit c5e10aa

File tree

2 files changed

+128
-0
lines changed

2 files changed

+128
-0
lines changed

src/helpers/TabManager.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ export default class TabManager {
156156
return console.error(`Tab id not found: ${id}`);
157157
}
158158
if (currentTab) {
159+
await core.getDocumentViewer().getAnnotationManager().exportAnnotations();
159160
await core.getDocumentViewer().getAnnotationsLoadedPromise();
160161
}
161162
fireEvent(Events['BEFORE_TAB_CHANGED'], {

tests/ui/tab-manager.test.js

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
import { expect } from 'chai';
2+
import { setupWebViewerInstance, delay } from '../../utils/TestingUtils';
3+
4+
describe('Tab Manager UI Tests', function() {
5+
this.timeout(10000);
6+
let viewerDiv;
7+
8+
beforeEach(async () => {
9+
// Create a new div with an ID and add it to the body before each test
10+
viewerDiv = document.createElement('div');
11+
viewerDiv.id = 'viewerDiv';
12+
document.body.appendChild(viewerDiv);
13+
});
14+
15+
afterEach(() => {
16+
// Clean up the div after each test
17+
document.body.removeChild(viewerDiv);
18+
});
19+
20+
it('Test closing tab with enabled warning modal', async () => {
21+
const options = {
22+
initialDoc: ['https://pdftron.s3.amazonaws.com/downloads/pl/demo-annotated.pdf', '/base/test/fixtures/pdfs/large-number-annotations.pdf'],
23+
fullAPI: true,
24+
};
25+
const instance = await setupWebViewerInstance(options);
26+
const { annotationManager } = instance.Core;
27+
28+
const documentLoadedPromise = new Promise((resolve) => {
29+
instance.UI.addEventListener('documentLoaded', resolve);
30+
});
31+
await documentLoadedPromise;
32+
33+
const annot = new instance.Core.Annotations.RectangleAnnotation({
34+
PageNumber: 1,
35+
X: 50,
36+
Y: 100,
37+
Width: 150,
38+
Height: 100,
39+
});
40+
41+
annotationManager.addAnnotation(annot);
42+
annotationManager.redrawAnnotation(annot);
43+
44+
instance.UI.TabManager.deleteTab(0);
45+
46+
await delay(1000);
47+
const iframeWindow = instance.UI.iframeWindow;
48+
49+
const warningModal = iframeWindow.document.querySelector('[aria-label="Close without downloading?"]');
50+
expect(warningModal, 'Expecting a Warning Modal').to.not.be.null;
51+
});
52+
53+
it('Test closing tab with disabled warning modal', async () => {
54+
const options = {
55+
initialDoc: ['https://pdftron.s3.amazonaws.com/downloads/pl/demo-annotated.pdf', '/base/test/fixtures/pdfs/large-number-annotations.pdf'],
56+
fullAPI: true,
57+
};
58+
const instance = await setupWebViewerInstance(options);
59+
const { annotationManager } = instance.Core;
60+
instance.UI.disableFeatures([instance.UI.Feature.Download]);
61+
const documentLoadedPromise = new Promise((resolve) => {
62+
instance.UI.addEventListener('documentLoaded', resolve);
63+
});
64+
await documentLoadedPromise;
65+
66+
const annot = new instance.Core.Annotations.RectangleAnnotation({
67+
PageNumber: 1,
68+
X: 50,
69+
Y: 100,
70+
Width: 150,
71+
Height: 100,
72+
});
73+
74+
annotationManager.addAnnotation(annot);
75+
annotationManager.redrawAnnotation(annot);
76+
77+
instance.UI.TabManager.deleteTab(0);
78+
79+
await delay(1000);
80+
const iframeWindow = instance.UI.iframeWindow;
81+
82+
const warningModal = iframeWindow.document.querySelector('[aria-label="Close without downloading?"]');
83+
expect(warningModal, 'Expecting no Warning Modal should appear').to.be.null;
84+
});
85+
86+
it('Export XFDF on beforeTabChanged event', async () => {
87+
const options = {
88+
initialDoc: ['/base/test/fixtures/pdfs/VirtualizedAnnotTest.pdf', 'https://pdftron.s3.amazonaws.com/downloads/pl/demo-annotated.pdf'],
89+
fullAPI: true,
90+
};
91+
const instance = await setupWebViewerInstance(options);
92+
const { UI } = instance;
93+
let resultXFDF;
94+
const documentLoadedPromise = new Promise((resolve) => {
95+
UI.addEventListener('documentLoaded', resolve);
96+
});
97+
await documentLoadedPromise;
98+
99+
UI.addEventListener('beforeTabChanged', async () => {
100+
resultXFDF = await instance.Core.documentViewer.getAnnotationManager().exportAnnotations();
101+
});
102+
103+
await UI.TabManager.setActiveTab(1);
104+
await delay(1000);
105+
expect(resultXFDF).to.not.be.undefined;
106+
});
107+
108+
it('Switching between tabs with a big file won\'t cause lag', async () => {
109+
const options = {
110+
initialDoc: ['/base/test/fixtures/pdfs/semi-big-file.pdf', 'https://pdftron.s3.amazonaws.com/downloads/pl/demo-annotated.pdf'],
111+
fullAPI: true,
112+
};
113+
const instance = await setupWebViewerInstance(options);
114+
const { UI } = instance;
115+
116+
const documentLoadedPromise = new Promise((resolve) => {
117+
UI.addEventListener('documentLoaded', resolve);
118+
});
119+
await documentLoadedPromise;
120+
121+
await UI.TabManager.setActiveTab(1);
122+
123+
await delay(2000);
124+
const activeTab = UI.TabManager.getActiveTab();
125+
expect(activeTab.options.filename).to.equal('demo-annotated.pdf');
126+
});
127+
})

0 commit comments

Comments
 (0)