Skip to content

Commit e6e7d5f

Browse files
fix(server): disable index html caching for in-app browsers
1 parent 1c8e9dc commit e6e7d5f

1 file changed

Lines changed: 14 additions & 2 deletions

File tree

src/server/index.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import fastifyStatic from '@fastify/static';
44
import fastifyWebsocket from '@fastify/websocket';
55
import { fileURLToPath } from 'node:url';
66
import { dirname, join, resolve } from 'node:path';
7-
import { existsSync } from 'node:fs';
7+
import { existsSync, readFileSync } from 'node:fs';
88
import { registerProjectRoutes } from './routes/project.js';
99
import { registerAgentRoutes } from './routes/agents.js';
1010
import { registerPlanetRoutes } from './routes/planets.js';
@@ -48,7 +48,19 @@ export async function startServer(opts: ServeOptions): Promise<void> {
4848

4949
function sendSpaEntry(reply: { sendFile: (path: string) => unknown; code: (status: number) => any; header: (key: string, value: string) => any; send: (body: string) => unknown; }) {
5050
if (hasBuiltStudio()) {
51-
return reply.sendFile('dist/index.html');
51+
// Avoid stale HTML cache in mobile in-app browsers (hashed asset names change on deploy).
52+
// `sendFile()` may override cache headers, so we manually send the HTML.
53+
try {
54+
const html = readFileSync(builtIndexPath, 'utf-8');
55+
return reply
56+
.code(200)
57+
.header('content-type', 'text/html; charset=utf-8')
58+
.header('cache-control', 'no-store')
59+
.send(html);
60+
} catch {
61+
// Fallback to the static handler if for some reason the file is not readable.
62+
return reply.sendFile('dist/index.html');
63+
}
5264
}
5365

5466
return reply.code(200).header('content-type', 'text/html').send(getEmbeddedHtml());

0 commit comments

Comments
 (0)