Skip to content

Commit 865d5a2

Browse files
authored
ui adjustments (#2371)
* adjust folder inclusion, ssr logging * avoid stale chunks * prevent hydration mismatch
1 parent 492168a commit 865d5a2

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

ui/server-start.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,12 @@ const server = createServer(async (req, res) => {
3131
const pathname = url.pathname;
3232

3333
// Try to serve static files from dist/client first
34-
if (pathname.startsWith('/assets/') || pathname === '/favicon.svg' || pathname === '/favicon.png' || pathname === '/favicon.ico') {
34+
// Serve: /assets/*, *.js, *.css, *.json, images, fonts, favicons
35+
const staticExtensions = ['.js', '.mjs', '.css', '.json', '.png', '.jpg', '.gif', '.ico', '.svg', '.woff', '.woff2'];
36+
const isStaticFile = pathname.startsWith('/assets/') ||
37+
staticExtensions.some(ext => pathname.endsWith(ext));
38+
39+
if (isStaticFile) {
3540
try {
3641
const filePath = join(__dirname, 'dist', 'client', pathname);
3742
const content = await readFile(filePath);
@@ -67,7 +72,14 @@ const server = createServer(async (req, res) => {
6772
});
6873

6974
// Call the TanStack Start fetch handler
75+
const ssrStart = Date.now();
7076
const response = await serverHandler.fetch(request);
77+
const ssrTime = Date.now() - ssrStart;
78+
79+
// Log slow SSR requests
80+
if (ssrTime > 1000) {
81+
console.log(`⚠️ SLOW SSR: ${req.method} ${pathname} took ${ssrTime}ms`);
82+
}
7183

7284
// Convert Web Standard Response to Node.js response
7385
res.statusCode = response.status;
@@ -77,6 +89,11 @@ const server = createServer(async (req, res) => {
7789
response.headers.forEach((value, key) => {
7890
res.setHeader(key, value);
7991
});
92+
93+
// Prevent caching of HTML to avoid stale chunk references for now
94+
if (response.headers.get('content-type')?.includes('text/html')) {
95+
res.setHeader('Cache-Control', 'no-store, no-cache, must-revalidate');
96+
}
8097

8198
// Stream the response body
8299
if (response.body) {

ui/src/hooks/use-mobile.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ export function useIsMobile() {
1010
typeof window !== "undefined" &&
1111
window.matchMedia(`(max-width: ${MOBILE_BREAKPOINT - 1}px)`).matches
1212

13-
const [isMobile, setIsMobile] = React.useState<boolean>(get)
13+
14+
const [isMobile, setIsMobile] = React.useState<boolean | undefined>(undefined)
1415

1516
useIsomorphicLayoutEffect(() => {
1617
const mql = window.matchMedia(`(max-width: ${MOBILE_BREAKPOINT - 1}px)`)
@@ -19,6 +20,6 @@ export function useIsMobile() {
1920
mql.addEventListener("change", onChange)
2021
return () => mql.removeEventListener("change", onChange)
2122
}, [])
22-
23-
return isMobile
23+
// prevent hydration mismatch before effect is called
24+
return isMobile ?? false
2425
}

0 commit comments

Comments
 (0)