Skip to content

Conversation

@vcarl
Copy link
Member

@vcarl vcarl commented Jan 17, 2026

Separates "login once" from "bind listeners" logic to enable proper hot module reloading. Previously, the gateway flag prevented duplicate logins but also prevented listener code from being updated on HMR.

Key changes:

  • Add listenerRegistry.ts with registerListener/removeAllListeners
  • Add HMR state helpers to client.server.ts (isClientReady, clearScheduledTasks)
  • Modify schedule.ts to return timer handles for cleanup
  • Refactor gateway.ts to split login from listener binding
  • Update all listener modules to use registerListener

On HMR, old listeners are removed before rebinding new ones with fresh closures.

Separates "login once" from "bind listeners" logic to enable proper hot
module reloading. Previously, the gateway flag prevented duplicate logins
but also prevented listener code from being updated on HMR.

Key changes:
- Add listenerRegistry.ts with registerListener/removeAllListeners
- Add HMR state helpers to client.server.ts (isClientReady, clearScheduledTasks)
- Modify schedule.ts to return timer handles for cleanup
- Refactor gateway.ts to split login from listener binding
- Update all listener modules to use registerListener

On HMR, old listeners are removed before rebinding new ones with fresh closures.

Co-Authored-By: Claude Opus 4.5 <[email protected]>
@github-actions
Copy link

github-actions bot commented Jan 17, 2026

Preview environment removed

The preview for this PR has been cleaned up.

@github-actions
Copy link

github-actions bot commented Jan 17, 2026

✅ E2E Tests Passed

View Report · View Run

Tested against: https://250.euno-staging.reactiflux.com

vcarl and others added 2 commits January 18, 2026 14:15
Move all HMR-related globals from scattered locations into a single
hmrRegistry.ts module:
- Login state (isLoginStarted/markLoginStarted) from gateway.ts
- Client ready state (isClientReady/setClientReady) from client.server.ts
- Scheduled tasks (registerScheduledTask/clearScheduledTasks) from client.server.ts
- Listener registry (existing, renamed from listenerRegistry.ts)

This centralizes HMR concerns and simplifies client.server.ts to just
client instantiation and login.

Co-Authored-By: Claude Opus 4.5 <[email protected]>
Co-Authored-By: Claude Opus 4.5 <[email protected]>
Replace explicit registerListener() wrapper with a monkeypatch on
client.on that automatically tracks listeners for HMR cleanup. This
prevents future errors when someone uses client.on directly.

- Patch client.on immediately after client creation
- Remove registerListener/getListenerCount exports from hmrRegistry
- Revert all 9 listener files to use native client.on syntax
- Keep once() unpatched for one-time init handlers

Co-Authored-By: Claude Opus 4.5 <[email protected]>
@vcarl vcarl merged commit 0d57a1b into main Jan 18, 2026
5 of 6 checks passed
@vcarl vcarl deleted the vc-hmr-discord branch January 18, 2026 19:55
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