This commit is contained in:
David Nguyen
2026-02-26 14:32:28 +11:00
parent 6425b242f0
commit 18d092f415
3 changed files with 14 additions and 7 deletions
@@ -262,8 +262,6 @@ test.describe('PDF Viewer Rendering', () => {
await fileChooser.setFiles(path.join(__dirname, '../../../../assets/example.pdf')); await fileChooser.setFiles(path.join(__dirname, '../../../../assets/example.pdf'));
await page.waitForTimeout(2000);
await page.getByRole('button', { name: 'Continue' }).click(); await page.getByRole('button', { name: 'Continue' }).click();
await expect(page.locator(PDF_PAGE_SELECTOR).first()).toBeVisible({ timeout: 30_000 }); await expect(page.locator(PDF_PAGE_SELECTOR).first()).toBeVisible({ timeout: 30_000 });
@@ -91,10 +91,19 @@ export const useFieldPageCoords = (
const mutationObserver = new MutationObserver(() => { const mutationObserver = new MutationObserver(() => {
const $page = document.querySelector<HTMLElement>(pageSelector); const $page = document.querySelector<HTMLElement>(pageSelector);
if ($page) { if (!$page) {
calculateCoords(); return;
attachResizeObserver($page);
} }
// Only recalculate when the observed page element has changed (e.g. new
// element appeared after virtual list scroll). Skip when mutations are
// from elsewhere in the DOM and the page element is unchanged.
if ($page === observedElement) {
return;
}
calculateCoords();
attachResizeObserver($page);
}); });
mutationObserver.observe(document.body, { mutationObserver.observe(document.body, {
@@ -61,8 +61,8 @@ export const usePageRenderer = (renderFunction: RenderFunction, pageData: PageRe
const imageProps = useMemo( const imageProps = useMemo(
(): React.ImgHTMLAttributes<HTMLImageElement> & Record<string, unknown> & { alt: '' } => ({ (): React.ImgHTMLAttributes<HTMLImageElement> & Record<string, unknown> & { alt: '' } => ({
className: PDF_VIEWER_PAGE_CLASSNAME, className: PDF_VIEWER_PAGE_CLASSNAME,
width: `${Math.floor(scaledViewport.width)}px`, width: Math.floor(scaledViewport.width),
height: `${Math.floor(scaledViewport.height)}px`, height: Math.floor(scaledViewport.height),
alt: '', alt: '',
onLoad: () => setRenderStatus('loaded'), onLoad: () => setRenderStatus('loaded'),
// Purposely not using lazy here since we can use the virtual list overscan to let us prerender images. // Purposely not using lazy here since we can use the virtual list overscan to let us prerender images.