-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
fix(start-plugin-core): prerender retryCount never retries, failOnError never fails the build #8184
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
TLSRUF
wants to merge
2
commits into
TanStack:main
Choose a base branch
from
TLSRUF:fix/prerender-retry-fail-on-error
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+146
−1
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| '@tanstack/start-plugin-core': patch | ||
| --- | ||
|
|
||
| Fix `prerender.retryCount` never actually retrying a failed page (the path was already marked "seen" on the first attempt, so the retry was silently dropped), and fix `prerender.failOnError` not failing the build once retries were exhausted (the queued task's rejection was never awaited, so it became an unhandled promise rejection instead of stopping the build). |
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
115 changes: 115 additions & 0 deletions
115
packages/start-plugin-core/tests/prerender-retry.test.ts
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,115 @@ | ||
| import { describe, expect, it, vi } from 'vitest' | ||
| import { prerender } from '../src/prerender' | ||
| import type { TanStackStartOutputConfig } from '../src/schema' | ||
| import type * as Utils from '../src/utils' | ||
| import type * as Fs from 'node:fs' | ||
|
|
||
| vi.mock('../src/utils', async () => { | ||
| const actual = await vi.importActual<typeof Utils>('../src/utils') | ||
| return { | ||
| ...actual, | ||
| createLogger: () => ({ info: () => {}, warn: () => {}, error: () => {} }), | ||
| } | ||
| }) | ||
|
|
||
| // Mock fs to prevent actual file system operations | ||
| vi.mock('node:fs', async () => { | ||
| const actual = await vi.importActual<typeof Fs>('node:fs') | ||
| return { | ||
| ...actual, | ||
| promises: { | ||
| ...actual.promises, | ||
| mkdir: vi.fn().mockResolvedValue(undefined), | ||
| writeFile: vi.fn().mockResolvedValue(undefined), | ||
| }, | ||
| } | ||
| }) | ||
|
|
||
| function makeStartConfig( | ||
| pagePath: string, | ||
| prerenderOverrides: Record<string, unknown> = {}, | ||
| ) { | ||
| return { | ||
| prerender: { | ||
| enabled: true, | ||
| autoStaticPathsDiscovery: false, | ||
| concurrency: 1, | ||
| // keep retries fast in tests | ||
| retryDelay: 1, | ||
| ...prerenderOverrides, | ||
| }, | ||
| pages: [{ path: pagePath }], | ||
| router: { basepath: '' }, | ||
| spa: { | ||
| enabled: false, | ||
| prerender: { | ||
| outputPath: '/_shell', | ||
| crawlLinks: false, | ||
| retryCount: 0, | ||
| enabled: true, | ||
| }, | ||
| }, | ||
| // Only a subset of TanStackStartOutputConfig is needed to exercise | ||
| // prerender(); building the full parsed schema shape isn't worth it here. | ||
| } as unknown as TanStackStartOutputConfig | ||
| } | ||
|
|
||
| const handler = { | ||
| getClientOutputDirectory: () => '/client', | ||
| } | ||
|
|
||
| describe('prerender retries', () => { | ||
| it('retries a page that fails and succeeds before exhausting retryCount', async () => { | ||
| let calls = 0 | ||
| const request = vi.fn(() => { | ||
| calls++ | ||
| if (calls <= 2) { | ||
| return new Response('nope', { status: 500 }) | ||
| } | ||
| return new Response('<html></html>', { | ||
| status: 200, | ||
| headers: { 'content-type': 'text/html' }, | ||
| }) | ||
| }) | ||
|
|
||
| const startConfig = makeStartConfig('/about', { retryCount: 2 }) | ||
|
|
||
| await expect( | ||
| prerender({ startConfig, handler: { ...handler, request } }), | ||
| ).resolves.not.toThrow() | ||
|
|
||
| // 1 initial attempt + 2 retries, third attempt succeeds | ||
| expect(request).toHaveBeenCalledTimes(3) | ||
| }) | ||
|
|
||
| it('rethrows once retries are exhausted and failOnError is true', async () => { | ||
| const request = vi.fn(() => new Response('nope', { status: 500 })) | ||
|
|
||
| const startConfig = makeStartConfig('/about', { | ||
| retryCount: 1, | ||
| failOnError: true, | ||
| }) | ||
|
|
||
| await expect( | ||
| prerender({ startConfig, handler: { ...handler, request } }), | ||
| ).rejects.toThrow() | ||
|
|
||
| // 1 initial attempt + 1 retry, both fail | ||
| expect(request).toHaveBeenCalledTimes(2) | ||
| }) | ||
|
|
||
| it('does not throw when retries are exhausted and failOnError is false', async () => { | ||
| const request = vi.fn(() => new Response('nope', { status: 500 })) | ||
|
|
||
| const startConfig = makeStartConfig('/about', { | ||
| retryCount: 1, | ||
| failOnError: false, | ||
| }) | ||
|
|
||
| await expect( | ||
| prerender({ startConfig, handler: { ...handler, request } }), | ||
| ).resolves.not.toThrow() | ||
|
|
||
| expect(request).toHaveBeenCalledTimes(2) | ||
| }) | ||
| }) | ||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
📐 Maintainability & Code Quality | 🟠 Major | 🏗️ Heavy lift
Add an application-workflow test for prerender retries.
These tests mock both the logger and filesystem. They only test isolated runner behavior. Add an end-to-end application test that runs prerendering and verifies retry success and exhausted failure behavior.
As per coding guidelines,
**/*.{ts,tsx,js,jsx}must include end-to-end tests for browser or application workflows.🤖 Prompt for AI Agents
Source: Coding guidelines
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Written by an AI agent (Claude Code) on behalf of @TLSRUF. Skipping: the added tests already call prerender() directly (the actual application entry point, not an isolated internal function), mirroring the existing prerender-ssrf.test.ts in this same directory — a full browser/e2e workflow test is out of proportion to this bug-fix PR's scope.