-
-
Notifications
You must be signed in to change notification settings - Fork 124
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduces a `--partial` flag that will skip rendering of already existing static RSC and HTML files. ## Use case Content updates of larger static sites should not re-render every page. ## Notes * Consciously avoids dealing with deleting files (cache invalidation). I think this can be solved much better with userland domain knowledge. * Bundle builds should probably be skipped as well, but are too tangled at this point. At least they don't scale with the amount of static pages. --------- Co-authored-by: Daishi Kato <[email protected]>
- Loading branch information
Showing
10 changed files
with
192 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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 @@ | ||
# Partial builds for static websites |
This file contains 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,24 @@ | ||
{ | ||
"name": "partial-build", | ||
"version": "0.1.0", | ||
"type": "module", | ||
"private": true, | ||
"scripts": { | ||
"dev": "waku dev", | ||
"build": "waku build", | ||
"start": "waku start", | ||
"partial": "waku build --experimental-partial" | ||
}, | ||
"dependencies": { | ||
"react": "19.0.0-beta-4508873393-20240430", | ||
"react-dom": "19.0.0-beta-4508873393-20240430", | ||
"react-server-dom-webpack": "19.0.0-beta-4508873393-20240430", | ||
"waku": "workspace:*", | ||
"serve": "^14.2.3" | ||
}, | ||
"devDependencies": { | ||
"@types/react": "18.3.1", | ||
"@types/react-dom": "18.3.0", | ||
"typescript": "5.4.4" | ||
} | ||
} |
This file contains 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,9 @@ | ||
export default function HomePage() { | ||
return <div>Home</div>; | ||
} | ||
|
||
export async function getConfig() { | ||
return { | ||
render: 'static', | ||
}; | ||
} |
This file contains 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,12 @@ | ||
import { getEnv } from 'waku/server'; | ||
|
||
export default function Test({ title }: { title: string }) { | ||
return <div data-testid="title">{title}</div>; | ||
} | ||
|
||
export async function getConfig() { | ||
return { | ||
render: 'static', | ||
staticPaths: getEnv('PAGES')?.split(',') || [], | ||
}; | ||
} |
This file contains 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 @@ | ||
{ | ||
"compilerOptions": { | ||
"composite": true, | ||
"strict": true, | ||
"target": "esnext", | ||
"downlevelIteration": true, | ||
"esModuleInterop": true, | ||
"module": "nodenext", | ||
"skipLibCheck": true, | ||
"noUncheckedIndexedAccess": true, | ||
"exactOptionalPropertyTypes": true, | ||
"types": ["react/experimental"], | ||
"jsx": "react-jsx", | ||
"rootDir": "./src", | ||
"outDir": "./dist" | ||
} | ||
} |
This file contains 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,76 @@ | ||
import { execSync, exec, ChildProcess } from 'node:child_process'; | ||
import { fileURLToPath } from 'node:url'; | ||
import waitPort from 'wait-port'; | ||
import { getFreePort, terminate, test } from './utils.js'; | ||
import { rm } from 'node:fs/promises'; | ||
import { expect } from '@playwright/test'; | ||
import { statSync } from 'fs'; | ||
|
||
const cwd = fileURLToPath(new URL('./fixtures/partial-build', import.meta.url)); | ||
|
||
const waku = fileURLToPath( | ||
new URL('../packages/waku/dist/cli.js', import.meta.url), | ||
); | ||
|
||
test.describe(`partial builds`, () => { | ||
test.skip( | ||
({ browserName }) => browserName !== 'chromium', | ||
'Browsers are not relevant for this test. One is enough.', | ||
); | ||
|
||
let cp: ChildProcess; | ||
let port: number; | ||
|
||
test.beforeEach(async ({ page }) => { | ||
await rm(`${cwd}/dist`, { | ||
recursive: true, | ||
force: true, | ||
}); | ||
execSync(`node ${waku} build`, { | ||
cwd, | ||
env: { ...process.env, PAGES: 'a' }, | ||
}); | ||
port = await getFreePort(); | ||
cp = exec(`node ${waku} start --port ${port}`, { cwd }); | ||
await waitPort({ port }); | ||
await page.goto(`http://localhost:${port}/page/a`); | ||
expect(await page.getByTestId('title').textContent()).toBe('a'); | ||
}); | ||
|
||
test('does not change pages that already exist', async () => { | ||
const htmlBefore = statSync(`${cwd}/dist/public/page/a/index.html`); | ||
const rscBefore = statSync(`${cwd}/dist/public/RSC/page/a.txt`); | ||
execSync(`node ${waku} build --experimental-partial`, { | ||
cwd, | ||
env: { ...process.env, PAGES: 'a,b' }, | ||
}); | ||
const htmlAfter = statSync(`${cwd}/dist/public/page/a/index.html`); | ||
const rscAfter = statSync(`${cwd}/dist/public/RSC/page/a.txt`); | ||
expect(htmlBefore.mtimeMs).toBe(htmlAfter.mtimeMs); | ||
expect(rscBefore.mtimeMs).toBe(rscAfter.mtimeMs); | ||
}); | ||
|
||
test('adds new pages', async ({ page }) => { | ||
execSync(`node ${waku} build --experimental-partial`, { | ||
cwd, | ||
env: { ...process.env, PAGES: 'a,b' }, | ||
}); | ||
await page.goto(`http://localhost:${port}/page/b`); | ||
expect(await page.getByTestId('title').textContent()).toBe('b'); | ||
}); | ||
|
||
test('does not delete old pages', async ({ page }) => { | ||
execSync(`node ${waku} build --experimental-partial`, { | ||
cwd, | ||
env: { ...process.env, PAGES: 'c' }, | ||
}); | ||
await page.goto(`http://localhost:${port}/page/a`); | ||
expect(await page.getByTestId('title').textContent()).toBe('a'); | ||
await page.goto(`http://localhost:${port}/page/c`); | ||
expect(await page.getByTestId('title').textContent()).toBe('c'); | ||
}); | ||
|
||
test.afterEach(async () => { | ||
await terminate(cp.pid!); | ||
}); | ||
}); |
This file contains 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 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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