Skip to content

TinyOffice SSE always shows Disconnected - Next.js rewrite buffers event stream #231

Open

Description

@crisdias

Bug

The TinyOffice office view always shows Disconnected status, even when the SSE endpoint (/api/events/stream) is working correctly on the backend.

Root Cause

The Next.js rewrite in next.config.ts buffers SSE responses:

async rewrites() {
  return [{ source: "/api/:path*", destination: "http://127.0.0.1:3777/api/:path*" }];
}

Next.js rewrites do not support streaming/SSE — they buffer the full response before forwarding. The EventSource in the browser connects to the Next.js server, which never flushes the SSE events in real time.

Fix

In tinyoffice/src/lib/api.ts, the subscribeToEvents function should create the EventSource pointing directly to the API server (port 3777) instead of going through the Next.js rewrite:

const sseBase = typeof window !== "undefined"
  ? (process.env.NEXT_PUBLIC_SSE_URL ?? `${window.location.protocol}//${window.location.hostname}:3777`)
  : "";
const es = new EventSource(`${sseBase}/api/events/stream`);

This allows the browser to connect directly to the backend SSE endpoint, bypassing the Next.js rewrite proxy.

Additional build error in v0.0.14

src/app/console/page.tsx uses onChange on a Radix <Select> component, which should be onValueChange. This breaks next build.

Activity

  1. added a commit that references this issue on Mar 16, 2026
    d9d018e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions