(
newComponent: any,
state: {
getRootKind: () => 'page' | 'frame';
setRootKind: (k: 'page' | 'frame') => void;
getCachedRoot: () => any;
setCachedRoot: (r: any) => void;
},
)
| 889 | } |
| 890 | |
| 891 | export function getRootForVue( |
| 892 | newComponent: any, |
| 893 | state: { |
| 894 | getRootKind: () => 'page' | 'frame'; |
| 895 | setRootKind: (k: 'page' | 'frame') => void; |
| 896 | getCachedRoot: () => any; |
| 897 | setCachedRoot: (r: any) => void; |
| 898 | }, |
| 899 | ): any { |
| 900 | const t0 = Date.now(); |
| 901 | if (__NS_ENV_VERBOSE__) console.log('[hmr-client] [createRoot] begin'); |
| 902 | ensureVueGlobals(); |
| 903 | const g = globalThis as any; |
| 904 | const AppFactory = g.createApp; |
| 905 | let RootCtor = g.NSVRoot as any; |
| 906 | // Hygiene: unmount any existing app instance to avoid duplicate lifecycle hooks |
| 907 | try { |
| 908 | const existing = (getCurrentApp() || g.__NS_VUE_APP__) as any; |
| 909 | if (existing && typeof existing.unmount === 'function') { |
| 910 | if (__NS_ENV_VERBOSE__) console.log('[hmr-client] [createRoot] unmounting existing app before remount'); |
| 911 | try { |
| 912 | existing.unmount(); |
| 913 | } catch {} |
| 914 | } |
| 915 | } catch {} |
| 916 | try { |
| 917 | if (!RootCtor) { |
| 918 | const registry: Map<string, any> | undefined = g.__nsVendorRegistry; |
| 919 | const req: any = registry?.get ? g.__nsVendorRequire || g.__nsRequire || g.require : g.__nsRequire || g.require; |
| 920 | let domMod: any = null; |
| 921 | if (registry && registry.has('nativescript-vue/dist/dom')) { |
| 922 | domMod = registry.get('nativescript-vue/dist/dom'); |
| 923 | if (__NS_ENV_VERBOSE__) console.log('[hmr-client] [createRoot] NS DOM from vendor registry'); |
| 924 | } else if (typeof req === 'function') { |
| 925 | try { |
| 926 | domMod = req('nativescript-vue/dist/dom'); |
| 927 | if (__NS_ENV_VERBOSE__) console.log('[hmr-client] [createRoot] NS DOM via require'); |
| 928 | } catch (e) { |
| 929 | if (__NS_ENV_VERBOSE__) console.warn('[hmr-client] [createRoot] NS DOM require failed', e); |
| 930 | } |
| 931 | } |
| 932 | if (domMod) { |
| 933 | const nsDom = (domMod && (domMod.default ?? domMod)) || domMod; |
| 934 | const ctor = nsDom?.NSVRoot || (nsDom?.default && nsDom.default.NSVRoot) || domMod?.NSVRoot; |
| 935 | if (ctor) RootCtor = ctor; |
| 936 | } |
| 937 | } |
| 938 | } catch {} |
| 939 | const existingApp = getCurrentApp() || g.__NS_VUE_APP__; |
| 940 | try { |
| 941 | ensureNsVueBootstrap(); |
| 942 | if (__NS_ENV_VERBOSE__) console.log('[hmr-client] [createRoot] ensured NS-Vue bootstrap'); |
| 943 | } catch (e) { |
| 944 | if (__NS_ENV_VERBOSE__) console.warn('[hmr-client] [createRoot] ensureNsVueBootstrap failed', e); |
| 945 | } |
| 946 | try { |
| 947 | if (typeof g.start === 'function' && !nsStartDone) { |
| 948 | if (__NS_ENV_VERBOSE__) console.log('[hmr-client] [createRoot] invoking global start()'); |
no test coverage detected