Skip to content

Commit 647bf11

Browse files
MarcosBrendonDePaulaclaude
andcommitted
fix: defer component registration until liveServer is initialized
registerAllComponents() was called at module evaluation time, before the liveComponentsPlugin setup() had created the LiveServer instance. The componentRegistry proxy hit liveServer!.registry with liveServer still null, crashing in production bundles. Now auto-generated-components.ts exports registerAllComponents() instead of calling it immediately, and websocket-plugin.ts calls it right after creating liveServer. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 4b7f4f4 commit 647bf11

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

core/build/live-components-generator.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,11 +130,11 @@ ${registrations}
130130
}
131131
}
132132
133-
// Auto-register components
134-
registerAllComponents()
133+
// Export registration function to be called after liveServer is initialized
134+
export { registerAllComponents }
135135
136136
// Export all components to ensure they're included in the bundle
137-
export {
137+
export {
138138
${components.map(comp => ` ${comp.className}`).join(',\n')}
139139
}
140140
`

core/server/live/websocket-plugin.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { LiveServer, RoomRegistry } from '@fluxstack/live'
44
import type { LiveAuthProvider, LiveRoomClass } from '@fluxstack/live'
55
import { ElysiaTransport } from '@fluxstack/live-elysia'
66
import type { Plugin, PluginContext } from '@core/plugins/types'
7+
import { registerAllComponents } from './auto-generated-components'
78
import path from 'path'
89
import { readdirSync, existsSync } from 'fs'
910

@@ -40,6 +41,9 @@ export const liveComponentsPlugin: Plugin = {
4041
rooms: [...discoveredRooms, ...pendingRoomClasses],
4142
})
4243

44+
// Register auto-generated components now that liveServer exists
45+
registerAllComponents()
46+
4347
// Replay any auth providers that were registered before setup()
4448
for (const provider of pendingAuthProviders) {
4549
liveServer.useAuth(provider)

0 commit comments

Comments
 (0)