@hypen-space/core 0.4.22 → 0.4.24

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -302,14 +302,16 @@ export class RemoteServer {
302
302
  * Handle new WebSocket connection
303
303
  * Waits for hello message before fully initializing
304
304
  */
305
- private async handleOpen(ws: ServerWebSocket<unknown>) {
305
+ private handleOpen(ws: ServerWebSocket<unknown>) {
306
306
  try {
307
307
  const clientId = `client_${this.nextClientId++}`;
308
308
  const connectedAt = new Date();
309
309
 
310
310
  // Create engine instance for this client
311
311
  const engine = new Engine();
312
- await engine.init();
312
+ // init() body is synchronous for wasm-node (just new WasmEngine())
313
+ // but declared async, so call it and catch the rejected promise if it fails
314
+ engine.init().catch((err) => log.error("Engine init failed:", err));
313
315
 
314
316
  // Wire up component resolver if we have discovered components
315
317
  this.setupComponentResolver(engine);
@@ -317,7 +319,9 @@ export class RemoteServer {
317
319
  // Create module instance
318
320
  const moduleInstance = new HypenModuleInstance(engine, this._module!);
319
321
 
320
- // Store client data (session will be set when hello is received)
322
+ log.info(`Client ${clientId} connected, engine initialized`);
323
+
324
+ // Store client data SYNCHRONOUSLY so handleMessage can find it
321
325
  const clientData: ClientData = {
322
326
  id: clientId,
323
327
  engine,
@@ -334,7 +338,9 @@ export class RemoteServer {
334
338
  clientData.helloTimeout = setTimeout(() => {
335
339
  if (!clientData.helloReceived) {
336
340
  // Legacy client - create new session automatically
337
- this.initializeSession(ws, clientData, undefined, undefined);
341
+ this.initializeSession(ws, clientData, undefined, undefined).catch(
342
+ (err) => log.error("Error initializing legacy session:", err)
343
+ );
338
344
  }
339
345
  }, 1000); // 1 second grace period
340
346
 
@@ -355,6 +361,7 @@ export class RemoteServer {
355
361
  ): Promise<void> {
356
362
  if (clientData.helloReceived) return;
357
363
  clientData.helloReceived = true;
364
+ log.info(`Initializing session for ${clientData.id} (sessionId: ${requestedSessionId ?? "new"})`);
358
365
 
359
366
  // Clear hello timeout
360
367
  if (clientData.helloTimeout) {
@@ -421,18 +428,23 @@ export class RemoteServer {
421
428
  isRestored,
422
429
  };
423
430
  ws.send(JSON.stringify(sessionAck));
431
+ log.info(`Sent sessionAck to ${clientData.id} (session: ${session.id})`);
424
432
 
425
- // Set up render callback
426
- this.setupRenderCallback(ws, clientData);
427
-
428
- // Render initial tree
433
+ // Render initial tree — capture patches synchronously
429
434
  const initialPatches: Patch[] = [];
430
435
  clientData.engine.setRenderCallback((patches) => {
431
436
  initialPatches.push(...patches);
432
437
  });
433
- clientData.engine.renderSource(this._ui);
434
438
 
435
- // Now set up streaming render callback
439
+ try {
440
+ clientData.engine.renderSource(this._ui);
441
+ } catch (renderError) {
442
+ log.error(`Failed to render UI for ${clientData.id}:`, renderError);
443
+ ws.close(1011, "Render failed");
444
+ return;
445
+ }
446
+
447
+ // Now set up streaming render callback for subsequent updates
436
448
  this.setupRenderCallback(ws, clientData);
437
449
 
438
450
  // Send initial tree
@@ -443,7 +455,14 @@ export class RemoteServer {
443
455
  patches: initialPatches,
444
456
  revision: 0,
445
457
  };
446
- ws.send(JSON.stringify(initialMessage));
458
+
459
+ try {
460
+ ws.send(JSON.stringify(initialMessage));
461
+ } catch (sendError) {
462
+ log.error(`Failed to send initialTree to ${clientData.id}:`, sendError);
463
+ return;
464
+ }
465
+ log.info(`Sent initialTree to ${clientData.id} (${initialPatches.length} patches)`);
447
466
 
448
467
  // Notify connection callbacks
449
468
  const client: RemoteClient = {
@@ -589,7 +608,7 @@ export class RemoteServer {
589
608
  clientData,
590
609
  helloMsg.sessionId,
591
610
  helloMsg.props
592
- );
611
+ ).catch((err) => log.error("Error initializing session from hello:", err));
593
612
  break;
594
613
  }
595
614
 
Binary file
@@ -5,7 +5,7 @@
5
5
  "Hypen Contributors"
6
6
  ],
7
7
  "description": "A Rust implementation of the Hypen engine",
8
- "version": "0.4.22",
8
+ "version": "0.4.24",
9
9
  "license": "MIT",
10
10
  "repository": {
11
11
  "type": "git",
Binary file
@@ -4,7 +4,7 @@
4
4
  "Hypen Contributors"
5
5
  ],
6
6
  "description": "A Rust implementation of the Hypen engine",
7
- "version": "0.4.22",
7
+ "version": "0.4.24",
8
8
  "license": "MIT",
9
9
  "repository": {
10
10
  "type": "git",