Skip to content

fix(pdf): resolve rendering timeout by switching to domcontentloaded strategy#804

Open
Frankli9986 wants to merge 1 commit into
srbhr:mainfrom
Frankli9986:fix-799-pdf-rendering-timeout
Open

fix(pdf): resolve rendering timeout by switching to domcontentloaded strategy#804
Frankli9986 wants to merge 1 commit into
srbhr:mainfrom
Frankli9986:fix-799-pdf-rendering-timeout

Conversation

@Frankli9986

@Frankli9986 Frankli9986 commented May 21, 2026

Copy link
Copy Markdown
Contributor

Fixes #799

Problem

PDF download fails with a 30-second timeout when page.goto() waits for networkidle in Next.js dev mode. The networkidle strategy is too strict for static print pages — Web Fonts, HMR WebSocket connections, and other resources keep the network active, causing Playwright to hang until the default 30s timeout expires.

This is particularly problematic on Windows 11 with Turbopack, where font loading and dev-mode resources create sustained network activity.

Changes

  • page.goto(url, wait_until="networkidle")page.goto(url, wait_until="domcontentloaded", timeout=15000)
  • page.wait_for_selector(selector)page.wait_for_selector(selector, timeout=10000)
  • document.fonts.ready wrapped in try/except with timeout=10000 and warning log

Why domcontentloaded?

PDF rendering is a static snapshot operation. It only needs the DOM tree to be ready — it does not require all async resources (fonts, analytics, HMR) to finish loading. This aligns with the 10-15s target mentioned in #799.

Comparison with #800

PR #800 (by @vinsmokejazz) proposed a similar fix. This PR builds on that approach with one additional improvement:

  • Added logger.warning() for font loading failures: Silently swallowing font exceptions with except Exception: pass makes production debugging difficult. The warning log allows operators to detect font issues without blocking PDF generation.

Testing

  • Resume PDF download completes within 10-15 seconds
  • PDF quality unchanged
  • Font loading warning appears in logs when fonts fail (non-blocking)

Summary by cubic

Switch PDF rendering to wait for DOMContentLoaded to avoid 30s timeouts in dev (notably on Windows 11 with Turbopack). Fixes #799.

  • Bug Fixes
    • Change page.goto(..., wait_until="domcontentloaded", timeout=15000) to avoid networkidle hangs.
    • Add timeout=10000 to page.wait_for_selector(...) for fail-fast behavior.
    • Wrap document.fonts.ready with a 10s timeout and log a warning on failure (non-blocking).

Written for commit 6cf8ed3. Summary will update on new commits. Review in cubic

…strategy

Fixes srbhr#799

- Change wait_until from "networkidle" to "domcontentloaded" with 15s timeout
  to avoid hangs caused by ongoing font/resource loading in dev mode
- Add explicit 10s timeout to wait_for_selector for fail-fast behavior
- Wrap document.fonts.ready in try/except with 10s timeout and warning log
  so font loading issues don't block PDF generation

This resolves the 30-second timeout error on Windows 11 when downloading
resumes as PDF in Next.js dev mode with Turbopack.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

No issues found across 1 file

Re-trigger cubic

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: PDF rendering timeout issue

1 participant