(payload: any)
| 302 | // Robust navigation fallback: create a sub-app and mount it on a new Page, then navigate there. |
| 303 | // __nsNavigateWithSubApp removed: no navigation fallbacks are used |
| 304 | function applyFullGraph(payload: any) { |
| 305 | if (typeof payload.version !== 'number' || !Array.isArray(payload.modules)) return; |
| 306 | graph.clear(); |
| 307 | payload.modules.forEach((m: any) => { |
| 308 | if (m && m.id) graph.set(m.id, { id: m.id, deps: m.deps || [], hash: m.hash || '' }); |
| 309 | }); |
| 310 | setGraphVersion(payload.version); |
| 311 | if (VERBOSE) console.log('[hmr][graph] full graph applied version', getGraphVersion(), 'modules=', graph.size); |
| 312 | // Guarded initial mount rescue: if app hasn't replaced the placeholder shortly after graph arrives, |
| 313 | // perform a one-time mount. This waits briefly to let the app's main entry start() run first to avoid double mounts. |
| 314 | try { |
| 315 | const g: any = globalThis as any; |
| 316 | const bootDone = !!g.__NS_HMR_BOOT_COMPLETE__; |
| 317 | if (!bootDone && !initialMounted && !initialMounting && !g.__NS_HMR_RESCUE_SCHEDULED__) { |
| 318 | // simple snapshot helpers |
| 319 | const getTopmost = () => { |
| 320 | try { |
| 321 | const F = getCore('Frame') || g.Frame; |
| 322 | return F?.topmost?.() || null; |
| 323 | } catch { |
| 324 | return null; |
| 325 | } |
| 326 | }; |
| 327 | const isPlaceholderView = (v: any) => { |
| 328 | try { |
| 329 | if (!v) return false; |
| 330 | if (v === (g.__NS_DEV_PLACEHOLDER_ROOT_VIEW__ || null)) return true; |
| 331 | return !!(v as any).__ns_dev_placeholder; |
| 332 | } catch { |
| 333 | return false; |
| 334 | } |
| 335 | }; |
| 336 | const hasRealRoot = () => { |
| 337 | try { |
| 338 | const fr = getTopmost(); |
| 339 | if (!fr) return false; |
| 340 | if (isPlaceholderView(fr)) return false; |
| 341 | const pg = (fr as any).currentPage || (fr as any)._currentEntry?.resolvedPage; |
| 342 | if (!pg) return false; |
| 343 | if (isPlaceholderView(pg)) return false; |
| 344 | return true; |
| 345 | } catch { |
| 346 | return false; |
| 347 | } |
| 348 | }; |
| 349 | try { |
| 350 | g.__NS_HMR_RESCUE_SCHEDULED__ = true; |
| 351 | } catch {} |
| 352 | setTimeout(() => { |
| 353 | try { |
| 354 | if (g.__NS_HMR_BOOT_COMPLETE__) return; // app already mounted |
| 355 | if (hasRealRoot()) { |
| 356 | try { |
| 357 | g.__NS_HMR_BOOT_COMPLETE__ = true; |
| 358 | } catch {} |
| 359 | if (VERBOSE) console.log('[hmr][init] detected real root after delay; skipping client initial mount'); |
| 360 | // Detach placeholder handler if still present |
| 361 | try { |
no test coverage detected