Skip to content

Fix cameras not loading: serve the camera catalogue uncompressed and let Next.js compress it - #518

Merged
simplifaisoul merged 1 commit into
masterfrom
fix/cctv-double-gzip
Nov 25, 2026
Merged

simplifaisoul merged 1 commit into
masterfrom
fix/cctv-double-gzip

Conversation

@simplifaisoul

@simplifaisoul simplifaisoul commented Nov 25, 2026 •

Copy link
Copy Markdown
Owner

Summary

Since the update to Next.js 16.4.6 (#516), no cameras load on the map, and the stats counters show 0.

  • /api/cctv served a pre-gzipped catalogue with Content-Encoding: gzip.
  • Next.js 16.4.5 drops a route handler's own Content-Encoding header (part of its security fixes).
  • Next.js 16.4.6 compresses route handler responses automatically (vercel/next.js#101280).
  • Together, browsers receive the catalogue gzipped twice. After decoding once they still hold gzip bytes, so the camera list fails to parse.
  • /api/stats reads /api/cctv internally and fails the same way, so every counter stays at 0.

Rolling Next.js back to 16.4.5 does not fix this, because that version already drops the header. Rolling back to 16.4.3 would reopen the seven advisories fixed in 16.4.5. This change keeps 16.4.6 and fixes the route instead.

Changes

  • servePayload in src/app/api/cctv/route.ts always sends the serialised JSON. Next.js compresses it once for clients that accept gzip. ETag and 304 handling are unchanged.
  • src/lib/cctv-snapshot.ts: the payload no longer keeps a gzip copy. This also removes a synchronous gzip of the whole catalogue from every rebuild.
  • Tests: a new route test checks that a client accepting gzip gets the whole catalogue as JSON without a route-set Content-Encoding. The snapshot test drops its gzip assertions.

Testing

  • vitest: camera route, snapshot and stats tests pass (25).
  • tsc --noEmit passes.
  • Production build on Next.js 16.4.6, run as the standalone server the Docker image uses:
    • /api/cctv requested with Accept-Encoding: gzip comes back gzipped once and parses as JSON.
    • Plain requests and If-None-Match (304) still work.
    • /api/stats returns non-zero counts again.

🤖 Generated with SIMPLIFAI

…mpress it

Next.js 16.4.5 drops a route handler's own Content-Encoding header, and
16.4.6 compresses route responses automatically. The catalogue was
pre-gzipped, so browsers received it gzipped twice, could not parse it,
and no cameras loaded. /api/stats reads /api/cctv internally and failed
the same way, leaving every counter at 0.

Serve the serialised JSON and leave compression to Next.js. The payload
no longer carries a gzip copy, which also removes a synchronous gzip of
the whole catalogue from every rebuild.
@vercel

vercel Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
osiris Ready Ready Preview Nov 25, 2026 11:17pm UTC

This branch was successfully deployed

1 active deployment
Preview – osiris — 8e8148c9 Deployed Nov 25, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant