Skip to content

Claude/fix server client leak zxa5d#71

Merged
MarcosBrendonDePaula merged 6 commits intomainfrom
claude/fix-server-client-leak-ZXA5d
Mar 1, 2026
Merged

Claude/fix server client leak zxa5d#71
MarcosBrendonDePaula merged 6 commits intomainfrom
claude/fix-server-client-leak-ZXA5d

Conversation

@MarcosBrendonDePaula
Copy link
Copy Markdown
Collaborator

  • Vite plugin (fluxstack-live-strip): Client components import server LiveComponent classes for type
    inference (Live.use(LiveCounter)), but those classes transitively pull in fs, path, RoomEventBus,
    LiveRoomManager, and other Node.js/server-only modules — breaking the client build. The new plugin intercepts
    @server/live/* imports from client code and replaces them with lightweight stubs containing only
    componentName, defaultState, and publicActions.
  • vite-plugins.ts facade: Centralizes all framework-level Vite plugins (live-strip, tsconfig-paths,
    checker) into a single fluxstackVitePlugins() call, cleaning up vite.config.ts.
  • TodoList demo: Adds LiveTodoList server component + TodoListDemo client component as a collaborative
    real-time todo list example using Room Events.
  • Custom agents: Adds live-components-specialist and fluxstack-core-researcher Claude Code agents.

What was wrong

Every client live component (CounterDemo, ChatDemo, RoomChatDemo, etc.) does import { LiveCounter } from '@server/live/LiveCounter'. The LiveComponent base class in core/types/types.ts has runtime imports of
RoomEventBus, LiveRoomManager, LiveLogger, and ServerWebSocket from Bun — all server-only. Without
intervention, Vite tries to bundle all of these into the client, causing build failures.

How it works

  1. Plugin hooks into Vite's resolveId — when a client file imports @server/live/Foo, it parses the server
    .ts file with regex, extracts the 3 static fields, and writes a minimal .js stub to app/client/.live-stubs/.
  2. Vite resolves the import to the stub instead of the real server file.
  3. On HMR, the plugin detects if metadata changed (triggers client reload) or only method bodies changed (skips
    reload).
  4. Stubs are cleaned up on buildEnd.

claude and others added 6 commits February 28, 2026 12:52
Server live components (e.g., LiveCounter, LiveChat) are imported by client
components to get type inference and static metadata (componentName,
defaultState, publicActions). However, these imports pulled in the full
server class and all its transitive dependencies, including Node.js-only
modules like 'fs', 'path', and server framework internals (RoomEventBus,
LiveRoomManager, etc.), causing client build failures.

Changes:
- Add Vite plugin (fluxstack-live-strip) that intercepts @server/live/*
  imports from client code and replaces them with lightweight stubs
  containing only static metadata
- Add LiveFileReader test component that imports 'fs' to demonstrate
  the leak scenario
- Add 35 unit tests covering leak detection and plugin functionality

https://claude.ai/code/session_018Hw3WNhmfUsuPFjwkL2BJ9
The plugin now watches server live component files during dev mode.
When static metadata (defaultState, publicActions) changes, it triggers
a client-side HMR update. Changes to server-only method bodies are
silently ignored (no unnecessary client reloads).

https://claude.ai/code/session_018Hw3WNhmfUsuPFjwkL2BJ9
Adds test cases for database (Prisma, Drizzle), Redis (ioredis),
Node.js builtins (crypto, child_process, net, os), third-party libs
(axios, sharp, nodemailer, AWS SDK), FluxStack server internals, and
Bun-specific imports. All are fully stripped from client stubs.

https://claude.ai/code/session_018Hw3WNhmfUsuPFjwkL2BJ9
- Delete LiveFileReader.ts — artificial demo component with path
  traversal vulnerability (unsanitized user input to readFileSync)
- Rewrite vite-plugin-live-strip tests to cover real components
  (LiveCounter, LiveChat, LiveTodoList) instead of hypothetical
  libs (Prisma, Redis, AWS SDK, etc.) that don't exist in the project
- Slim down server-client-leak tests from 365 to 75 lines, keeping
  only the assertions that document the actual problem and verify
  the fix is wired up

532 tests passing, 0 failures.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
- live-components-specialist: WebSocket-based Live Components
- fluxstack-core-researcher: read-only core framework analysis

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@MarcosBrendonDePaula MarcosBrendonDePaula merged commit 609fe88 into main Mar 1, 2026
11 checks passed
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.

2 participants