Repository navigation
feat: add SSG retries option
#8979
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
da29068
fix(router): replace a crashed ssg worker
maiieul 1910eda
fix(router): fail ssg routes that render a 5xx error page
maiieul 3b2b6f2
feat(router): add an ssg retries option
maiieul c273330
feat(router): retry ssg renders that time out
maiieul 2201694
docs(router): document failed ssg renders and retries
maiieul 25e1606
fix(router): drain the ssg queue after a retryable render error
maiieul 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 @@ | ||
| --- | ||
| '@qwik.dev/router': patch | ||
| --- | ||
|
|
||
| fix: a crashed ssg worker no longer stalls the build until it times out |
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 @@ | ||
| --- | ||
| '@qwik.dev/router': patch | ||
| --- | ||
|
|
||
| fix: ssg no longer silently skips routes that render a 5xx error page |
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 @@ | ||
| --- | ||
| '@qwik.dev/router': minor | ||
| --- | ||
|
|
||
| feat: add the ssg `retries` option to re-render a failed route before the build fails |
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 @@ | ||
| { | ||
| "description": "Qwik Router SSG retries fixture", | ||
| "private": true, | ||
| "type": "module" | ||
| } |
13 changes: 13 additions & 0 deletions
13
e2e/qwik-e2e/apps/qwikrouter-ssg-retries/src/entry.ssr.tsx
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,13 @@ | ||
| import { createRenderer } from '@qwik.dev/router'; | ||
| import Root from './root'; | ||
|
|
||
| export default createRenderer((opts) => ({ | ||
| jsx: <Root />, | ||
| options: { | ||
| ...opts, | ||
| containerAttributes: { | ||
| lang: 'en', | ||
| ...opts.containerAttributes, | ||
| }, | ||
| }, | ||
| })); |
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,18 @@ | ||
| import { component$ } from '@qwik.dev/core'; | ||
| import { DocumentHeadTags, RouterOutlet, useQwikRouter } from '@qwik.dev/router'; | ||
|
|
||
| export default component$(() => { | ||
| useQwikRouter(); | ||
|
|
||
| return ( | ||
| <> | ||
| <head> | ||
| <meta charset="utf-8" /> | ||
| <DocumentHeadTags /> | ||
| </head> | ||
| <body> | ||
| <RouterOutlet /> | ||
| </body> | ||
| </> | ||
| ); | ||
| }); |
17 changes: 17 additions & 0 deletions
17
e2e/qwik-e2e/apps/qwikrouter-ssg-retries/src/routes/index.tsx
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,17 @@ | ||
| import { component$ } from '@qwik.dev/core'; | ||
| import { routeLoader$ } from '@qwik.dev/router'; | ||
|
|
||
| export const useFlakyData = routeLoader$(async (requestEvent) => { | ||
| const { existsSync, writeFileSync } = await import('node:fs'); | ||
| const marker = requestEvent.env.get('SSG_RETRIES_MARKER')!; | ||
| if (!existsSync(marker)) { | ||
| writeFileSync(marker, 'failed once'); | ||
| throw requestEvent.error(503, 'Service unavailable'); | ||
| } | ||
| return 'rendered after a retry'; | ||
| }); | ||
|
|
||
| export default component$(() => { | ||
| const data = useFlakyData(); | ||
| return <p>{data.value}</p>; | ||
| }); |
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,80 @@ | ||
| import { expect, test } from '@playwright/test'; | ||
| import { qwikVite } from '@qwik.dev/core/optimizer'; | ||
| import { ssgAdapter } from '@qwik.dev/router/adapters/ssg/vite'; | ||
| import { qwikRouter } from '@qwik.dev/router/vite'; | ||
| import { mkdtemp, readFile, rm } from 'node:fs/promises'; | ||
| import { tmpdir } from 'node:os'; | ||
| import { join, resolve } from 'node:path'; | ||
| import { fileURLToPath } from 'node:url'; | ||
| import { build, createBuilder, type InlineConfig } from 'vite'; | ||
| import tsconfigPaths from 'vite-tsconfig-paths'; | ||
|
|
||
| const __dirname = fileURLToPath(new URL('.', import.meta.url)); | ||
| const repoRoot = resolve(__dirname, '../../../../'); | ||
| const appDir = resolve(repoRoot, 'e2e/qwik-e2e/apps/qwikrouter-ssg-retries'); | ||
| const distDir = resolve(appDir, 'dist'); | ||
| const serverDir = resolve(appDir, 'server'); | ||
|
|
||
| test.describe('router ssg retries', () => { | ||
| // Both tests build into the same `distDir`/`serverDir`, so they must not run in parallel. | ||
| test.describe.configure({ mode: 'serial', timeout: 120_000 }); | ||
|
|
||
| test.skip(({ browserName }) => browserName !== 'chromium', 'Runs once in Chromium e2e.'); | ||
|
|
||
| test('fails the build when the route fails and retries are off', async () => { | ||
| await expect(buildFixtureApp({ retries: 0 })).rejects.toThrow( | ||
| 'At least one path failed to render' | ||
| ); | ||
| }); | ||
|
|
||
| test('re-renders a route that failed once when retries are enabled', async () => { | ||
| await buildFixtureApp({ retries: 1 }); | ||
|
|
||
| const html = await readFile(resolve(distDir, 'index.html'), 'utf-8'); | ||
| expect(html).toContain('rendered after a retry'); | ||
| }); | ||
| }); | ||
|
|
||
| async function buildFixtureApp({ retries }: { retries: number }) { | ||
| await rm(distDir, { recursive: true, force: true }); | ||
| await rm(serverDir, { recursive: true, force: true }); | ||
| const markerDir = await mkdtemp(join(tmpdir(), 'qwik-router-ssg-retries-')); | ||
| process.env.SSG_RETRIES_MARKER = join(markerDir, 'failed-once'); | ||
|
|
||
| const getConfig = (extra?: InlineConfig): InlineConfig => ({ | ||
| root: appDir, | ||
| mode: 'production', | ||
| configFile: false, | ||
| clearScreen: false, | ||
| logLevel: 'error', | ||
| ...extra, | ||
| }); | ||
|
|
||
| try { | ||
| await build( | ||
| getConfig({ | ||
| plugins: [ | ||
| qwikRouter(), | ||
| tsconfigPaths({ root: '.' }), | ||
| qwikVite({ tsOptimizer: true, client: { outDir: distDir } }), | ||
| ], | ||
| }) | ||
| ); | ||
|
|
||
| const builder = await createBuilder( | ||
| getConfig({ | ||
| build: { ssr: true, outDir: serverDir }, | ||
| plugins: [ | ||
| qwikRouter(), | ||
| tsconfigPaths({ root: '.' }), | ||
| qwikVite({ tsOptimizer: true }), | ||
| ssgAdapter({ origin: 'https://retries.qwik.dev', include: ['/*'], retries }), | ||
| ], | ||
| }) | ||
| ); | ||
| await builder.buildApp(); | ||
| } finally { | ||
| delete process.env.SSG_RETRIES_MARKER; | ||
| await rm(markerDir, { recursive: true, force: true }); | ||
| } | ||
| } |
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
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.