@mandujs/core 0.7.4 → 0.7.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.
- package/package.json +1 -1
- package/src/client/runtime.ts +22 -14
package/package.json
CHANGED
package/src/client/runtime.ts
CHANGED
|
@@ -15,14 +15,22 @@ import React from "react";
|
|
|
15
15
|
export type IslandLoader = () => Promise<CompiledIsland<any, any>> | CompiledIsland<any, any>;
|
|
16
16
|
|
|
17
17
|
/**
|
|
18
|
-
* Island 레지스트리
|
|
18
|
+
* Island 레지스트리 (글로벌)
|
|
19
|
+
* 주의: 로컬 Map 사용 시 번들러 인라인 문제로 별도 인스턴스 생성됨
|
|
20
|
+
* 항상 window.__MANDU_ISLANDS__를 직접 참조해야 함
|
|
19
21
|
*/
|
|
20
|
-
|
|
22
|
+
declare global {
|
|
23
|
+
interface Window {
|
|
24
|
+
__MANDU_ISLANDS__: Map<string, IslandLoader>;
|
|
25
|
+
__MANDU_ROOTS__: Map<string, Root>;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
21
28
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
29
|
+
// 글로벌 레지스트리 초기화
|
|
30
|
+
if (typeof window !== "undefined") {
|
|
31
|
+
window.__MANDU_ISLANDS__ = window.__MANDU_ISLANDS__ || new Map<string, IslandLoader>();
|
|
32
|
+
window.__MANDU_ROOTS__ = window.__MANDU_ROOTS__ || new Map<string, Root>();
|
|
33
|
+
}
|
|
26
34
|
|
|
27
35
|
/**
|
|
28
36
|
* Hydration 상태 추적
|
|
@@ -45,14 +53,14 @@ const hydrationState: HydrationState = {
|
|
|
45
53
|
* Island 등록
|
|
46
54
|
*/
|
|
47
55
|
export function registerIsland(id: string, loader: IslandLoader): void {
|
|
48
|
-
|
|
56
|
+
window.__MANDU_ISLANDS__.set(id, loader);
|
|
49
57
|
}
|
|
50
58
|
|
|
51
59
|
/**
|
|
52
60
|
* 등록된 모든 Island 가져오기
|
|
53
61
|
*/
|
|
54
62
|
export function getRegisteredIslands(): string[] {
|
|
55
|
-
return Array.from(
|
|
63
|
+
return Array.from(window.__MANDU_ISLANDS__.keys());
|
|
56
64
|
}
|
|
57
65
|
|
|
58
66
|
/**
|
|
@@ -139,7 +147,7 @@ async function hydrateIsland(
|
|
|
139
147
|
id: string,
|
|
140
148
|
serverData: unknown
|
|
141
149
|
): Promise<void> {
|
|
142
|
-
const loader =
|
|
150
|
+
const loader = window.__MANDU_ISLANDS__.get(id);
|
|
143
151
|
if (!loader) {
|
|
144
152
|
console.warn(`[Mandu] Island not registered: ${id}`);
|
|
145
153
|
hydrationState.failed++;
|
|
@@ -179,7 +187,7 @@ async function hydrateIsland(
|
|
|
179
187
|
|
|
180
188
|
// Hydrate
|
|
181
189
|
const root = hydrateRoot(element, content);
|
|
182
|
-
|
|
190
|
+
window.__MANDU_ROOTS__.set(id, root);
|
|
183
191
|
|
|
184
192
|
// 상태 업데이트
|
|
185
193
|
element.setAttribute("data-mandu-hydrated", "true");
|
|
@@ -252,13 +260,13 @@ export function getHydrationState(): Readonly<HydrationState> {
|
|
|
252
260
|
* 특정 Island unmount
|
|
253
261
|
*/
|
|
254
262
|
export function unmountIsland(id: string): boolean {
|
|
255
|
-
const root =
|
|
263
|
+
const root = window.__MANDU_ROOTS__.get(id);
|
|
256
264
|
if (!root) {
|
|
257
265
|
return false;
|
|
258
266
|
}
|
|
259
267
|
|
|
260
268
|
root.unmount();
|
|
261
|
-
|
|
269
|
+
window.__MANDU_ROOTS__.delete(id);
|
|
262
270
|
return true;
|
|
263
271
|
}
|
|
264
272
|
|
|
@@ -266,9 +274,9 @@ export function unmountIsland(id: string): boolean {
|
|
|
266
274
|
* 모든 Island unmount
|
|
267
275
|
*/
|
|
268
276
|
export function unmountAllIslands(): void {
|
|
269
|
-
for (const [id, root] of
|
|
277
|
+
for (const [id, root] of window.__MANDU_ROOTS__) {
|
|
270
278
|
root.unmount();
|
|
271
|
-
|
|
279
|
+
window.__MANDU_ROOTS__.delete(id);
|
|
272
280
|
}
|
|
273
281
|
}
|
|
274
282
|
|