Skip to content

fix(prerender): ensure failed prerenders are retried#7803

Open
wildlyinaccurate wants to merge 1 commit into
TanStack:mainfrom
wildlyinaccurate:fix/prerender-retry-noop
Open

fix(prerender): ensure failed prerenders are retried#7803
wildlyinaccurate wants to merge 1 commit into
TanStack:mainfrom
wildlyinaccurate:fix/prerender-retry-noop

Conversation

@wildlyinaccurate

@wildlyinaccurate wildlyinaccurate commented Jul 13, 2026

Copy link
Copy Markdown

Right now if a page fails to prerender, it is not retried. I see things like this in my logs:

[prerender] Crawling: /site/klg75hzo
[prerender] Encountered error, retrying: /site/klg75hzo in 10000ms

but that URL /site/klg75hzo is never retried.

Summary by CodeRabbit

  • Bug Fixes
    • Improved prerendering retry behavior so page requests are retried until a successful response is received or the configured retry limit is reached.
    • Collected asynchronous queue task failures and surfaced the first relevant error after prerender completes.
    • Maintained existing error-handling semantics, including failOnError: false stopping retries without throwing.
  • Tests
    • Added Vitest coverage for retry success, retry-limit stop behavior, and promise rejection/throwing based on failOnError.

@coderabbitai

coderabbitai Bot commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 5df01d2a-b28f-4f4e-9776-a0361f3206a6

📥 Commits

Reviewing files that changed from the base of the PR and between 8bcd97e and e87c462.

📒 Files selected for processing (2)
  • packages/start-plugin-core/src/prerender.ts
  • packages/start-plugin-core/tests/prerender-retry.test.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • packages/start-plugin-core/tests/prerender-retry.test.ts
  • packages/start-plugin-core/src/prerender.ts

📝 Walkthrough

Walkthrough

prerenderPages now uses a named renderPage task for initial rendering and retries, captures queue failures, and rethrows them after settlement. Tests verify eventual success and configured retry exhaustion behavior.

Changes

Prerender retry scheduling

Layer / File(s) Summary
Render and retry flow
packages/start-plugin-core/src/prerender.ts
Extracts page rendering into renderPage, preserves output generation and link crawling, directly queues retries, and rethrows collected queue errors after completion.
Retry behavior validation
packages/start-plugin-core/tests/prerender-retry.test.ts
Mocks filesystem and logging operations and verifies successful retries, non-throwing exhaustion, and rejection after retries are exhausted.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant prerenderPages
  participant Queue
  participant renderPage
  participant handler.request
  prerenderPages->>Queue: schedule renderPage(page)
  Queue->>renderPage: execute page task
  renderPage->>handler.request: request page with redirects
  renderPage->>Queue: requeue renderPage(page) when retries remain
  Queue-->>prerenderPages: report task error
  prerenderPages->>Queue: await queue settlement
  prerenderPages-->>prerenderPages: rethrow first collected error
Loading
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: fixing prerender retries for failed pages.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai 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.

Actionable comments posted: 1

🧹 Nitpick comments (2)
packages/start-plugin-core/tests/prerender-retry.test.ts (2)

4-22: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

any usage and as any casts weaken type safety.

vi.importActual<any>(...) and the as any cast on makeStartConfig's return bypass type checking entirely for startConfig. As per coding guidelines, **/*.{ts,tsx} should use TypeScript strict mode with extensive type safety. This is a common/pragmatic tradeoff for test mocks, so treat as optional.

Also applies to: 38-62

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/start-plugin-core/tests/prerender-retry.test.ts` around lines 4 -
22, Replace the `vi.importActual<any>` usages in the `utils` and `node:fs` mocks
with appropriately typed imports or inferred types, and remove the `as any` cast
from `makeStartConfig` while preserving the mocked APIs and test behavior. Keep
the changes limited to improving type safety in these test mocks.

Source: Coding guidelines


64-107: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Missing coverage for the failOnError: true (default) exhaustion path.

Both tests avoid the scenario where retries are exhausted with failOnError at its default (true). Given the propagation concerns raised in prerender.ts (whether prerender() actually rejects/throws when a page permanently fails), a test asserting await expect(prerender(...)).rejects.toThrow() for that case would directly validate (or expose) that behavior.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/start-plugin-core/tests/prerender-retry.test.ts` around lines 64 -
107, The prerender retry tests lack coverage for exhausted retries with the
default failOnError behavior. Add a test alongside the existing cases using a
permanently failing request, retryCount: 2, and retryDelay: 0 without setting
failOnError: false; assert that prerender rejects with an error and that the
request mock is called three times.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/start-plugin-core/src/prerender.ts`:
- Around line 217-230: Collect task failures in the prerender flow around
queue.add and queue.start instead of relying on the current throw inside
renderPage. Capture queue errors via queue.onError/onSettled or handled
queue.add promises, await queue.start(), then rethrow the collected error when
failOnError is enabled, while preserving retry scheduling and preventing
unhandled rejections.

---

Nitpick comments:
In `@packages/start-plugin-core/tests/prerender-retry.test.ts`:
- Around line 4-22: Replace the `vi.importActual<any>` usages in the `utils` and
`node:fs` mocks with appropriately typed imports or inferred types, and remove
the `as any` cast from `makeStartConfig` while preserving the mocked APIs and
test behavior. Keep the changes limited to improving type safety in these test
mocks.
- Around line 64-107: The prerender retry tests lack coverage for exhausted
retries with the default failOnError behavior. Add a test alongside the existing
cases using a permanently failing request, retryCount: 2, and retryDelay: 0
without setting failOnError: false; assert that prerender rejects with an error
and that the request mock is called three times.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 317def34-292c-457b-8027-d20ce61ff9d2

📥 Commits

Reviewing files that changed from the base of the PR and between 41f7bf3 and 8dcd787.

📒 Files selected for processing (2)
  • packages/start-plugin-core/src/prerender.ts
  • packages/start-plugin-core/tests/prerender-retry.test.ts

Comment thread packages/start-plugin-core/src/prerender.ts
@wildlyinaccurate wildlyinaccurate force-pushed the fix/prerender-retry-noop branch from 8dcd787 to 8bcd97e Compare July 13, 2026 02:25
@wildlyinaccurate

Copy link
Copy Markdown
Author

Fixes from CodeRabbit's first review have been applied and squashed.

@wildlyinaccurate wildlyinaccurate force-pushed the fix/prerender-retry-noop branch from 8bcd97e to e87c462 Compare July 14, 2026 08:19
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.

1 participant