Skip to content

Commit 47f3a9f

Browse files
committed
docs: add GitHub Pages demo with simulated deploys
The example app built with VITE_DEMO=1 becomes an interactive playground: a "Deploy new version" button, live boundary props, the tab's version and Cache Storage state, and an event log that survives reloads. GitHub Pages serves static files only, so a fetch shim answers meta.json with a version kept in localStorage; the version check, cache clearing and reload run through the library unchanged. A Pages workflow publishes it from master, replacing the gh-pages script. Playwright serves the demo under the same sub-path as Pages and covers the dialog, the stale-chunk path and a custom banner prompt. The library is built once before Playwright starts, since two webServer builds racing on dist would be flaky.
1 parent f77bae9 commit 47f3a9f

18 files changed

Lines changed: 1233 additions & 371 deletions

‎.github/workflows/pages.yml‎

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
name: Pages
2+
3+
on:
4+
push:
5+
branches: [master]
6+
workflow_dispatch:
7+
8+
permissions:
9+
contents: read
10+
pages: write
11+
id-token: write
12+
13+
concurrency:
14+
group: pages
15+
cancel-in-progress: true
16+
17+
jobs:
18+
build:
19+
runs-on: ubuntu-latest
20+
steps:
21+
- uses: actions/checkout@v4
22+
- uses: pnpm/action-setup@v4
23+
- uses: actions/setup-node@v4
24+
with:
25+
node-version-file: .nvmrc
26+
cache: pnpm
27+
- run: pnpm install --frozen-lockfile
28+
- run: pnpm build
29+
- run: pnpm demo:build
30+
- uses: actions/upload-pages-artifact@v3
31+
with:
32+
path: example/dist-demo
33+
34+
deploy:
35+
needs: build
36+
runs-on: ubuntu-latest
37+
environment:
38+
name: github-pages
39+
url: ${{ steps.deployment.outputs.page_url }}
40+
steps:
41+
- id: deployment
42+
uses: actions/deploy-pages@v4

‎.gitignore‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ node_modules
77

88
# builds
99
dist
10+
dist-demo
1011
build
1112

1213
# misc

‎.prettierignore‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
dist
2+
dist-demo
23
coverage
34
pnpm-lock.yaml
45
playwright-report

‎README.md‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
55
[![NPM](https://img.shields.io/npm/v/react-clear-browser-cache.svg)](https://www.npmjs.com/package/react-clear-browser-cache) [![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com)
66

7+
**[Live demo](https://devmaxxx.github.io/react-clear-browser-cache/)**: deploy a new version in one click and watch an open tab notice it, prompt, clear Cache Storage and reload.
8+
79
## Install
810

911
```bash
@@ -235,8 +237,14 @@ pnpm install
235237
pnpm test # lint, typecheck, unit tests, build, e2e
236238
pnpm test:unit # Vitest
237239
pnpm test:e2e # Playwright against the example app in Chromium, Firefox and WebKit
240+
pnpm demo:dev # the GitHub Pages demo, with deploys simulated in the browser
238241
```
239242

243+
The demo is the example app built with `VITE_DEMO=1`. GitHub Pages serves static
244+
files only, so a fetch shim answers `meta.json` with a version kept in
245+
localStorage; the version check, cache clearing and reload are the library's own.
246+
`.github/workflows/pages.yml` publishes it on every push to `master`.
247+
240248
## License
241249

242250
MIT © [arenuzzz](https://github.com/arenuzzz)

‎e2e/demo.spec.ts‎

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import { expect, test } from '@playwright/test';
2+
3+
test('a simulated deploy is offered through the dialog and applied on Reload', async ({
4+
page
5+
}) => {
6+
await page.goto('./');
7+
await expect(page.getByTestId('stored')).toHaveText('v1');
8+
9+
await page.getByRole('button', { name: 'Deploy new version' }).click();
10+
await expect(page.getByTestId('deployed')).toHaveText('v2');
11+
12+
const dialog = page.getByRole('dialog', {
13+
name: 'A new version is available'
14+
});
15+
await expect(dialog).toBeVisible({ timeout: 10_000 });
16+
await dialog.getByRole('button', { name: 'Reload' }).click();
17+
18+
await expect(page.getByTestId('loads')).toHaveText('2');
19+
await expect(page.getByTestId('running')).toHaveText('v2');
20+
await expect(page.getByTestId('stored')).toHaveText('v2');
21+
await expect(page.getByText('Cache Storage is empty')).toBeVisible();
22+
});
23+
24+
test('a lazy chunk removed by a deploy prompts with the error message', async ({
25+
page
26+
}) => {
27+
await page.goto('./?duration=0');
28+
await page.getByRole('button', { name: 'Deploy new version' }).click();
29+
await page.getByRole('button', { name: 'Open reports (lazy chunk)' }).click();
30+
31+
const dialog = page.getByRole('dialog');
32+
await expect(dialog).toContainText('could not load');
33+
await dialog.getByRole('button', { name: 'Reload' }).click();
34+
35+
await expect(page.getByTestId('running')).toHaveText('v2');
36+
await page.getByRole('button', { name: 'Open reports (lazy chunk)' }).click();
37+
await expect(page.getByTestId('reports')).toHaveText(/v2 chunk/);
38+
});
39+
40+
test('the custom banner component replaces the dialog', async ({ page }) => {
41+
await page.goto('./?prompt=banner&duration=3000');
42+
await page.getByRole('button', { name: 'Deploy new version' }).click();
43+
44+
const banner = page.getByRole('status');
45+
await expect(banner).toContainText('v2 is ready', { timeout: 10_000 });
46+
await banner.getByRole('button', { name: 'Dismiss' }).click();
47+
await expect(banner).toBeHidden();
48+
await expect(page.getByTestId('is-latest')).toHaveText('false');
49+
});

‎eslint.config.mjs‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,13 @@ import tseslint from 'typescript-eslint';
66

77
export default tseslint.config(
88
{
9-
ignores: ['**/dist', 'coverage', 'playwright-report', 'test-results']
9+
ignores: [
10+
'**/dist',
11+
'**/dist-demo',
12+
'coverage',
13+
'playwright-report',
14+
'test-results'
15+
]
1016
},
1117
js.configs.recommended,
1218
tseslint.configs.recommended,

‎example/README.md‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,11 @@ Query parameters configure the boundary, so one build covers every scenario:
1717
| `duration` | Polling interval in ms. |
1818
| `prompt=1` | Show the built-in `UpdatePrompt` dialog. |
1919
| `promptOnError=1` | Prompt instead of reloading on a stale-chunk error. |
20+
21+
## GitHub Pages demo
22+
23+
`pnpm demo:dev` and `pnpm demo:build` set `VITE_DEMO=1`, which swaps the entry
24+
for `src/demo`: a playground with a **Deploy new version** button, live boundary
25+
props, the tab's state and an event log. A fetch shim stands in for the server,
26+
since Pages serves static files only. `e2e/demo.spec.ts` covers it under the
27+
same `/react-clear-browser-cache/` sub-path that Pages uses.

0 commit comments

Comments
 (0)