@mandujs/core 0.18.2 → 0.18.5

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.
@@ -428,6 +428,7 @@ export function generateHMRClientScript(port: number): string {
428
428
  let reconnectAttempts = 0;
429
429
  const maxReconnectAttempts = ${TIMEOUTS.HMR_MAX_RECONNECT};
430
430
  const reconnectDelay = ${TIMEOUTS.HMR_RECONNECT_DELAY};
431
+ const staleIslands = new Set();
431
432
 
432
433
  function connect() {
433
434
  try {
@@ -464,8 +465,9 @@ export function generateHMRClientScript(port: number): string {
464
465
  function scheduleReconnect() {
465
466
  if (reconnectAttempts < maxReconnectAttempts) {
466
467
  reconnectAttempts++;
467
- console.log('[Mandu HMR] Reconnecting... (' + reconnectAttempts + '/' + maxReconnectAttempts + ')');
468
- setTimeout(connect, reconnectDelay * reconnectAttempts);
468
+ var delay = Math.min(reconnectDelay * Math.pow(2, reconnectAttempts - 1), 30000);
469
+ console.log('[Mandu HMR] Reconnecting in ' + delay + 'ms (' + reconnectAttempts + '/' + maxReconnectAttempts + ')');
470
+ setTimeout(connect, delay);
469
471
  }
470
472
  }
471
473
 
@@ -483,6 +485,7 @@ export function generateHMRClientScript(port: number): string {
483
485
  case 'island-update':
484
486
  const routeId = message.data?.routeId;
485
487
  console.log('[Mandu HMR] Island updated:', routeId);
488
+ staleIslands.add(routeId);
486
489
 
487
490
  // 현재 페이지의 island인지 확인
488
491
  const island = document.querySelector('[data-mandu-island="' + routeId + '"]');
@@ -533,7 +536,19 @@ export function generateHMRClientScript(port: number): string {
533
536
  const overlay = document.createElement('div');
534
537
  overlay.id = 'mandu-hmr-error';
535
538
  overlay.style.cssText = 'position:fixed;top:0;left:0;right:0;bottom:0;background:rgba(0,0,0,0.9);color:#ff6b6b;font-family:monospace;padding:40px;z-index:99999;overflow:auto;';
536
- overlay.innerHTML = '<h2 style="color:#ff6b6b;margin:0 0 20px;">🔥 Build Error</h2><pre style="white-space:pre-wrap;word-break:break-all;">' + (message || 'Unknown error') + '</pre><button onclick="this.parentElement.remove()" style="position:fixed;top:20px;right:20px;background:#333;color:#fff;border:none;padding:10px 20px;cursor:pointer;">Close</button>';
539
+ const h2 = document.createElement('h2');
540
+ h2.style.cssText = 'color:#ff6b6b;margin:0 0 20px;';
541
+ h2.textContent = '🔥 Build Error';
542
+ const pre = document.createElement('pre');
543
+ pre.style.cssText = 'white-space:pre-wrap;word-break:break-all;';
544
+ pre.textContent = message || 'Unknown error';
545
+ const btn = document.createElement('button');
546
+ btn.style.cssText = 'position:fixed;top:20px;right:20px;background:#333;color:#fff;border:none;padding:10px 20px;cursor:pointer;';
547
+ btn.textContent = 'Close';
548
+ btn.onclick = function() { overlay.remove(); };
549
+ overlay.appendChild(h2);
550
+ overlay.appendChild(pre);
551
+ overlay.appendChild(btn);
537
552
  document.body.appendChild(overlay);
538
553
  }
539
554
 
@@ -549,6 +564,22 @@ export function generateHMRClientScript(port: number): string {
549
564
  if (ws) ws.close();
550
565
  });
551
566
 
567
+ // 페이지 이동 시 stale island 감지 후 리로드 (#115)
568
+ function checkStaleIslandsOnNavigation() {
569
+ if (staleIslands.size === 0) return;
570
+ for (const id of staleIslands) {
571
+ if (document.querySelector('[data-mandu-island="' + id + '"]')) {
572
+ console.log('[Mandu HMR] Stale island detected after navigation, reloading...');
573
+ location.reload();
574
+ return;
575
+ }
576
+ }
577
+ }
578
+ window.addEventListener('popstate', checkStaleIslandsOnNavigation);
579
+ window.addEventListener('pageshow', function(e) {
580
+ if (e.persisted) checkStaleIslandsOnNavigation();
581
+ });
582
+
552
583
  // Ping 전송 (연결 유지)
553
584
  setInterval(function() {
554
585
  if (ws && ws.readyState === WebSocket.OPEN) {
@@ -26,7 +26,7 @@ export interface ManduConfig {
26
26
  };
27
27
  };
28
28
  guard?: {
29
- preset?: "mandu" | "fsd" | "clean" | "hexagonal" | "atomic";
29
+ preset?: "mandu" | "fsd" | "clean" | "hexagonal" | "atomic" | "cqrs";
30
30
  srcDir?: string;
31
31
  exclude?: string[];
32
32
  realtime?: boolean;
@@ -71,7 +71,7 @@ const ServerConfigSchema = z
71
71
  */
72
72
  const GuardConfigSchema = z
73
73
  .object({
74
- preset: z.enum(["mandu", "fsd", "clean", "hexagonal", "atomic"]).default("mandu"),
74
+ preset: z.enum(["mandu", "fsd", "clean", "hexagonal", "atomic", "cqrs"]).default("mandu"),
75
75
  srcDir: z.string().default("src"),
76
76
  exclude: z.array(z.string()).default([]),
77
77
  realtime: z.boolean().default(true),