Skip to content

Commit 6dcb5d4

Browse files
ralyodioclaude
andauthored
fix: revalidate pages on every open so the iOS app stops opening old builds (0.12.2) (#325)
* fix: installed iOS app picks up new deploys by itself (0.12.1) An iOS home-screen app has no reload button and iOS resumes it from memory instead of reloading, so it kept running an old build while Safari showed the new one. The service worker file never changes between deploys, so the existing update toast never fired. - next.config.js stamps every build with one id (version + time), baked into client and server (generateBuildId + NEXT_PUBLIC_BUILD_ID). - GET /api/version (no-store) returns the running build's id. - PWAToastManager checks it whenever the app comes back to the foreground (visibilitychange, pageshow from bfcache) and every 5 minutes while open. On resume with nothing in progress it reloads; with an unsent draft, voice mode or a call it shows the "new version" toast instead (src/lib/app-update.js). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix: pages are revalidated on every open, so the iOS app stops opening old builds (0.12.2) Next sends prerendered pages with `s-maxage=300, stale-while-revalidate=31535700`. Browsers ignore s-maxage but honour stale-while-revalidate, so the installed iOS app kept opening a cached page (and the old build it loads) for up to a year, refreshing only in the background. 0.12.1's version check never ran because the old page did not contain it. src/proxy.js now sends `Cache-Control: no-cache` on page routes (not /api, /_next or files), so every open revalidates (a cheap 304 when nothing changed). Hashed /_next/static files stay cached. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 0ac9361 commit 6dcb5d4

3 files changed

Lines changed: 28 additions & 1 deletion

File tree

‎package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "qryptchat-web",
33
"private": true,
4-
"version": "0.12.1",
4+
"version": "0.12.2",
55
"type": "module",
66
"bin": {
77
"qc": "./bin/qc.js",

‎src/proxy.js‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,25 @@ export async function proxy(request) {
5656
if (!allowed) return rateLimitedResponse();
5757
}
5858

59+
// Pages must be revalidated on every open. Next sends prerendered pages with
60+
// `s-maxage=300, stale-while-revalidate=<a year>`: browsers ignore s-maxage
61+
// but honour the stale-while-revalidate, so an installed iOS app kept opening
62+
// a year-old cached page (and the old build it loads) after every deploy.
63+
// Hashed /_next/static files are untouched and stay cached for good.
64+
if (isPage(pathname)) {
65+
const res = NextResponse.next();
66+
res.headers.set('Cache-Control', 'no-cache');
67+
return res;
68+
}
69+
5970
return NextResponse.next();
6071
}
6172

73+
/** A page route: not an API, a Next.js asset or a file with an extension. */
74+
export function isPage(pathname) {
75+
return !pathname.startsWith('/api/') && !pathname.startsWith('/_next/') && !/\.[a-z0-9]+$/i.test(pathname);
76+
}
77+
6278
export const config = {
6379
matcher: ['/api/:path*', '/:path*'],
6480
};

‎src/proxy.test.js‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { describe, expect, it } from 'vitest';
2+
import { isPage } from './proxy.js';
3+
4+
describe('isPage', () => {
5+
it('marks page routes for revalidation and leaves assets and APIs alone', () => {
6+
for (const p of ['/', '/chat', '/join/abc', '/u/riotcoder']) expect(isPage(p)).toBe(true);
7+
for (const p of ['/api/version', '/_next/static/chunks/a.js', '/sw.js', '/manifest.json', '/icons/icon-192x192.png']) {
8+
expect(isPage(p)).toBe(false);
9+
}
10+
});
11+
});

0 commit comments

Comments
 (0)