fix(pdf): resolve rendering timeout by switching to domcontentloaded strategy#804
Open
Frankli9986 wants to merge 1 commit into
Open
fix(pdf): resolve rendering timeout by switching to domcontentloaded strategy#804Frankli9986 wants to merge 1 commit into
Frankli9986 wants to merge 1 commit into
Conversation
…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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #799
Problem
PDF download fails with a 30-second timeout when
page.goto()waits fornetworkidlein Next.js dev mode. Thenetworkidlestrategy 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.readywrapped intry/exceptwithtimeout=10000and warning logWhy
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:
logger.warning()for font loading failures: Silently swallowing font exceptions withexcept Exception: passmakes production debugging difficult. The warning log allows operators to detect font issues without blocking PDF generation.Testing
Summary by cubic
Switch PDF rendering to wait for DOMContentLoaded to avoid 30s timeouts in dev (notably on Windows 11 with Turbopack). Fixes #799.
page.goto(..., wait_until="domcontentloaded", timeout=15000)to avoidnetworkidlehangs.timeout=10000topage.wait_for_selector(...)for fail-fast behavior.document.fonts.readywith a 10s timeout and log a warning on failure (non-blocking).Written for commit 6cf8ed3. Summary will update on new commits. Review in cubic