@mandujs/core 0.9.6 → 0.9.8

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mandujs/core",
3
- "version": "0.9.6",
3
+ "version": "0.9.8",
4
4
  "description": "Mandu Framework Core - Spec, Generator, Guard, Runtime",
5
5
  "type": "module",
6
6
  "main": "./src/index.ts",
@@ -427,19 +427,22 @@ function generateRouterRuntimeSource(): string {
427
427
  */
428
428
 
429
429
  // 전역 상태 초기화 (Island와 공유)
430
+ (function initGlobalState() {
431
+ if (window.__MANDU_ROUTER_STATE__) return;
432
+ var route = window.__MANDU_ROUTE__;
433
+ window.__MANDU_ROUTER_STATE__ = {
434
+ currentRoute: route ? {
435
+ id: route.id,
436
+ pattern: route.pattern,
437
+ params: route.params || {}
438
+ } : null,
439
+ loaderData: window.__MANDU_DATA__ && window.__MANDU_DATA__[route && route.id] ? window.__MANDU_DATA__[route.id].serverData : undefined,
440
+ navigation: { state: 'idle' }
441
+ };
442
+ window.__MANDU_ROUTER_LISTENERS__ = window.__MANDU_ROUTER_LISTENERS__ || new Set();
443
+ })();
444
+
430
445
  function getGlobalState() {
431
- if (!window.__MANDU_ROUTER_STATE__) {
432
- const route = window.__MANDU_ROUTE__;
433
- window.__MANDU_ROUTER_STATE__ = {
434
- currentRoute: route ? {
435
- id: route.id,
436
- pattern: route.pattern,
437
- params: route.params || {}
438
- } : null,
439
- loaderData: window.__MANDU_DATA__?.[route?.id]?.serverData,
440
- navigation: { state: 'idle' }
441
- };
442
- }
443
446
  return window.__MANDU_ROUTER_STATE__;
444
447
  }
445
448
 
@@ -447,16 +450,12 @@ function setGlobalState(state) {
447
450
  window.__MANDU_ROUTER_STATE__ = state;
448
451
  }
449
452
 
450
- // 전역 listeners
451
453
  function getListeners() {
452
- if (!window.__MANDU_ROUTER_LISTENERS__) {
453
- window.__MANDU_ROUTER_LISTENERS__ = new Set();
454
- }
455
454
  return window.__MANDU_ROUTER_LISTENERS__;
456
455
  }
457
456
 
458
457
  // 패턴 매칭 캐시
459
- const patternCache = new Map();
458
+ var patternCache = new Map();
460
459
 
461
460
  function compilePattern(pattern) {
462
461
  if (patternCache.has(pattern)) return patternCache.get(pattern);
@@ -583,8 +582,10 @@ function handlePopState(e) {
583
582
 
584
583
  // 초기화
585
584
  function init() {
586
- if (currentRoute) {
587
- currentRoute.params = extractParams(currentRoute.pattern, location.pathname);
585
+ var state = getGlobalState();
586
+ if (state.currentRoute) {
587
+ state.currentRoute.params = extractParams(state.currentRoute.pattern, location.pathname);
588
+ setGlobalState(state);
588
589
  }
589
590
 
590
591
  window.addEventListener('popstate', handlePopState);
@@ -597,8 +598,6 @@ if (document.readyState === 'loading') {
597
598
  } else {
598
599
  init();
599
600
  }
600
-
601
- export { currentRoute, currentLoaderData, navigationState };
602
601
  `;
603
602
  }
604
603
 
@@ -47,9 +47,17 @@ function getGlobalRouterState(): RouterState {
47
47
  return { currentRoute: null, loaderData: undefined, navigation: { state: "idle" } };
48
48
  }
49
49
  if (!window.__MANDU_ROUTER_STATE__) {
50
+ // SSR에서 주입된 __MANDU_ROUTE__에서 초기화
51
+ const route = (window as any).__MANDU_ROUTE__;
52
+ const data = (window as any).__MANDU_DATA__;
53
+
50
54
  window.__MANDU_ROUTER_STATE__ = {
51
- currentRoute: null,
52
- loaderData: undefined,
55
+ currentRoute: route ? {
56
+ id: route.id,
57
+ pattern: route.pattern,
58
+ params: route.params || {},
59
+ } : null,
60
+ loaderData: route && data?.[route.id]?.serverData,
53
61
  navigation: { state: "idle" },
54
62
  };
55
63
  }