@nativescript/vite 8.0.0-beta.0 → 8.0.0-rc.0

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.
Files changed (577) hide show
  1. package/README.md +73 -14
  2. package/bin/cli.cjs +8 -14
  3. package/configuration/angular.d.ts +35 -2
  4. package/configuration/angular.js +541 -216
  5. package/configuration/angular.js.map +1 -1
  6. package/configuration/base.js +227 -77
  7. package/configuration/base.js.map +1 -1
  8. package/configuration/javascript.js +17 -96
  9. package/configuration/javascript.js.map +1 -1
  10. package/configuration/react.js +41 -73
  11. package/configuration/react.js.map +1 -1
  12. package/configuration/solid.js +58 -6
  13. package/configuration/solid.js.map +1 -1
  14. package/configuration/typescript.js +15 -96
  15. package/configuration/typescript.js.map +1 -1
  16. package/helpers/app-components.d.ts +2 -1
  17. package/helpers/app-components.js.map +1 -1
  18. package/helpers/app-css-refresh.d.ts +31 -0
  19. package/helpers/app-css-refresh.js +43 -0
  20. package/helpers/app-css-refresh.js.map +1 -0
  21. package/helpers/app-css-state.d.ts +17 -0
  22. package/helpers/app-css-state.js +51 -0
  23. package/helpers/app-css-state.js.map +1 -0
  24. package/helpers/bundler-context.d.ts +11 -0
  25. package/helpers/bundler-context.js +71 -0
  26. package/helpers/bundler-context.js.map +1 -0
  27. package/helpers/cli-flags.d.ts +12 -0
  28. package/helpers/cli-flags.js +34 -0
  29. package/helpers/cli-flags.js.map +1 -1
  30. package/helpers/commonjs-plugins.d.ts +5 -2
  31. package/helpers/commonjs-plugins.js +126 -0
  32. package/helpers/commonjs-plugins.js.map +1 -1
  33. package/helpers/config-as-json.js +10 -0
  34. package/helpers/config-as-json.js.map +1 -1
  35. package/helpers/css-platform-plugin.d.ts +14 -0
  36. package/helpers/css-platform-plugin.js +43 -25
  37. package/helpers/css-platform-plugin.js.map +1 -1
  38. package/helpers/dev-host.d.ts +360 -0
  39. package/helpers/dev-host.js +694 -0
  40. package/helpers/dev-host.js.map +1 -0
  41. package/helpers/dynamic-import-plugin.d.ts +2 -1
  42. package/helpers/dynamic-import-plugin.js +59 -53
  43. package/helpers/dynamic-import-plugin.js.map +1 -1
  44. package/helpers/esbuild-platform-resolver.js +9 -6
  45. package/helpers/esbuild-platform-resolver.js.map +1 -1
  46. package/helpers/external-configs.d.ts +10 -4
  47. package/helpers/external-configs.js +63 -15
  48. package/helpers/external-configs.js.map +1 -1
  49. package/helpers/flavor.d.ts +13 -0
  50. package/helpers/flavor.js +18 -1
  51. package/helpers/flavor.js.map +1 -1
  52. package/helpers/global-defines.d.ts +117 -0
  53. package/helpers/global-defines.js +209 -11
  54. package/helpers/global-defines.js.map +1 -1
  55. package/helpers/hmr-scope.d.ts +26 -0
  56. package/helpers/hmr-scope.js +67 -0
  57. package/helpers/hmr-scope.js.map +1 -0
  58. package/helpers/import-meta-path.d.ts +4 -0
  59. package/helpers/import-meta-path.js +5 -0
  60. package/helpers/import-meta-path.js.map +1 -0
  61. package/helpers/import-specifier.d.ts +1 -0
  62. package/helpers/import-specifier.js +18 -0
  63. package/helpers/import-specifier.js.map +1 -0
  64. package/helpers/init.js +6 -20
  65. package/helpers/init.js.map +1 -1
  66. package/helpers/logging.d.ts +1 -0
  67. package/helpers/logging.js +65 -4
  68. package/helpers/logging.js.map +1 -1
  69. package/helpers/main-entry.d.ts +8 -2
  70. package/helpers/main-entry.js +622 -120
  71. package/helpers/main-entry.js.map +1 -1
  72. package/helpers/nativeclass-esbuild-plugin.d.ts +2 -1
  73. package/helpers/nativeclass-esbuild-plugin.js +6 -1
  74. package/helpers/nativeclass-esbuild-plugin.js.map +1 -1
  75. package/helpers/nativeclass-transform.d.ts +13 -0
  76. package/helpers/nativeclass-transform.js +42 -131
  77. package/helpers/nativeclass-transform.js.map +1 -1
  78. package/helpers/nativeclass-transformer-plugin.d.ts +19 -1
  79. package/helpers/nativeclass-transformer-plugin.js +324 -37
  80. package/helpers/nativeclass-transformer-plugin.js.map +1 -1
  81. package/helpers/nativescript-package-resolver.js +10 -62
  82. package/helpers/nativescript-package-resolver.js.map +1 -1
  83. package/helpers/normalize-id.d.ts +42 -0
  84. package/helpers/normalize-id.js +60 -0
  85. package/helpers/normalize-id.js.map +1 -0
  86. package/helpers/ns-core-external-urls.d.ts +32 -0
  87. package/helpers/ns-core-external-urls.js +107 -0
  88. package/helpers/ns-core-external-urls.js.map +1 -0
  89. package/helpers/ns-core-url.d.ts +106 -0
  90. package/helpers/ns-core-url.js +225 -0
  91. package/helpers/ns-core-url.js.map +1 -0
  92. package/helpers/optimize-deps.d.ts +16 -0
  93. package/helpers/optimize-deps.js +17 -0
  94. package/helpers/optimize-deps.js.map +1 -0
  95. package/helpers/package-platform-aliases.js +34 -49
  96. package/helpers/package-platform-aliases.js.map +1 -1
  97. package/helpers/platform-types.d.ts +2 -0
  98. package/helpers/platform-types.js +2 -0
  99. package/helpers/platform-types.js.map +1 -0
  100. package/helpers/postcss-platform-config.d.ts +17 -1
  101. package/helpers/postcss-platform-config.js +20 -37
  102. package/helpers/postcss-platform-config.js.map +1 -1
  103. package/helpers/project.d.ts +35 -0
  104. package/helpers/project.js +120 -2
  105. package/helpers/project.js.map +1 -1
  106. package/helpers/resolve-main-field-platform.d.ts +20 -0
  107. package/helpers/resolve-main-field-platform.js +49 -0
  108. package/helpers/resolve-main-field-platform.js.map +1 -0
  109. package/helpers/resolver.js +17 -2
  110. package/helpers/resolver.js.map +1 -1
  111. package/helpers/theme-core-plugins.js +1 -1
  112. package/helpers/theme-core-plugins.js.map +1 -1
  113. package/helpers/ts-config-paths.d.ts +32 -0
  114. package/helpers/ts-config-paths.js +156 -27
  115. package/helpers/ts-config-paths.js.map +1 -1
  116. package/helpers/typescript-check.d.ts +2 -1
  117. package/helpers/typescript-check.js +4 -4
  118. package/helpers/typescript-check.js.map +1 -1
  119. package/helpers/ui-registration.d.ts +21 -0
  120. package/helpers/ui-registration.js +156 -0
  121. package/helpers/ui-registration.js.map +1 -0
  122. package/helpers/utils.d.ts +9 -0
  123. package/helpers/utils.js +22 -2
  124. package/helpers/utils.js.map +1 -1
  125. package/helpers/vite-package-version.d.ts +7 -0
  126. package/helpers/vite-package-version.js +44 -0
  127. package/helpers/vite-package-version.js.map +1 -0
  128. package/helpers/workers.d.ts +40 -19
  129. package/helpers/workers.js +312 -13
  130. package/helpers/workers.js.map +1 -1
  131. package/hmr/client/css-handler.d.ts +2 -1
  132. package/hmr/client/css-handler.js +95 -23
  133. package/hmr/client/css-handler.js.map +1 -1
  134. package/hmr/client/css-update-overlay.d.ts +18 -0
  135. package/hmr/client/css-update-overlay.js +27 -0
  136. package/hmr/client/css-update-overlay.js.map +1 -0
  137. package/hmr/client/framework-client-strategy.d.ts +87 -0
  138. package/hmr/client/framework-client-strategy.js +18 -0
  139. package/hmr/client/framework-client-strategy.js.map +1 -0
  140. package/hmr/client/hmr-pending-overlay.d.ts +13 -0
  141. package/hmr/client/hmr-pending-overlay.js +41 -0
  142. package/hmr/client/hmr-pending-overlay.js.map +1 -0
  143. package/hmr/client/hot-context.d.ts +67 -0
  144. package/hmr/client/hot-context.js +307 -0
  145. package/hmr/client/hot-context.js.map +1 -0
  146. package/hmr/client/index.d.ts +9 -1
  147. package/hmr/client/index.js +91 -1418
  148. package/hmr/client/index.js.map +1 -1
  149. package/hmr/client/overlay-driver.d.ts +10 -0
  150. package/hmr/client/overlay-driver.js +33 -0
  151. package/hmr/client/overlay-driver.js.map +1 -0
  152. package/hmr/client/protocol-dispatch.d.ts +8 -0
  153. package/hmr/client/protocol-dispatch.js +308 -0
  154. package/hmr/client/protocol-dispatch.js.map +1 -0
  155. package/hmr/client/root-reset.d.ts +15 -0
  156. package/hmr/client/root-reset.js +358 -0
  157. package/hmr/client/root-reset.js.map +1 -0
  158. package/hmr/client/strategy-loader.d.ts +24 -0
  159. package/hmr/client/strategy-loader.js +100 -0
  160. package/hmr/client/strategy-loader.js.map +1 -0
  161. package/hmr/client/update-pipeline.d.ts +27 -0
  162. package/hmr/client/update-pipeline.js +464 -0
  163. package/hmr/client/update-pipeline.js.map +1 -0
  164. package/hmr/client/utils.d.ts +14 -1
  165. package/hmr/client/utils.js +265 -54
  166. package/hmr/client/utils.js.map +1 -1
  167. package/hmr/client/ws-transport.d.ts +21 -0
  168. package/hmr/client/ws-transport.js +323 -0
  169. package/hmr/client/ws-transport.js.map +1 -0
  170. package/hmr/entry-runtime.d.ts +11 -0
  171. package/hmr/entry-runtime.js +566 -43
  172. package/hmr/entry-runtime.js.map +1 -1
  173. package/hmr/frameworks/angular/build/angular-linker.d.ts +12 -0
  174. package/hmr/frameworks/angular/build/angular-linker.js +113 -0
  175. package/hmr/frameworks/angular/build/angular-linker.js.map +1 -0
  176. package/hmr/frameworks/angular/build/inject-component-hmr-registration.d.ts +112 -0
  177. package/hmr/frameworks/angular/build/inject-component-hmr-registration.js +291 -0
  178. package/hmr/frameworks/angular/build/inject-component-hmr-registration.js.map +1 -0
  179. package/hmr/frameworks/angular/build/inject-hmr-vite-ignore.d.ts +75 -0
  180. package/hmr/frameworks/angular/build/inject-hmr-vite-ignore.js +221 -0
  181. package/hmr/frameworks/angular/build/inject-hmr-vite-ignore.js.map +1 -0
  182. package/hmr/frameworks/angular/build/inline-decorator-component-templates.d.ts +3 -0
  183. package/hmr/frameworks/angular/build/inline-decorator-component-templates.js +231 -0
  184. package/hmr/frameworks/angular/build/inline-decorator-component-templates.js.map +1 -0
  185. package/hmr/frameworks/angular/build/js-lexer.d.ts +4 -0
  186. package/hmr/frameworks/angular/build/js-lexer.js +182 -0
  187. package/hmr/frameworks/angular/build/js-lexer.js.map +1 -0
  188. package/hmr/frameworks/angular/build/linker-stats.d.ts +18 -0
  189. package/hmr/frameworks/angular/build/linker-stats.js +29 -0
  190. package/hmr/frameworks/angular/build/linker-stats.js.map +1 -0
  191. package/hmr/frameworks/angular/build/shared-linker.d.ts +39 -0
  192. package/hmr/frameworks/angular/build/shared-linker.js +128 -0
  193. package/hmr/frameworks/angular/build/shared-linker.js.map +1 -0
  194. package/hmr/frameworks/angular/build/synthesize-decorator-ctor-parameters.d.ts +1 -0
  195. package/hmr/frameworks/angular/build/synthesize-decorator-ctor-parameters.js +88 -0
  196. package/hmr/frameworks/angular/build/synthesize-decorator-ctor-parameters.js.map +1 -0
  197. package/hmr/frameworks/angular/build/synthesize-injectable-factories.d.ts +3 -0
  198. package/hmr/frameworks/angular/build/synthesize-injectable-factories.js +241 -0
  199. package/hmr/frameworks/angular/build/synthesize-injectable-factories.js.map +1 -0
  200. package/hmr/frameworks/angular/build/ts-fallback-transform.d.ts +5 -0
  201. package/hmr/frameworks/angular/build/ts-fallback-transform.js +138 -0
  202. package/hmr/frameworks/angular/build/ts-fallback-transform.js.map +1 -0
  203. package/{helpers/angular → hmr/frameworks/angular/build}/util.d.ts +1 -0
  204. package/hmr/frameworks/angular/build/util.js +155 -0
  205. package/hmr/frameworks/angular/build/util.js.map +1 -0
  206. package/hmr/frameworks/angular/build/worker-url-preserve.d.ts +5 -0
  207. package/hmr/frameworks/angular/build/worker-url-preserve.js +140 -0
  208. package/hmr/frameworks/angular/build/worker-url-preserve.js.map +1 -0
  209. package/hmr/frameworks/angular/client/index.d.ts +2 -1
  210. package/hmr/frameworks/angular/client/index.js +637 -23
  211. package/hmr/frameworks/angular/client/index.js.map +1 -1
  212. package/hmr/frameworks/angular/client/strategy.d.ts +9 -0
  213. package/hmr/frameworks/angular/client/strategy.js +19 -0
  214. package/hmr/frameworks/angular/client/strategy.js.map +1 -0
  215. package/hmr/frameworks/angular/server/angular-root-component.d.ts +79 -0
  216. package/hmr/frameworks/angular/server/angular-root-component.js +149 -0
  217. package/hmr/frameworks/angular/server/angular-root-component.js.map +1 -0
  218. package/hmr/frameworks/angular/server/linker.js +37 -6
  219. package/hmr/frameworks/angular/server/linker.js.map +1 -1
  220. package/hmr/frameworks/angular/server/ng-component-route.d.ts +43 -0
  221. package/hmr/frameworks/angular/server/ng-component-route.js +113 -0
  222. package/hmr/frameworks/angular/server/ng-component-route.js.map +1 -0
  223. package/hmr/frameworks/angular/server/strategy.js +697 -18
  224. package/hmr/frameworks/angular/server/strategy.js.map +1 -1
  225. package/hmr/frameworks/angular/server/websocket-angular-entry.d.ts +2 -0
  226. package/hmr/frameworks/angular/server/websocket-angular-entry.js +68 -0
  227. package/hmr/frameworks/angular/server/websocket-angular-entry.js.map +1 -0
  228. package/hmr/frameworks/angular/server/websocket-angular-hot-update.d.ts +94 -0
  229. package/hmr/frameworks/angular/server/websocket-angular-hot-update.js +485 -0
  230. package/hmr/frameworks/angular/server/websocket-angular-hot-update.js.map +1 -0
  231. package/hmr/frameworks/react/client/strategy.d.ts +12 -0
  232. package/hmr/frameworks/react/client/strategy.js +27 -0
  233. package/hmr/frameworks/react/client/strategy.js.map +1 -0
  234. package/hmr/frameworks/react/server/strategy.d.ts +2 -0
  235. package/hmr/frameworks/react/server/strategy.js +230 -0
  236. package/hmr/frameworks/react/server/strategy.js.map +1 -0
  237. package/hmr/frameworks/solid/build/solid-jsx-deps.d.ts +15 -0
  238. package/hmr/frameworks/solid/build/solid-jsx-deps.js +178 -0
  239. package/hmr/frameworks/solid/build/solid-jsx-deps.js.map +1 -0
  240. package/hmr/frameworks/solid/client/app-runtime.d.ts +68 -0
  241. package/hmr/frameworks/solid/client/app-runtime.js +252 -0
  242. package/hmr/frameworks/solid/client/app-runtime.js.map +1 -0
  243. package/hmr/frameworks/solid/client/strategy.d.ts +7 -0
  244. package/hmr/frameworks/solid/client/strategy.js +391 -0
  245. package/hmr/frameworks/solid/client/strategy.js.map +1 -0
  246. package/hmr/frameworks/solid/server/strategy.js +293 -16
  247. package/hmr/frameworks/solid/server/strategy.js.map +1 -1
  248. package/hmr/frameworks/typescript/client/strategy.d.ts +7 -0
  249. package/hmr/frameworks/typescript/client/strategy.js +418 -0
  250. package/hmr/frameworks/typescript/client/strategy.js.map +1 -0
  251. package/hmr/frameworks/typescript/server/strategy.js +48 -16
  252. package/hmr/frameworks/typescript/server/strategy.js.map +1 -1
  253. package/hmr/frameworks/vue/client/dep-propagation.d.ts +44 -0
  254. package/hmr/frameworks/vue/client/dep-propagation.js +148 -0
  255. package/hmr/frameworks/vue/client/dep-propagation.js.map +1 -0
  256. package/hmr/frameworks/vue/client/index.d.ts +10 -1
  257. package/hmr/frameworks/vue/client/index.js +287 -562
  258. package/hmr/frameworks/vue/client/index.js.map +1 -1
  259. package/hmr/frameworks/vue/client/navigate-app.d.ts +3 -0
  260. package/hmr/frameworks/vue/client/navigate-app.js +178 -0
  261. package/hmr/frameworks/vue/client/navigate-app.js.map +1 -0
  262. package/hmr/frameworks/vue/client/strategy.d.ts +33 -0
  263. package/hmr/frameworks/vue/client/strategy.js +152 -0
  264. package/hmr/frameworks/vue/client/strategy.js.map +1 -0
  265. package/hmr/frameworks/vue/client/vue-sfc-update-overlay.d.ts +49 -0
  266. package/hmr/frameworks/vue/client/vue-sfc-update-overlay.js +124 -0
  267. package/hmr/frameworks/vue/client/vue-sfc-update-overlay.js.map +1 -0
  268. package/hmr/frameworks/vue/server/compiler.d.ts +3 -1
  269. package/hmr/frameworks/vue/server/compiler.js +3 -1
  270. package/hmr/frameworks/vue/server/compiler.js.map +1 -1
  271. package/hmr/frameworks/vue/server/sfc-route-assemble.d.ts +7 -0
  272. package/hmr/frameworks/vue/server/sfc-route-assemble.js +823 -0
  273. package/hmr/frameworks/vue/server/sfc-route-assemble.js.map +1 -0
  274. package/hmr/frameworks/vue/server/sfc-route-meta.d.ts +7 -0
  275. package/hmr/frameworks/vue/server/sfc-route-meta.js +80 -0
  276. package/hmr/frameworks/vue/server/sfc-route-meta.js.map +1 -0
  277. package/hmr/frameworks/vue/server/sfc-route-serve.d.ts +8 -0
  278. package/hmr/frameworks/vue/server/sfc-route-serve.js +462 -0
  279. package/hmr/frameworks/vue/server/sfc-route-serve.js.map +1 -0
  280. package/hmr/frameworks/vue/server/sfc-route-shared.d.ts +45 -0
  281. package/hmr/frameworks/vue/server/sfc-route-shared.js +105 -0
  282. package/hmr/frameworks/vue/server/sfc-route-shared.js.map +1 -0
  283. package/hmr/frameworks/vue/server/strategy.d.ts +35 -0
  284. package/hmr/frameworks/vue/server/strategy.js +291 -7
  285. package/hmr/frameworks/vue/server/strategy.js.map +1 -1
  286. package/hmr/frameworks/vue/server/websocket-sfc.d.ts +15 -0
  287. package/hmr/frameworks/vue/server/websocket-sfc.js +20 -0
  288. package/hmr/frameworks/vue/server/websocket-sfc.js.map +1 -0
  289. package/hmr/helpers/ast-normalizer.d.ts +3 -1
  290. package/hmr/helpers/ast-normalizer.js +131 -24
  291. package/hmr/helpers/ast-normalizer.js.map +1 -1
  292. package/hmr/helpers/cjs-named-exports.d.ts +23 -0
  293. package/hmr/helpers/cjs-named-exports.js +152 -0
  294. package/hmr/helpers/cjs-named-exports.js.map +1 -0
  295. package/hmr/helpers/package-exports.d.ts +16 -0
  296. package/hmr/helpers/package-exports.js +396 -0
  297. package/hmr/helpers/package-exports.js.map +1 -0
  298. package/hmr/helpers/vendor-rewrite.d.ts +1 -1
  299. package/hmr/helpers/vendor-rewrite.js +5 -3
  300. package/hmr/helpers/vendor-rewrite.js.map +1 -1
  301. package/hmr/server/boot-recording.d.ts +51 -0
  302. package/hmr/server/boot-recording.js +214 -0
  303. package/hmr/server/boot-recording.js.map +1 -0
  304. package/hmr/server/constants.d.ts +1 -0
  305. package/hmr/server/constants.js +21 -4
  306. package/hmr/server/constants.js.map +1 -1
  307. package/hmr/server/content-css-update.d.ts +54 -0
  308. package/hmr/server/content-css-update.js +78 -0
  309. package/hmr/server/content-css-update.js.map +1 -0
  310. package/hmr/server/core-bundle.d.ts +140 -0
  311. package/hmr/server/core-bundle.js +614 -0
  312. package/hmr/server/core-bundle.js.map +1 -0
  313. package/hmr/server/core-sanitize.d.ts +130 -4
  314. package/hmr/server/core-sanitize.js +393 -32
  315. package/hmr/server/core-sanitize.js.map +1 -1
  316. package/hmr/server/css-connect-sync.d.ts +28 -0
  317. package/hmr/server/css-connect-sync.js +59 -0
  318. package/hmr/server/css-connect-sync.js.map +1 -0
  319. package/hmr/server/css-device-module.d.ts +28 -0
  320. package/hmr/server/css-device-module.js +44 -0
  321. package/hmr/server/css-device-module.js.map +1 -0
  322. package/hmr/server/css-update-message.d.ts +23 -0
  323. package/hmr/server/css-update-message.js +41 -0
  324. package/hmr/server/css-update-message.js.map +1 -0
  325. package/hmr/server/deps-bundle.d.ts +233 -0
  326. package/hmr/server/deps-bundle.js +1022 -0
  327. package/hmr/server/deps-bundle.js.map +1 -0
  328. package/hmr/server/device-transform-helpers.d.ts +24 -0
  329. package/hmr/server/device-transform-helpers.js +408 -0
  330. package/hmr/server/device-transform-helpers.js.map +1 -0
  331. package/hmr/server/framework-strategy.d.ts +182 -11
  332. package/hmr/server/hmr-module-graph.d.ts +37 -0
  333. package/hmr/server/hmr-module-graph.js +215 -0
  334. package/hmr/server/hmr-module-graph.js.map +1 -0
  335. package/hmr/server/import-map.d.ts +99 -0
  336. package/hmr/server/import-map.js +294 -0
  337. package/hmr/server/import-map.js.map +1 -0
  338. package/hmr/server/index.d.ts +2 -1
  339. package/hmr/server/index.js +7 -16
  340. package/hmr/server/index.js.map +1 -1
  341. package/hmr/server/node-builtins-route.d.ts +12 -0
  342. package/hmr/server/node-builtins-route.js +86 -0
  343. package/hmr/server/node-builtins-route.js.map +1 -0
  344. package/hmr/server/ns-core-cjs-shape.d.ts +204 -0
  345. package/hmr/server/ns-core-cjs-shape.js +271 -0
  346. package/hmr/server/ns-core-cjs-shape.js.map +1 -0
  347. package/hmr/server/ns-m-response-memo.d.ts +10 -0
  348. package/hmr/server/ns-m-response-memo.js +33 -0
  349. package/hmr/server/ns-m-response-memo.js.map +1 -0
  350. package/hmr/server/ns-rt-bridge.d.ts +51 -0
  351. package/hmr/server/ns-rt-bridge.js +131 -0
  352. package/hmr/server/ns-rt-bridge.js.map +1 -0
  353. package/hmr/server/ns-rt-route.d.ts +5 -0
  354. package/hmr/server/ns-rt-route.js +39 -0
  355. package/hmr/server/ns-rt-route.js.map +1 -0
  356. package/hmr/server/perf-instrumentation.d.ts +114 -0
  357. package/hmr/server/perf-instrumentation.js +197 -0
  358. package/hmr/server/perf-instrumentation.js.map +1 -0
  359. package/hmr/server/process-code-for-device.d.ts +44 -0
  360. package/hmr/server/process-code-for-device.js +834 -0
  361. package/hmr/server/process-code-for-device.js.map +1 -0
  362. package/hmr/server/require-guard.d.ts +1 -0
  363. package/hmr/server/require-guard.js +12 -0
  364. package/hmr/server/require-guard.js.map +1 -0
  365. package/hmr/server/rewrite-imports.d.ts +2 -0
  366. package/hmr/server/rewrite-imports.js +631 -0
  367. package/hmr/server/rewrite-imports.js.map +1 -0
  368. package/hmr/server/route-helpers.d.ts +7 -0
  369. package/hmr/server/route-helpers.js +13 -0
  370. package/hmr/server/route-helpers.js.map +1 -0
  371. package/hmr/server/runtime-graph-filter.d.ts +5 -0
  372. package/hmr/server/runtime-graph-filter.js +28 -0
  373. package/hmr/server/runtime-graph-filter.js.map +1 -0
  374. package/hmr/server/server-origin.d.ts +2 -0
  375. package/hmr/server/server-origin.js +88 -0
  376. package/hmr/server/server-origin.js.map +1 -0
  377. package/hmr/server/shared-transform-request.d.ts +12 -0
  378. package/hmr/server/shared-transform-request.js +143 -0
  379. package/hmr/server/shared-transform-request.js.map +1 -0
  380. package/hmr/server/socket-utils.d.ts +10 -0
  381. package/hmr/server/socket-utils.js +14 -0
  382. package/hmr/server/socket-utils.js.map +1 -0
  383. package/hmr/server/transform-cache-invalidation.d.ts +37 -0
  384. package/hmr/server/transform-cache-invalidation.js +156 -0
  385. package/hmr/server/transform-cache-invalidation.js.map +1 -0
  386. package/hmr/server/vendor-bare-module-shims.d.ts +4 -0
  387. package/hmr/server/vendor-bare-module-shims.js +80 -0
  388. package/hmr/server/vendor-bare-module-shims.js.map +1 -0
  389. package/hmr/server/vite-plugin.d.ts +22 -1
  390. package/hmr/server/vite-plugin.js +655 -58
  391. package/hmr/server/vite-plugin.js.map +1 -1
  392. package/hmr/server/websocket-core-bridge.d.ts +68 -0
  393. package/hmr/server/websocket-core-bridge.js +370 -0
  394. package/hmr/server/websocket-core-bridge.js.map +1 -0
  395. package/hmr/server/websocket-device-transform.d.ts +3 -0
  396. package/hmr/server/websocket-device-transform.js +7 -0
  397. package/hmr/server/websocket-device-transform.js.map +1 -0
  398. package/hmr/server/websocket-graph-upsert.d.ts +21 -0
  399. package/hmr/server/websocket-graph-upsert.js +33 -0
  400. package/hmr/server/websocket-graph-upsert.js.map +1 -0
  401. package/hmr/server/websocket-hmr-pending.d.ts +29 -0
  402. package/hmr/server/websocket-hmr-pending.js +33 -0
  403. package/hmr/server/websocket-hmr-pending.js.map +1 -0
  404. package/hmr/server/websocket-hot-update.d.ts +80 -0
  405. package/hmr/server/websocket-hot-update.js +295 -0
  406. package/hmr/server/websocket-hot-update.js.map +1 -0
  407. package/hmr/server/websocket-import-map-route.d.ts +15 -0
  408. package/hmr/server/websocket-import-map-route.js +51 -0
  409. package/hmr/server/websocket-import-map-route.js.map +1 -0
  410. package/hmr/server/websocket-module-bindings.d.ts +21 -0
  411. package/hmr/server/websocket-module-bindings.js +504 -0
  412. package/hmr/server/websocket-module-bindings.js.map +1 -0
  413. package/hmr/server/websocket-module-specifiers.d.ts +96 -0
  414. package/hmr/server/websocket-module-specifiers.js +819 -0
  415. package/hmr/server/websocket-module-specifiers.js.map +1 -0
  416. package/hmr/server/websocket-ns-core.d.ts +34 -0
  417. package/hmr/server/websocket-ns-core.js +414 -0
  418. package/hmr/server/websocket-ns-core.js.map +1 -0
  419. package/hmr/server/websocket-ns-entry.d.ts +21 -0
  420. package/hmr/server/websocket-ns-entry.js +163 -0
  421. package/hmr/server/websocket-ns-entry.js.map +1 -0
  422. package/hmr/server/websocket-ns-m-paths.d.ts +19 -0
  423. package/hmr/server/websocket-ns-m-paths.js +115 -0
  424. package/hmr/server/websocket-ns-m-paths.js.map +1 -0
  425. package/hmr/server/websocket-ns-m-request.d.ts +46 -0
  426. package/hmr/server/websocket-ns-m-request.js +197 -0
  427. package/hmr/server/websocket-ns-m-request.js.map +1 -0
  428. package/hmr/server/websocket-ns-m.d.ts +52 -0
  429. package/hmr/server/websocket-ns-m.js +590 -0
  430. package/hmr/server/websocket-ns-m.js.map +1 -0
  431. package/hmr/server/websocket-served-module-helpers.d.ts +89 -0
  432. package/hmr/server/websocket-served-module-helpers.js +935 -0
  433. package/hmr/server/websocket-served-module-helpers.js.map +1 -0
  434. package/hmr/server/websocket-txn.d.ts +6 -0
  435. package/hmr/server/websocket-txn.js +42 -0
  436. package/hmr/server/websocket-txn.js.map +1 -0
  437. package/hmr/server/websocket-vendor-unifier.d.ts +9 -0
  438. package/hmr/server/websocket-vendor-unifier.js +46 -0
  439. package/hmr/server/websocket-vendor-unifier.js.map +1 -0
  440. package/hmr/server/websocket.d.ts +7 -17
  441. package/hmr/server/websocket.js +723 -5376
  442. package/hmr/server/websocket.js.map +1 -1
  443. package/hmr/shared/ns-globals.d.ts +107 -0
  444. package/hmr/shared/ns-globals.js +29 -0
  445. package/hmr/shared/ns-globals.js.map +1 -0
  446. package/hmr/shared/package-classifier.d.ts +9 -0
  447. package/hmr/shared/package-classifier.js +58 -0
  448. package/hmr/shared/package-classifier.js.map +1 -0
  449. package/hmr/shared/protocol.d.ts +157 -0
  450. package/hmr/shared/protocol.js +28 -0
  451. package/hmr/shared/protocol.js.map +1 -0
  452. package/hmr/shared/runtime/boot-complete.d.ts +14 -0
  453. package/hmr/shared/runtime/boot-complete.js +32 -0
  454. package/hmr/shared/runtime/boot-complete.js.map +1 -0
  455. package/hmr/shared/runtime/boot-placeholder-ui.d.ts +69 -0
  456. package/hmr/shared/runtime/boot-placeholder-ui.js +101 -0
  457. package/hmr/shared/runtime/boot-placeholder-ui.js.map +1 -0
  458. package/hmr/shared/runtime/boot-progress.d.ts +44 -0
  459. package/hmr/shared/runtime/boot-progress.js +134 -0
  460. package/hmr/shared/runtime/boot-progress.js.map +1 -0
  461. package/hmr/shared/runtime/boot-timeline.d.ts +17 -0
  462. package/hmr/shared/runtime/boot-timeline.js +40 -0
  463. package/hmr/shared/runtime/boot-timeline.js.map +1 -0
  464. package/hmr/shared/runtime/browser-runtime-contract.d.ts +97 -0
  465. package/hmr/shared/runtime/browser-runtime-contract.js +66 -0
  466. package/hmr/shared/runtime/browser-runtime-contract.js.map +1 -0
  467. package/hmr/shared/runtime/dev-overlay-ios.d.ts +87 -0
  468. package/hmr/shared/runtime/dev-overlay-ios.js +521 -0
  469. package/hmr/shared/runtime/dev-overlay-ios.js.map +1 -0
  470. package/hmr/shared/runtime/dev-overlay-shared.d.ts +58 -0
  471. package/hmr/shared/runtime/dev-overlay-shared.js +116 -0
  472. package/hmr/shared/runtime/dev-overlay-shared.js.map +1 -0
  473. package/hmr/shared/runtime/dev-overlay-snapshots.d.ts +31 -0
  474. package/hmr/shared/runtime/dev-overlay-snapshots.js +324 -0
  475. package/hmr/shared/runtime/dev-overlay-snapshots.js.map +1 -0
  476. package/hmr/shared/runtime/dev-overlay-tree.d.ts +59 -0
  477. package/hmr/shared/runtime/dev-overlay-tree.js +712 -0
  478. package/hmr/shared/runtime/dev-overlay-tree.js.map +1 -0
  479. package/hmr/shared/runtime/dev-overlay.d.ts +39 -0
  480. package/hmr/shared/runtime/dev-overlay.js +292 -0
  481. package/hmr/shared/runtime/dev-overlay.js.map +1 -0
  482. package/hmr/shared/runtime/global-scope.d.ts +18 -0
  483. package/hmr/shared/runtime/global-scope.js +21 -0
  484. package/hmr/shared/runtime/global-scope.js.map +1 -0
  485. package/hmr/shared/runtime/hooks.js +2 -1
  486. package/hmr/shared/runtime/hooks.js.map +1 -1
  487. package/hmr/shared/runtime/launch-bridge.d.ts +9 -0
  488. package/hmr/shared/runtime/launch-bridge.js +98 -0
  489. package/hmr/shared/runtime/launch-bridge.js.map +1 -0
  490. package/hmr/shared/runtime/module-provenance.d.ts +1 -0
  491. package/hmr/shared/runtime/module-provenance.js +64 -0
  492. package/hmr/shared/runtime/module-provenance.js.map +1 -0
  493. package/hmr/shared/runtime/ns-runtime-test-double.d.ts +21 -0
  494. package/hmr/shared/runtime/ns-runtime-test-double.js +20 -0
  495. package/hmr/shared/runtime/ns-runtime-test-double.js.map +1 -0
  496. package/hmr/shared/runtime/overlay-flag.d.ts +9 -0
  497. package/hmr/shared/runtime/overlay-flag.js +34 -0
  498. package/hmr/shared/runtime/overlay-flag.js.map +1 -0
  499. package/hmr/shared/runtime/platform-polyfills.d.ts +26 -0
  500. package/hmr/shared/runtime/platform-polyfills.js +122 -0
  501. package/hmr/shared/runtime/platform-polyfills.js.map +1 -0
  502. package/hmr/shared/runtime/root-placeholder-view.d.ts +19 -0
  503. package/hmr/shared/runtime/root-placeholder-view.js +311 -0
  504. package/hmr/shared/runtime/root-placeholder-view.js.map +1 -0
  505. package/hmr/shared/runtime/root-placeholder.d.ts +1 -0
  506. package/hmr/shared/runtime/root-placeholder.js +778 -83
  507. package/hmr/shared/runtime/root-placeholder.js.map +1 -1
  508. package/hmr/shared/runtime/session-bootstrap.d.ts +1 -0
  509. package/hmr/shared/runtime/session-bootstrap.js +350 -0
  510. package/hmr/shared/runtime/session-bootstrap.js.map +1 -0
  511. package/hmr/shared/runtime/vendor-bootstrap.js +54 -16
  512. package/hmr/shared/runtime/vendor-bootstrap.js.map +1 -1
  513. package/hmr/shared/runtime/vendor-resolve.d.ts +22 -0
  514. package/hmr/shared/runtime/vendor-resolve.js +45 -0
  515. package/hmr/shared/runtime/vendor-resolve.js.map +1 -0
  516. package/hmr/shared/runtime/worker-tracking.d.ts +28 -0
  517. package/hmr/shared/runtime/worker-tracking.js +114 -0
  518. package/hmr/shared/runtime/worker-tracking.js.map +1 -0
  519. package/hmr/shared/vendor/manifest-collect.d.ts +4 -0
  520. package/hmr/shared/vendor/manifest-collect.js +909 -0
  521. package/hmr/shared/vendor/manifest-collect.js.map +1 -0
  522. package/hmr/shared/vendor/manifest-loader.d.ts +2 -1
  523. package/hmr/shared/vendor/manifest-loader.js +5 -3
  524. package/hmr/shared/vendor/manifest-loader.js.map +1 -1
  525. package/hmr/shared/vendor/manifest.d.ts +12 -0
  526. package/hmr/shared/vendor/manifest.js +341 -545
  527. package/hmr/shared/vendor/manifest.js.map +1 -1
  528. package/hmr/shared/vendor/registry.d.ts +2 -0
  529. package/hmr/shared/vendor/registry.js +118 -7
  530. package/hmr/shared/vendor/registry.js.map +1 -1
  531. package/hmr/shared/vendor/vendor-device-shim.d.ts +1 -0
  532. package/hmr/shared/vendor/vendor-device-shim.js +208 -0
  533. package/hmr/shared/vendor/vendor-device-shim.js.map +1 -0
  534. package/hmr/shared/vendor/vendor-esbuild-plugins.d.ts +107 -0
  535. package/hmr/shared/vendor/vendor-esbuild-plugins.js +540 -0
  536. package/hmr/shared/vendor/vendor-esbuild-plugins.js.map +1 -0
  537. package/index.d.ts +1 -0
  538. package/index.js +5 -0
  539. package/index.js.map +1 -1
  540. package/package.json +76 -14
  541. package/runtime/core-aliases-early.js +103 -81
  542. package/runtime/core-aliases-early.js.map +1 -1
  543. package/shims/react-jsx-runtime.d.ts +4 -0
  544. package/shims/react-jsx-runtime.js +61 -0
  545. package/shims/react-jsx-runtime.js.map +1 -0
  546. package/shims/solid-jsx-runtime.d.ts +7 -0
  547. package/shims/solid-jsx-runtime.js +17 -0
  548. package/shims/solid-jsx-runtime.js.map +1 -0
  549. package/helpers/angular/angular-linker.d.ts +0 -13
  550. package/helpers/angular/angular-linker.js +0 -189
  551. package/helpers/angular/angular-linker.js.map +0 -1
  552. package/helpers/angular/shared-linker.d.ts +0 -4
  553. package/helpers/angular/shared-linker.js +0 -39
  554. package/helpers/angular/shared-linker.js.map +0 -1
  555. package/helpers/angular/util.js +0 -67
  556. package/helpers/angular/util.js.map +0 -1
  557. package/helpers/module-runner-patch.d.ts +0 -3
  558. package/helpers/module-runner-patch.js +0 -63
  559. package/helpers/module-runner-patch.js.map +0 -1
  560. package/helpers/prelink-angular.d.ts +0 -2
  561. package/helpers/prelink-angular.js +0 -117
  562. package/helpers/prelink-angular.js.map +0 -1
  563. package/hmr/shared/runtime/http-only-boot.d.ts +0 -1
  564. package/hmr/shared/runtime/http-only-boot.js +0 -124
  565. package/hmr/shared/runtime/http-only-boot.js.map +0 -1
  566. package/hmr/vendor-bootstrap.d.ts +0 -3
  567. package/hmr/vendor-bootstrap.js +0 -32
  568. package/hmr/vendor-bootstrap.js.map +0 -1
  569. package/shims/react-reconciler-constants.d.ts +0 -14
  570. package/shims/react-reconciler-constants.js +0 -21
  571. package/shims/react-reconciler-constants.js.map +0 -1
  572. package/shims/react-reconciler.d.ts +0 -8
  573. package/shims/react-reconciler.js +0 -15
  574. package/shims/react-reconciler.js.map +0 -1
  575. package/transformers/NativeClass/index.d.ts +0 -2
  576. package/transformers/NativeClass/index.js +0 -222
  577. package/transformers/NativeClass/index.js.map +0 -1
@@ -1,1445 +1,101 @@
1
1
  /**
2
- * Robust HMR client for NativeScript.
2
+ * HMR client entry for NativeScript devices.
3
3
  *
4
4
  * Avoid importing from '@nativescript/core' and other framework modules here to prevent creating a second module realm via HTTP ESM.
5
5
  * Always resolve core classes and Application from the vendor realm or globalThis at runtime.
6
6
  * The HMR client is evaluated via HTTP ESM on device; static imports would create secondary instances.
7
+ *
8
+ * This entry owns boot-time side effects (core aliases, launch-notification
9
+ * bridge, CSS register) and wires the seams together:
10
+ * - `ws-transport.ts` — socket connect/reconnect + connection overlay
11
+ * - `protocol-dispatch.ts` — routes parsed wire messages
12
+ * - `update-pipeline.ts` — graph state + evict-then-reimport queue
13
+ * - `root-reset.ts` — root-view replacement
14
+ * - `strategy-loader.ts` — flavor detection + framework strategy loading
7
15
  */
8
- import { setHMRWsUrl, getHMRWsUrl, pendingModuleFetches, deriveHttpOrigin, setHttpOriginForVite, moduleFetchCache, requestModuleFromServer, getHttpOriginForVite, normalizeSpec, hmrMetrics, graph, setGraphVersion, getGraphVersion, getCurrentApp, getRootFrame, setCurrentApp, setRootFrame, getCore } from './utils.js';
9
- import { handleCssUpdates } from './css-handler.js';
10
- const VERBOSE = typeof __NS_ENV_VERBOSE__ !== 'undefined' && __NS_ENV_VERBOSE__;
11
- const APP_ROOT_VIRTUAL = typeof __NS_APP_ROOT_VIRTUAL__ === 'string' && __NS_APP_ROOT_VIRTUAL__ ? __NS_APP_ROOT_VIRTUAL__ : '/src';
12
- const APP_VIRTUAL_WITH_SLASH = APP_ROOT_VIRTUAL.endsWith('/') ? APP_ROOT_VIRTUAL : `${APP_ROOT_VIRTUAL}/`;
13
- const APP_MAIN_ENTRY_SPEC = `${APP_VIRTUAL_WITH_SLASH}app.ts`;
14
- // Policy: by default, let the app's own main entry mount initially; HMR client handles updates/remounts only.
15
- // Flip this to true via global __NS_HMR_ALLOW_INITIAL_MOUNT__ if you need the client to perform the first mount.
16
- const ALLOW_INITIAL_MOUNT = !!globalThis.__NS_HMR_ALLOW_INITIAL_MOUNT__;
17
- // Ensure core aliases are present on globalThis early so that /ns/rt exports resolve to functions
16
+ import { setHMRWsUrl, getHMRWsUrl, getCore, ENV_VERBOSE } from './utils.js';
17
+ import { applyCssText } from './css-handler.js';
18
+ import { getGlobalScope } from '../shared/runtime/global-scope.js';
19
+ import { installLaunchNotificationBridge } from '../shared/runtime/launch-bridge.js';
20
+ import { connectHmr, setHmrMessageHandler } from './ws-transport.js';
21
+ import { handleHmrMessage } from './protocol-dispatch.js';
22
+ import { ensureCoreAliasesOnGlobalThis, performResetRoot } from './root-reset.js';
23
+ import { CLIENT_STRATEGY_READY, getClientStrategy } from './strategy-loader.js';
24
+ const VERBOSE = ENV_VERBOSE;
25
+ // Apply once on module evaluation so that /ns/rt exports resolve to functions
18
26
  // before any SFCs are evaluated during HTTP-only dev boot.
19
- function ensureCoreAliasesOnGlobalThis() {
20
- const g = globalThis;
21
- try {
22
- const F = getCore('Frame') || g.Frame;
23
- const A = getCore('Application') || g.Application;
24
- const P = getCore('Page') || g.Page;
25
- // Publish to globalThis if missing
26
- try {
27
- if (F && !g.Frame)
28
- g.Frame = F;
29
- }
30
- catch { }
31
- try {
32
- if (A && !g.Application)
33
- g.Application = A;
34
- }
35
- catch { }
36
- try {
37
- if (P && !g.Page)
38
- g.Page = P;
39
- }
40
- catch { }
41
- }
42
- catch { }
43
- }
44
- // Apply once on module evaluation
45
27
  ensureCoreAliasesOnGlobalThis();
46
- /**
47
- * Flavor hooks
48
- */
49
- import { installNsVueDevShims, ensureBackWrapperInstalled, getRootForVue, loadSfcComponent, ensureVueGlobals, ensurePiniaOnApp, addSfcMapping, recordVuePayloadChanges, handleVueSfcRegistry, handleVueSfcRegistryUpdate } from '../frameworks/vue/client/index.js';
50
- import { handleAngularHotUpdateMessage, installAngularHmrClientHooks } from '../frameworks/angular/client/index.js';
51
- switch (__NS_TARGET_FLAVOR__) {
52
- case 'vue':
53
- installNsVueDevShims();
54
- break;
55
- case 'angular':
56
- installAngularHmrClientHooks();
57
- break;
58
- }
59
- // Track whether we've mounted an initial app root yet in HTTP-only boot
60
- let initialMounted = !!globalThis.__NS_HMR_BOOT_COMPLETE__;
61
- // Prevent duplicate initial-mount scheduling across rapid full-graph broadcasts and re-evaluations
62
- let initialMounting = !!globalThis.__NS_HMR_INITIAL_MOUNT_IN_PROGRESS__;
63
- // TypeScript flavor: track registry modules and inferred main id
64
- let tsModuleSet = null;
65
- let tsMainId = null;
66
- const changedQueue = [];
67
- let processingQueue = false;
68
- let processingPromise = null;
69
- // Detect whether the early placeholder root is still active on screen
70
- function isPlaceholderActive() {
71
- try {
72
- const g = globalThis;
73
- if (g.__NS_DEV_PLACEHOLDER_ROOT_VIEW__)
74
- return true;
75
- if (g.__NS_DEV_PLACEHOLDER_ROOT_EARLY__)
76
- return true;
77
- }
78
- catch { }
79
- return false;
80
- }
81
- // Navigation queue removed: we navigate immediately or throw with a clear error
82
- // Robust navigation fallback: create a sub-app and mount it on a new Page, then navigate there.
83
- // __nsNavigateWithSubApp removed: no navigation fallbacks are used
84
- function applyFullGraph(payload) {
85
- if (typeof payload.version !== 'number' || !Array.isArray(payload.modules))
86
- return;
87
- graph.clear();
88
- payload.modules.forEach((m) => {
89
- if (m && m.id)
90
- graph.set(m.id, { id: m.id, deps: m.deps || [], hash: m.hash || '' });
91
- });
92
- setGraphVersion(payload.version);
93
- if (VERBOSE)
94
- console.log('[hmr][graph] full graph applied version', getGraphVersion(), 'modules=', graph.size);
95
- // Guarded initial mount rescue: if app hasn't replaced the placeholder shortly after graph arrives,
96
- // perform a one-time mount. This waits briefly to let the app's main entry start() run first to avoid double mounts.
97
- try {
98
- const g = globalThis;
99
- const bootDone = !!g.__NS_HMR_BOOT_COMPLETE__;
100
- if (!bootDone && !initialMounted && !initialMounting && !g.__NS_HMR_RESCUE_SCHEDULED__) {
101
- // simple snapshot helpers
102
- const getTopmost = () => {
103
- try {
104
- const F = getCore('Frame') || g.Frame;
105
- return F?.topmost?.() || null;
106
- }
107
- catch {
108
- return null;
109
- }
110
- };
111
- const isPlaceholderView = (v) => {
112
- try {
113
- if (!v)
114
- return false;
115
- if (v === (g.__NS_DEV_PLACEHOLDER_ROOT_VIEW__ || null))
116
- return true;
117
- return !!v.__ns_dev_placeholder;
118
- }
119
- catch {
120
- return false;
121
- }
122
- };
123
- const hasRealRoot = () => {
124
- try {
125
- const fr = getTopmost();
126
- if (!fr)
127
- return false;
128
- if (isPlaceholderView(fr))
129
- return false;
130
- const pg = fr.currentPage || fr._currentEntry?.resolvedPage;
131
- if (!pg)
132
- return false;
133
- if (isPlaceholderView(pg))
134
- return false;
135
- return true;
136
- }
137
- catch {
138
- return false;
139
- }
140
- };
141
- try {
142
- g.__NS_HMR_RESCUE_SCHEDULED__ = true;
143
- }
144
- catch { }
145
- setTimeout(() => {
146
- try {
147
- if (g.__NS_HMR_BOOT_COMPLETE__)
148
- return; // app already mounted
149
- if (hasRealRoot()) {
150
- try {
151
- g.__NS_HMR_BOOT_COMPLETE__ = true;
152
- }
153
- catch { }
154
- if (VERBOSE)
155
- console.log('[hmr][init] detected real root after delay; skipping client initial mount');
156
- // Detach placeholder handler if still present
157
- try {
158
- const restore = g.__NS_DEV_RESTORE_PLACEHOLDER__;
159
- if (typeof restore === 'function')
160
- restore();
161
- }
162
- catch { }
163
- return;
164
- }
165
- // If placeholder still active and no real root, try a one-time gentle initial mount.
166
- // Vue: prefer SFCs; TypeScript: import the app main TS module and let performResetRoot handle it once.
167
- const placeholderActive = isPlaceholderActive();
168
- if (!placeholderActive)
169
- return;
170
- if (VERBOSE)
171
- console.log('[hmr][init] placeholder persists after delay; evaluating rescue policy');
172
- // Flavor-specific rescue handling
173
- if (__NS_TARGET_FLAVOR__ === 'typescript') {
174
- // For TS apps, perform a one-time resetRootView to the conventional
175
- // app root module. This mimics what Application.run would do and
176
- // replaces the placeholder with the real UI without trying to
177
- // treat app.ts as a component.
178
- try {
179
- const App = getCore('Application') || g.Application;
180
- if (App && typeof App.resetRootView === 'function') {
181
- if (VERBOSE)
182
- console.log('[hmr][init] TS flavor: performing rescue resetRootView to moduleName=app-root');
183
- initialMounting = true;
184
- try {
185
- g.__NS_HMR_INITIAL_MOUNT_IN_PROGRESS__ = true;
186
- }
187
- catch { }
188
- App.resetRootView({ moduleName: 'app-root' });
189
- initialMounted = true;
190
- try {
191
- g.__NS_HMR_BOOT_COMPLETE__ = true;
192
- }
193
- catch { }
194
- if (VERBOSE)
195
- console.log('[hmr][init] TS rescue resetRootView complete');
196
- }
197
- else if (VERBOSE) {
198
- console.warn('[hmr][init] TS flavor: Application.resetRootView unavailable; cannot perform rescue');
199
- }
200
- }
201
- catch (e) {
202
- console.warn('[hmr][init] TS rescue resetRootView failed', e);
203
- }
204
- finally {
205
- initialMounting = false;
206
- try {
207
- g.__NS_HMR_INITIAL_MOUNT_IN_PROGRESS__ = false;
208
- }
209
- catch { }
210
- }
211
- return;
212
- }
213
- let candidate = null;
214
- switch (__NS_TARGET_FLAVOR__) {
215
- case 'vue': {
216
- const appEntry = graph.get(APP_MAIN_ENTRY_SPEC);
217
- if (appEntry && Array.isArray(appEntry.deps)) {
218
- const vueDep = appEntry.deps.find((d) => typeof d === 'string' && /\.vue$/i.test(d));
219
- if (vueDep)
220
- candidate = vueDep;
221
- }
222
- if (!candidate) {
223
- for (const id of graph.keys()) {
224
- if (/\.vue$/i.test(id)) {
225
- candidate = id;
226
- break;
227
- }
228
- }
229
- }
230
- break;
231
- }
232
- }
233
- if (!candidate)
234
- return;
235
- initialMounting = true;
236
- try {
237
- g.__NS_HMR_INITIAL_MOUNT_IN_PROGRESS__ = true;
238
- }
239
- catch { }
240
- (async () => {
241
- try {
242
- let comp = null;
243
- switch (__NS_TARGET_FLAVOR__) {
244
- case 'vue':
245
- comp = await loadSfcComponent(candidate, 'initial_mount_rescue');
246
- break;
247
- }
248
- if (!comp)
249
- return;
250
- const ok = await performResetRoot(comp);
251
- if (ok) {
252
- initialMounted = true;
253
- try {
254
- g.__NS_HMR_BOOT_COMPLETE__ = true;
255
- }
256
- catch { }
257
- if (VERBOSE)
258
- console.log('[hmr][init] initial mount (rescue) complete');
259
- }
260
- }
261
- catch (e) {
262
- console.warn('[hmr][init] initial mount (rescue) error', e);
263
- }
264
- finally {
265
- initialMounting = false;
266
- try {
267
- g.__NS_HMR_INITIAL_MOUNT_IN_PROGRESS__ = false;
268
- }
269
- catch { }
270
- }
271
- })();
272
- }
273
- catch { }
274
- }, 450);
275
- }
276
- }
277
- catch { }
278
- // On first full graph, if we have not mounted yet, attempt an initial mount
279
- // by choosing a likely root component for the active flavor and performing a resetRootView with it.
28
+ // Late-registration bridge for one-shot iOS launch notifications
29
+ // (see shared/runtime/launch-bridge.ts).
30
+ //
31
+ // Under a webpack (or non-HMR vite) build the app bundle evaluates BEFORE
32
+ // `UIApplicationMain` finishes launching, so
33
+ // `Application.ios.addNotificationObserver(UIApplicationDidFinishLaunchingNotification, cb)`
34
+ // registers in time. Under the HTTP dev session UIKit is fully launched long
35
+ // before the app graph evaluates — those observers register AFTER the
36
+ // notification fired and are never called, so apps that gate SDK init (auth,
37
+ // Firebase, Sentry) behind didFinishLaunching silently never initialize. The
38
+ // bridge wraps `addNotificationObserver` so a post-launch registration for
39
+ // Did/WillFinishLaunching still registers normally AND has its callback
40
+ // invoked on the next macrotask with a synthesized NSNotification.
41
+ //
42
+ // The DETERMINISTIC install happens in the /__ns_dev__/client bootstrap
43
+ // wrapper, which runs before the app entry. This module-eval attempt and the
44
+ // global hook are belt-and-braces for exotic boot paths — this client
45
+ // evaluates async and can lose the race against the entry graph, so it must
46
+ // never be the only wrap.
47
+ function tryInstallLaunchNotificationBridge(attempts, explicitApplication) {
48
+ let wrappedAny = false;
280
49
  try {
281
- // Short-circuit if boot is complete or an initial mount is already underway (across realms/evals)
282
- const bootDone = !!globalThis.__NS_HMR_BOOT_COMPLETE__;
283
- const bootInProgress = !!globalThis.__NS_HMR_INITIAL_MOUNT_IN_PROGRESS__ || initialMounting;
284
- // Only allow initial mount when explicitly enabled. Rely on the app's own main entry start() for the first mount
285
- // to avoid double-mount races that can cause duplicate navigation logs.
286
- if (ALLOW_INITIAL_MOUNT && !initialMounted && !bootDone && !bootInProgress && !getCurrentApp() && !getRootFrame()) {
287
- let candidate = null;
288
- switch (__NS_TARGET_FLAVOR__) {
289
- case 'vue': {
290
- const appEntry = graph.get(APP_MAIN_ENTRY_SPEC);
291
- if (appEntry && Array.isArray(appEntry.deps)) {
292
- const vueDep = appEntry.deps.find((d) => typeof d === 'string' && /\.vue$/i.test(d));
293
- if (vueDep)
294
- candidate = vueDep;
295
- }
296
- if (!candidate) {
297
- for (const id of graph.keys()) {
298
- if (/\.vue$/i.test(id)) {
299
- candidate = id;
300
- break;
301
- }
302
- }
303
- }
304
- break;
305
- }
306
- case 'typescript': {
307
- // For TS flavor, do not perform client-driven initial mount; rely on Application.run.
308
- return;
309
- }
310
- }
311
- if (candidate) {
312
- // Mark initial-mount in progress (both module-local and global) BEFORE scheduling async work
313
- initialMounting = true;
314
- try {
315
- globalThis.__NS_HMR_INITIAL_MOUNT_IN_PROGRESS__ = true;
316
- }
317
- catch { }
318
- (async () => {
319
- try {
320
- if (VERBOSE)
321
- console.log('[hmr][init] mounting initial root from', candidate, 'flavor=', __NS_TARGET_FLAVOR__);
322
- // Android-only: avoid racing entry-runtime reset and Activity bring-up
323
- try {
324
- const g = globalThis;
325
- const App = getCore('Application') || g.Application;
326
- const isAndroid = !!(App && App.android !== undefined);
327
- if (isAndroid) {
328
- const ready = async (ms = 8000, step = 60) => {
329
- const start = Date.now();
330
- const ok = () => {
331
- try {
332
- const a = App.android;
333
- const act = a && (a.foregroundActivity || a.startActivity);
334
- const inProg = !!g.__NS_DEV_RESET_IN_PROGRESS__;
335
- return !!act && !inProg;
336
- }
337
- catch {
338
- return false;
339
- }
340
- };
341
- while (Date.now() - start < ms) {
342
- if (ok())
343
- return true;
344
- await new Promise((r) => setTimeout(r, step));
345
- }
346
- return ok();
347
- };
348
- const ok = await ready(8000, 60);
349
- if (!ok && VERBOSE)
350
- console.warn('[hmr][init] proceeding without explicit boot-ready signal (timeout)');
351
- }
352
- }
353
- catch { }
354
- let comp = null;
355
- switch (__NS_TARGET_FLAVOR__) {
356
- case 'vue':
357
- comp = await loadSfcComponent(candidate, 'initial_mount');
358
- break;
359
- case 'typescript':
360
- try {
361
- const url = await requestModuleFromServer(candidate);
362
- const mod = await import(/* @vite-ignore */ url);
363
- comp = mod && (mod.default || mod);
364
- }
365
- catch (e) {
366
- if (VERBOSE)
367
- console.warn('[hmr][init] TS initial mount failed to import', candidate, e);
368
- }
369
- break;
370
- }
371
- if (comp) {
372
- const ok = await performResetRoot(comp);
373
- if (ok) {
374
- initialMounted = true;
375
- try {
376
- globalThis.__NS_HMR_BOOT_COMPLETE__ = true;
377
- }
378
- catch { }
379
- if (VERBOSE)
380
- console.log('[hmr][init] initial mount complete');
381
- }
382
- else if (VERBOSE) {
383
- console.warn('[hmr][init] initial mount did not verify; will rely on subsequent retries');
384
- }
385
- }
386
- else if (VERBOSE) {
387
- console.warn('[hmr][init] failed to load initial component from', candidate);
388
- }
389
- }
390
- catch (e) {
391
- console.warn('[hmr][init] initial mount error', e);
392
- }
393
- finally {
394
- // Clear in-progress flag regardless of outcome to allow future retries if needed
395
- initialMounting = false;
396
- try {
397
- globalThis.__NS_HMR_INITIAL_MOUNT_IN_PROGRESS__ = false;
398
- }
399
- catch { }
400
- }
401
- })();
402
- }
403
- else if (VERBOSE) {
404
- console.warn('[hmr][init] no component found in graph to mount initially for flavor', __NS_TARGET_FLAVOR__);
405
- }
406
- }
50
+ wrappedAny = installLaunchNotificationBridge(explicitApplication, [getCore('Application')]);
407
51
  }
408
52
  catch { }
409
- }
410
- function applyDelta(payload) {
411
- // If versions are out of sync, request a full graph resync, but still
412
- // opportunistically queue the changed ids so the client can react once
413
- // the resync arrives. This is especially important for simple TS flavors
414
- // where we only need a signal that "something changed" to trigger a
415
- // resetRootView-driven hot update.
416
- const currentVersion = getGraphVersion();
417
- const versionMatches = payload.baseVersion === currentVersion;
418
- if (!versionMatches) {
419
- if (VERBOSE)
420
- console.warn('[hmr][graph] version mismatch requesting resync', payload.baseVersion, currentVersion);
421
- try {
422
- hmrSocket?.send(JSON.stringify({ type: 'ns:hmr-resync-request' }));
423
- }
424
- catch { }
425
- }
426
- if (versionMatches) {
427
- setGraphVersion(payload.newVersion);
428
- }
429
- const changed = payload.changed || [];
430
- switch (__NS_TARGET_FLAVOR__) {
431
- case 'vue':
432
- recordVuePayloadChanges(changed, getGraphVersion());
433
- break;
434
- }
435
- (payload.changed || []).forEach((m) => {
436
- if (!m || !m.id)
437
- return;
438
- // Always update the local graph view with the announced module metadata
439
- graph.set(m.id, { id: m.id, deps: m.deps || [], hash: m.hash || '' });
440
- });
441
- (payload.removed || []).forEach((r) => {
442
- graph.delete(r);
443
- });
444
- if (VERBOSE)
445
- console.log('[hmr][graph] delta applied newVersion', getGraphVersion(), 'changed=', (payload.changed || []).length, 'removed=', (payload.removed || []).length, 'baseVersion=', payload.baseVersion);
446
- // Queue evaluation of changed modules (placeholder pipeline)
447
- if (payload.changed?.length) {
448
- // HARD SUPPRESS: the very first delta (baseVersion 0) commonly includes the app main entry which is already evaluated during bootstrap.
449
- // Importing it again with a cache-bust often produces a spurious module-not-found (timestamp param treated as distinct file).
450
- const isInitial = payload.baseVersion === 0;
451
- // Filter out virtual helper ids (e.g. '\0plugin-vue:export-helper') which we do not evaluate directly
452
- const realIds = payload.changed.map((c) => c.id).filter((id) => !/^\0|^\/\0|plugin-vue:export-helper/.test(id));
453
- // Proactively prefetch core/src deps for any changed .vue SFCs (before registry update triggers reset)
454
- try {
455
- for (const entry of payload.changed || []) {
456
- if (!entry || !/\.vue$/i.test(entry.id))
457
- continue;
458
- const deps = Array.isArray(entry.deps) ? entry.deps : [];
459
- const prefetchTargets = deps.filter((d) => /^\//.test(d) && !/node_modules/.test(d) && !/\.vue$/i.test(d));
460
- if (prefetchTargets.length && VERBOSE)
461
- console.log('[hmr][prefetch] SFC deps', entry.id, '->', prefetchTargets);
462
- for (const dep of prefetchTargets) {
463
- const norm = normalizeSpec(dep);
464
- // Skip if we already wrote it (basic heuristic: moduleFetchCache has it or path exists in Documents/_ns_hmr)
465
- if (moduleFetchCache.has(norm))
466
- continue;
467
- // Fire and forget; ensure rejection does not break HMR pipeline
468
- requestModuleFromServer(norm).catch(() => { });
469
- }
470
- }
471
- }
472
- catch (e) {
473
- if (VERBOSE)
474
- console.warn('[hmr][prefetch] failed', e);
475
- }
476
- const isAppMainEntryId = (value) => value.endsWith(APP_MAIN_ENTRY_SPEC);
477
- for (const id of realIds) {
478
- // We now rely on SFC registry update events to trigger root resets for .vue files directly
479
- if (/\.vue$/i.test(id)) {
480
- if (VERBOSE)
481
- console.log('[hmr][delta] skipping queue for .vue id; will handle on registry update', id);
482
- continue;
483
- }
484
- if (isInitial && isAppMainEntryId(id)) {
485
- if (VERBOSE)
486
- console.log(`[hmr][delta] suppressing initial ${APP_MAIN_ENTRY_SPEC} evaluation`);
487
- continue;
488
- }
489
- if (isAppMainEntryId(id)) {
490
- try {
491
- const exists = globalThis.require?.(id) || globalThis.__nsGetModuleExports?.(id);
492
- if (!exists && VERBOSE)
493
- console.log(`[hmr][delta] skipping unresolved ${APP_MAIN_ENTRY_SPEC} change`);
494
- if (!exists)
495
- continue;
496
- }
497
- catch {
498
- /* ignore */
499
- }
500
- }
501
- changedQueue.push(id);
502
- }
503
- if (changedQueue.length)
504
- processQueue();
53
+ if (!wrappedAny && attempts > 0) {
54
+ setTimeout(() => tryInstallLaunchNotificationBridge(attempts - 1, explicitApplication), 100);
505
55
  }
506
56
  }
507
- // Deterministic navigation using the current Vue app instance rather than vendor-held rootApp
508
- function __nsNavigateUsingApp(comp, opts = {}) {
509
- const g = globalThis;
510
- switch (__NS_TARGET_FLAVOR__) {
511
- case 'vue':
512
- ensureVueGlobals();
513
- break;
514
- }
515
- const AppFactory = g.createApp;
516
- const RootCtor = g.NSVRoot;
517
- if (typeof AppFactory !== 'function' || typeof RootCtor !== 'function') {
518
- throw new Error('Vue runtime not initialized');
519
- }
520
- try {
521
- const top = (g.Frame && g.Frame.topmost && g.Frame.topmost()) || null;
522
- const ctor = top && top.constructor && top.constructor.name;
523
- if (VERBOSE)
524
- console.log('[app-nav] begin', {
525
- hmrRealm: g.__NS_HMR_REALM__ || 'unknown',
526
- rtRealm: g.__NS_RT_REALM__ || 'unknown',
527
- topCtor: ctor,
528
- hasTop: !!top,
529
- });
530
- }
531
- catch { }
532
- // Build a fresh Page each time the factory is invoked to avoid reusing a Page instance
533
- // across fragment recreations (Android) or multiple frame attachments.
534
- const buildTarget = () => {
535
- const existingApp = getCurrentApp();
536
- const baseProvides = (existingApp && existingApp._context && existingApp._context.provides) || {};
537
- const app = AppFactory(normalizeComponent(comp, comp && (comp.__name || comp.name)));
538
- switch (__NS_TARGET_FLAVOR__) {
539
- case 'vue':
540
- ensurePiniaOnApp(app);
541
- break;
542
- }
543
- try {
544
- const registry = g.__nsVendorRegistry;
545
- const req = registry?.get ? g.__nsVendorRequire || g.__nsRequire || g.require : g.__nsRequire || g.require;
546
- let rh = null;
547
- if (registry && registry.has('nativescript-vue/dist/runtimeHelpers'))
548
- rh = registry.get('nativescript-vue/dist/runtimeHelpers');
549
- if (!rh && typeof req === 'function') {
550
- try {
551
- rh = req('nativescript-vue/dist/runtimeHelpers');
552
- }
553
- catch { }
554
- }
555
- const setRootApp = rh && (rh.setRootApp || rh.default?.setRootApp);
556
- if (typeof setRootApp === 'function')
557
- setRootApp(app);
558
- }
559
- catch { }
560
- try {
561
- const ctx = app?._context;
562
- if (ctx) {
563
- const prov = (ctx.provides || (ctx.provides = {}));
564
- Object.getOwnPropertyNames(baseProvides).forEach((k) => {
565
- if (!Object.prototype.hasOwnProperty.call(prov, k))
566
- prov[k] = baseProvides[k];
567
- });
568
- Object.getOwnPropertySymbols(baseProvides).forEach((s) => {
569
- if (!Object.prototype.hasOwnProperty.call(prov, s))
570
- prov[s] = baseProvides[s];
571
- });
572
- }
573
- }
574
- catch { }
575
- const root = new RootCtor();
576
- const vm = typeof app.runWithContext === 'function' ? app.runWithContext(() => app.mount(root)) : app.mount(root);
577
- setCurrentApp(app);
578
- const el = vm?.$el;
579
- const nativeView = el?.nativeView;
580
- if (!nativeView)
581
- throw new Error('navigation mount did not yield a nativeView');
582
- const P = getCore('Page');
583
- const ctorName = String(nativeView?.constructor?.name || '').replace(/^_+/, '');
584
- if (ctorName === 'Page' || /^Page(\$\d+)?$/.test(ctorName)) {
585
- return nativeView;
586
- }
587
- if (typeof P === 'function') {
588
- const pg = new P();
589
- pg.content = nativeView;
590
- // Hide default ActionBar for wrapped views to avoid double bars
591
- try {
592
- pg.actionBarHidden = true;
593
- }
594
- catch { }
595
- return pg;
596
- }
597
- return nativeView; // fallback
598
- };
599
- let frame = opts && opts.frame ? opts.frame : getRootFrame();
600
- if (!frame) {
601
- const F = getCore('Frame');
602
- frame = F && typeof F.topmost === 'function' ? F.topmost() : null;
603
- }
604
- if (!frame) {
605
- const GApp = getCore('Application') || g.Application;
606
- const F = getCore('Frame');
607
- if (typeof GApp?.resetRootView === 'function' && typeof F === 'function') {
608
- GApp.resetRootView({
609
- create: () => {
610
- const fr = new F();
611
- const navEntry = {
612
- create: () => buildTarget(),
613
- clearHistory: true,
614
- animated: false,
615
- };
616
- try {
617
- fr.navigate(navEntry);
618
- }
619
- catch { }
620
- setRootFrame(fr);
621
- return fr;
622
- },
623
- });
624
- return undefined;
625
- }
626
- throw new Error('Application.resetRootView unavailable');
627
- }
628
- const navEntry = { create: () => buildTarget(), ...(opts || {}) };
629
- frame.navigate(navEntry);
630
- return undefined;
631
- }
632
- // Expose deterministic app navigation globally so /ns/rt can guarantee single-path navigation
57
+ tryInstallLaunchNotificationBridge(100);
633
58
  try {
634
- globalThis.__nsNavigateUsingApp = __nsNavigateUsingApp;
59
+ globalThis.__NS_DEV_INSTALL_LAUNCH_BRIDGE__ = (explicitApplication) => tryInstallLaunchNotificationBridge(100, explicitApplication);
635
60
  }
636
61
  catch { }
637
- async function processQueue() {
638
- if (!globalThis.__NS_HMR_BOOT_COMPLETE__) {
639
- if (VERBOSE)
640
- console.log('[hmr][gate] deferring HMR eval until boot complete');
641
- setTimeout(() => {
642
- try {
643
- processQueue();
644
- }
645
- catch { }
646
- }, 150);
647
- return Promise.resolve();
648
- }
649
- if (processingQueue)
650
- return processingPromise || Promise.resolve();
651
- processingQueue = true;
652
- processingPromise = (async () => {
653
- try {
654
- // Simple deterministic drain of the queue. We currently focus on TS flavor
655
- // by re-importing changed modules (to refresh their HTTP ESM copies) and
656
- // then performing a root reset so the UI reflects the new code.
657
- const seen = new Set();
658
- const drained = [];
659
- while (changedQueue.length) {
660
- const id = changedQueue.shift();
661
- if (!id || typeof id !== 'string')
662
- continue;
663
- if (seen.has(id))
664
- continue;
665
- seen.add(id);
666
- drained.push(id);
667
- }
668
- if (!drained.length)
669
- return;
670
- if (VERBOSE)
671
- console.log('[hmr][queue] processing changed ids', drained);
672
- // Evaluate changed modules best-effort; failures shouldn't completely break HMR.
673
- for (const id of drained) {
674
- try {
675
- const spec = normalizeSpec(id);
676
- const url = await requestModuleFromServer(spec);
677
- if (!url)
678
- continue;
679
- if (VERBOSE)
680
- console.log('[hmr][queue] re-import', { id, spec, url });
681
- const mod = await import(/* @vite-ignore */ url);
682
- }
683
- catch (e) {
684
- if (VERBOSE)
685
- console.warn('[hmr][queue] re-import failed for', id, e);
686
- }
687
- }
688
- // After evaluating the batch, perform flavor-specific UI refresh.
689
- switch (__NS_TARGET_FLAVOR__) {
690
- case 'vue':
691
- // Vue SFCs are handled via the registry update path; nothing to do here.
692
- break;
693
- case 'typescript': {
694
- // For TS apps, always reset back to the conventional app root.
695
- // This preserves the shell (Frame, ActionBar, etc.) that the app's
696
- // own bootstrapping wires up via `Application.run`.
697
- try {
698
- const g = globalThis;
699
- const App = getCore('Application') || g.Application;
700
- if (!App || typeof App.resetRootView !== 'function') {
701
- if (VERBOSE)
702
- console.warn('[hmr][queue] TS flavor: Application.resetRootView unavailable; skipping UI refresh');
703
- break;
704
- }
705
- if (VERBOSE)
706
- console.log('[hmr][queue] TS flavor: resetRootView(app-root) after changes');
707
- App.resetRootView({ moduleName: 'app-root' });
708
- }
709
- catch (e) {
710
- console.warn('[hmr][queue] TS flavor: resetRootView(app-root) failed', e);
711
- }
712
- break;
713
- }
714
- }
715
- }
716
- finally {
717
- processingQueue = false;
718
- processingPromise = null;
719
- }
720
- })();
721
- return processingPromise;
722
- }
723
- let hmrSocket = null;
724
- // Track server-announced batches for each version so we can import in-order client-side
725
- const txnClientBatches = new Map();
726
- // Public hook for NativeScript runtime to call from ImportModuleDynamicallyCallback later.
727
- globalThis.__nsHmrRequestModule = async function (spec) {
728
- let normalized = normalizeSpec(spec);
729
- // Remove extension for transform lookup variants (server will try .ts/.js/.mjs)
730
- normalized = normalized.replace(/\.(ts|js|tsx|jsx|mjs)$/i, '');
731
- if (!normalized.startsWith('/'))
732
- normalized = '/' + normalized;
733
- if (normalized === '@') {
734
- // Soft-handle instead of throwing to avoid breaking evaluation paths: return a safe empty module stub.
735
- try {
736
- const err = new Error('[hmr-fetch] anomalous @ spec');
737
- const stack = err.stack || '';
738
- hmrMetrics.invalidAtSpec = (hmrMetrics.invalidAtSpec || 0) + 1;
739
- console.warn('[hmr-fetch] refusing to fetch bare @ spec; returning stub; original=', spec, 'stack=\n' + stack);
740
- }
741
- catch { }
742
- return '/__invalid_at__.mjs';
743
- }
744
- const url = await requestModuleFromServer(normalized);
745
- return url;
746
- };
747
- function connectHmr() {
748
- if (hmrSocket?.readyState === WebSocket.OPEN)
749
- return;
750
- if (hmrSocket?.readyState === WebSocket.CONNECTING) {
751
- if (__NS_ENV_VERBOSE__)
752
- console.log('[hmr-client] Already connecting to HMR WebSocket, skipping');
62
+ // Install the device CSS applier. CSS-bearing modules (a Vue SFC `<style>` via
63
+ // `/ns/asm`, an imported `.css` via `/ns/m`) call `__NS_REGISTER_CSS__(tag, css)`,
64
+ // or queue in `__NS_PENDING_CSS__` if they ran first; the drain below covers that.
65
+ // Routes through the shared `applyCssText` (tagged remove+add + root restyle),
66
+ // the same path app.css and live `.css` edits use.
67
+ function installCssRegister() {
68
+ const g = getGlobalScope();
69
+ if (typeof g.__NS_REGISTER_CSS__ === 'function') {
753
70
  return;
754
71
  }
755
- const baseUrl = getHMRWsUrl() || 'ws://localhost:5173/ns-hmr';
756
- const buildCandidates = (url) => {
757
- let candidates = [];
758
- try {
759
- const u = new URL(url);
760
- const proto = u.protocol === 'wss:' ? ['wss'] : ['ws'];
761
- const defaultPort = u.port || '5173';
762
- // Build ordered host candidates with preference to the active HTTP origin
763
- const orderedHosts = [];
764
- try {
765
- const g = globalThis;
766
- const httpOrigin = g && typeof g.__NS_HTTP_ORIGIN__ === 'string' ? g.__NS_HTTP_ORIGIN__ : undefined;
767
- if (httpOrigin) {
768
- try {
769
- const ho = new URL(httpOrigin);
770
- orderedHosts.push({
771
- host: ho.hostname,
772
- port: ho.port || defaultPort,
773
- });
774
- }
775
- catch { }
776
- }
777
- }
778
- catch { }
779
- // From provided URL
780
- orderedHosts.push({ host: u.hostname, port: defaultPort });
781
- // Explicit override
782
- try {
783
- const h = globalThis.__NS_HMR_HOST;
784
- if (h)
785
- orderedHosts.push({ host: String(h), port: defaultPort });
786
- }
787
- catch { }
788
- // Common fallbacks
789
- orderedHosts.push({ host: '10.0.2.2', port: defaultPort });
790
- orderedHosts.push({ host: 'localhost', port: defaultPort });
791
- const seen = new Set();
792
- for (const p of proto) {
793
- for (const { host, port } of orderedHosts) {
794
- const key = `${host}:${port}`;
795
- if (seen.has(key))
796
- continue;
797
- seen.add(key);
798
- const cand = `${p}://${host}:${port}${u.pathname || '/ns-hmr'}`;
799
- candidates.push(cand);
800
- }
801
- }
802
- }
803
- catch {
804
- candidates.push(url);
805
- }
806
- // Deduplicate while preserving order
807
- const seen = new Set();
808
- return candidates.filter((c) => (seen.has(c) ? false : (seen.add(c), true)));
809
- };
810
- const candidates = buildCandidates(baseUrl);
811
- let idx = 0;
812
- const tryNext = () => {
813
- if (idx >= candidates.length) {
814
- console.warn('[hmr-client] All WS candidates failed:', candidates.join(', '));
72
+ const apply = (tag, cssText) => {
73
+ if (typeof cssText !== 'string' || !cssText.length) {
815
74
  return;
816
75
  }
817
- const url = candidates[idx++];
818
76
  try {
819
- if (__NS_ENV_VERBOSE__)
820
- console.log('[hmr-client] Connecting to HMR WebSocket:', url);
821
- const sock = new WebSocket(url);
822
- hmrSocket = sock;
823
- setHttpOriginForVite(deriveHttpOrigin(url));
824
- let opened = false;
825
- const timeout = setTimeout(() => {
826
- if (!opened && sock.readyState !== WebSocket.OPEN) {
827
- try {
828
- sock.close();
829
- }
830
- catch { }
831
- if (VERBOSE)
832
- console.warn('[hmr-client] WS connect timeout, trying next…');
833
- tryNext();
834
- }
835
- }, 3500);
836
- sock.onopen = () => {
837
- opened = true;
838
- clearTimeout(timeout);
839
- VERBOSE && console.log('[hmr-client] Connected to HMR WebSocket');
840
- };
841
- sock.onmessage = handleHmrMessage;
842
- sock.onerror = (error) => {
843
- clearTimeout(timeout);
844
- console.warn('[hmr-client] WebSocket error:', (error && (error.message || error)) || error);
845
- };
846
- sock.onclose = (ev) => {
847
- clearTimeout(timeout);
848
- if (!opened) {
849
- // immediate failure during connect → try another candidate
850
- if (VERBOSE)
851
- console.warn('[hmr-client] WS close before open (code', ev?.code, '), trying next…');
852
- tryNext();
853
- }
854
- else {
855
- if (VERBOSE)
856
- console.log('[hmr-client] WebSocket closed (code', ev?.code, '), will reconnect…');
857
- // try to reconnect with full candidate list again
858
- setTimeout(connectHmr, 1000);
859
- }
860
- };
77
+ applyCssText(cssText, tag);
861
78
  }
862
- catch (e) {
863
- console.warn('[hmr-client] Failed to connect WebSocket', e);
864
- tryNext();
79
+ catch (cssErr) {
80
+ if (VERBOSE)
81
+ console.warn('[ns-hmr] CSS register/apply failed for', tag, cssErr?.message || cssErr);
865
82
  }
866
83
  };
867
- tryNext();
868
- }
869
- async function handleHmrMessage(ev) {
870
- let msg;
84
+ g.__NS_REGISTER_CSS__ = apply;
871
85
  try {
872
- msg = JSON.parse(ev.data);
873
- }
874
- catch {
875
- return;
876
- }
877
- // Notify optional app-level hook after an HMR batch is applied.
878
- function notifyAppHmrUpdate(kind, changedIds) {
879
- try {
880
- const hook = globalThis.__NS_HMR_ON_UPDATE__;
881
- if (typeof hook === 'function') {
882
- hook({ type: kind, version: getGraphVersion(), changedIds: changedIds || [], raw: msg });
86
+ const pending = g.__NS_PENDING_CSS__;
87
+ if (pending && typeof pending === 'object') {
88
+ for (const tag of Object.keys(pending)) {
89
+ apply(tag, pending[tag]);
883
90
  }
91
+ g.__NS_PENDING_CSS__ = null;
884
92
  }
885
- catch { }
886
- }
887
- if (msg) {
888
- if (msg.type === 'ns:hmr-full-graph') {
889
- // Bump a monotonic nonce so HTTP ESM imports can always be cache-busted per update.
890
- try {
891
- const g = globalThis;
892
- g.__NS_HMR_IMPORT_NONCE__ = (typeof g.__NS_HMR_IMPORT_NONCE__ === 'number' ? g.__NS_HMR_IMPORT_NONCE__ : 0) + 1;
893
- }
894
- catch { }
895
- // Capture previous graph snapshot so we can infer which modules changed.
896
- const prevGraph = new Map(graph);
897
- setGraphVersion(Number(msg.version || getGraphVersion() || 0));
898
- applyFullGraph(msg);
899
- // In some cases (e.g. server chooses full-graph resync / page reload), we won't
900
- // receive a delta queue to re-import changed TS modules. Without re-import,
901
- // HTTP ESM caching means module bodies (and side effects) won't re-run.
902
- try {
903
- const inferredChanged = [];
904
- try {
905
- for (const [id, next] of graph.entries()) {
906
- const prev = prevGraph.get(id);
907
- if (!prev || prev.hash !== next.hash)
908
- inferredChanged.push(id);
909
- }
910
- // Removed modules are also "changed" but we don't import them.
911
- }
912
- catch { }
913
- // Best-effort: only re-import real source modules (avoid .vue registry pipeline and virtual ids)
914
- const toReimport = inferredChanged.filter((id) => {
915
- if (!id || typeof id !== 'string')
916
- return false;
917
- if (/^\0|^\/\0/.test(id))
918
- return false;
919
- if (/plugin-vue:export-helper/.test(id))
920
- return false;
921
- if (/\.vue$/i.test(id))
922
- return false;
923
- if (id.endsWith(APP_MAIN_ENTRY_SPEC))
924
- return false;
925
- return true;
926
- });
927
- if (toReimport.length && VERBOSE)
928
- console.log('[hmr][full-graph] inferred changed modules; re-importing', toReimport);
929
- for (const id of toReimport) {
930
- try {
931
- const spec = normalizeSpec(id);
932
- const url = await requestModuleFromServer(spec);
933
- if (!url)
934
- continue;
935
- if (VERBOSE)
936
- console.log('[hmr][full-graph] re-import', { id, spec, url });
937
- await import(/* @vite-ignore */ url);
938
- }
939
- catch (e) {
940
- if (VERBOSE)
941
- console.warn('[hmr][full-graph] re-import failed for', id, e);
942
- }
943
- }
944
- }
945
- catch { }
946
- const fullIds = Array.isArray(msg.modules) ? msg.modules.map((m) => m?.id).filter(Boolean) : [];
947
- notifyAppHmrUpdate('full-graph', fullIds);
948
- return;
949
- }
950
- if (msg.type === 'ns:ts-module-registry') {
951
- try {
952
- const mods = Array.isArray(msg.modules) ? msg.modules.filter((m) => typeof m === 'string') : [];
953
- if (mods.length) {
954
- if (!tsModuleSet)
955
- tsModuleSet = new Set();
956
- mods.forEach((m) => tsModuleSet.add(m));
957
- // Prefer explicit app main entry if present, else first module
958
- if (mods.includes(APP_MAIN_ENTRY_SPEC)) {
959
- tsMainId = APP_MAIN_ENTRY_SPEC;
960
- }
961
- else if (!tsMainId) {
962
- tsMainId = mods[0];
963
- }
964
- if (VERBOSE)
965
- console.log('[hmr-client][ts-registry] registered TS modules', {
966
- count: tsModuleSet.size,
967
- mainId: tsMainId,
968
- });
969
- }
970
- }
971
- catch (e) {
972
- if (VERBOSE)
973
- console.warn('[hmr-client][ts-registry] failed to record', e);
974
- }
975
- return;
976
- }
977
- if (msg.type === 'ns:hmr-delta') {
978
- // Bump a monotonic nonce so HTTP ESM imports can always be cache-busted per update.
979
- try {
980
- const g = globalThis;
981
- g.__NS_HMR_IMPORT_NONCE__ = (typeof g.__NS_HMR_IMPORT_NONCE__ === 'number' ? g.__NS_HMR_IMPORT_NONCE__ : 0) + 1;
982
- }
983
- catch { }
984
- try {
985
- const ids = Array.isArray(msg.changed) ? msg.changed.map((c) => c?.id).filter(Boolean) : [];
986
- if (ids.length)
987
- txnClientBatches.set(getGraphVersion(), ids);
988
- }
989
- catch { }
990
- applyDelta(msg);
991
- // Ensure queued module re-imports complete before notifying app hooks.
992
- // Otherwise app-level handlers can run against stale module bodies due to HTTP ESM caching.
993
- try {
994
- await processQueue();
995
- }
996
- catch { }
997
- const deltaIds = Array.isArray(msg.changed) ? msg.changed.map((c) => c?.id).filter(Boolean) : [];
998
- notifyAppHmrUpdate('delta', deltaIds);
999
- return;
1000
- }
1001
- else if (handleAngularHotUpdateMessage(msg, { getCore, verbose: VERBOSE })) {
1002
- return;
1003
- }
1004
- }
1005
- // On-demand module fetch response (Option A)
1006
- if (msg.type === 'ns:module-response' && typeof msg.requestId === 'number') {
1007
- const pending = pendingModuleFetches.get(msg.requestId);
1008
- if (pending) {
1009
- pendingModuleFetches.delete(msg.requestId);
1010
- if (msg.error) {
1011
- if (VERBOSE)
1012
- console.warn('[hmr-fetch] error', msg.error, 'spec=', pending.spec, 'id=', msg.requestId);
1013
- pending.reject(new Error(`[hmr-fetch] ${msg.error} for ${pending.spec}`));
1014
- }
1015
- else {
1016
- try {
1017
- const origin = getHttpOriginForVite() || deriveHttpOrigin(getHMRWsUrl());
1018
- if (!origin)
1019
- throw new Error('no-http-origin');
1020
- const url = origin + '/ns/m' + (String(pending.spec).startsWith('/') ? pending.spec : '/' + pending.spec);
1021
- moduleFetchCache.set(pending.spec, url);
1022
- if (VERBOSE)
1023
- console.log('[hmr-fetch] resolved via URL', pending.spec, '->', url, 'id=', msg.requestId);
1024
- pending.resolve(url);
1025
- }
1026
- catch (e) {
1027
- pending.reject(e);
1028
- }
1029
- }
1030
- }
1031
- return;
1032
- }
1033
- if (msg.type === 'ns:css-updates' && Array.isArray(msg.updates)) {
1034
- try {
1035
- const origin = msg.origin || getHttpOriginForVite() || deriveHttpOrigin(getHMRWsUrl());
1036
- await handleCssUpdates(msg.updates, origin);
1037
- return;
1038
- }
1039
- catch (e) {
1040
- console.warn('[hmr-client] CSS updates handling failed:', e);
1041
- return;
1042
- }
1043
- }
1044
- if (msg.type === 'ns:vue-sfc-registry') {
1045
- handleVueSfcRegistry(msg);
1046
- return;
1047
- }
1048
- if (msg.type === 'ns:vue-sfc-registry-update') {
1049
- if (typeof msg.version === 'number')
1050
- setGraphVersion(msg.version);
1051
- const comp = await handleVueSfcRegistryUpdate(msg, getGraphVersion());
1052
- if (comp) {
1053
- await performResetRoot(comp);
1054
- }
1055
- return;
1056
- }
1057
- }
1058
- function normalizeComponent(input, nameHint) {
1059
- try {
1060
- if (!input)
1061
- return null;
1062
- // Unwrap module namespace with default
1063
- if (input && typeof input === 'object' && 'default' in input) {
1064
- const d = input.default;
1065
- if (d)
1066
- return normalizeComponent(d, nameHint);
1067
- }
1068
- // If already a component-like object with render/setup/template, return as-is
1069
- if (typeof input === 'object' && (input.render || input.setup || input.template || input.__isVue)) {
1070
- return input;
1071
- }
1072
- // If provided a render function, wrap with defineComponent
1073
- if (typeof input === 'function') {
1074
- ensureVueGlobals();
1075
- const comp = globalThis.defineComponent
1076
- ? globalThis.defineComponent({
1077
- name: nameHint || input.name || 'AnonymousSFC',
1078
- render: input,
1079
- })
1080
- : { name: nameHint || input.name || 'AnonymousSFC', render: input };
1081
- return comp;
1082
- }
1083
- // If object has a render function property
1084
- if (input?.render && typeof input.render === 'function') {
1085
- ensureVueGlobals();
1086
- const comp = globalThis.defineComponent
1087
- ? globalThis.defineComponent({
1088
- name: nameHint || input.name || 'AnonymousSFC',
1089
- render: input.render,
1090
- })
1091
- : {
1092
- name: nameHint || input.name || 'AnonymousSFC',
1093
- render: input.render,
1094
- };
1095
- return comp;
1096
- }
1097
- }
1098
- catch { }
1099
- return input;
1100
- }
1101
- async function performResetRoot(newComponent) {
1102
- const tStart = Date.now();
1103
- // Guard against re-entrant or rapid successive resets
1104
- try {
1105
- globalThis.__NS_DEV_RESET_IN_PROGRESS__ = true;
1106
- }
1107
- catch { }
1108
- try {
1109
- ensureCoreAliasesOnGlobalThis();
1110
- }
1111
- catch { }
1112
- if (VERBOSE) {
1113
- console.log('[hmr-client] Single-path: replace current root Page');
1114
- console.log('[hmr-client] Component details:', {
1115
- componentName: newComponent?.__name,
1116
- componentFile: newComponent?.__file,
1117
- hasRender: !!newComponent?.render,
1118
- hasSetup: !!newComponent?.setup,
1119
- componentKeys: Object.keys(newComponent || {}),
1120
- });
1121
- }
1122
- function createRootFactory() {
1123
- let rootKind = 'page';
1124
- let cachedRoot = undefined;
1125
- const state = {
1126
- getRootKind: () => rootKind,
1127
- setRootKind: (k) => {
1128
- rootKind = k;
1129
- },
1130
- getCachedRoot: () => cachedRoot,
1131
- setCachedRoot: (r) => {
1132
- cachedRoot = r;
1133
- },
1134
- };
1135
- const factory = {
1136
- get kind() {
1137
- return rootKind;
1138
- },
1139
- create: () => {
1140
- if (cachedRoot)
1141
- return cachedRoot;
1142
- try {
1143
- switch (__NS_TARGET_FLAVOR__) {
1144
- case 'vue':
1145
- cachedRoot = getRootForVue(newComponent, state);
1146
- break;
1147
- case 'typescript': {
1148
- // For TS flavor, treat the component as a factory or direct NS view.
1149
- let root = null;
1150
- try {
1151
- if (typeof newComponent === 'function') {
1152
- root = newComponent();
1153
- }
1154
- else {
1155
- root = newComponent;
1156
- }
1157
- }
1158
- catch (e) {
1159
- console.warn('[hmr-client][ts] root factory invocation failed', e);
1160
- }
1161
- cachedRoot = root || {};
1162
- // Heuristic: if the root "looks" like a Frame, prefer frame semantics
1163
- try {
1164
- const name = String(cachedRoot?.constructor?.name || '').replace(/^_+/, '');
1165
- if (/^Frame(\$\d+)?$/.test(name)) {
1166
- rootKind = 'frame';
1167
- }
1168
- }
1169
- catch { }
1170
- break;
1171
- }
1172
- }
1173
- return cachedRoot;
1174
- }
1175
- catch (e) {
1176
- console.warn('[hmr-client] createRootFactory failed', e);
1177
- if (VERBOSE)
1178
- console.warn('[hmr-client] [createRoot] stack', e?.stack);
1179
- const GPage = getCore('Page');
1180
- rootKind = 'page';
1181
- cachedRoot = GPage ? new GPage() : {};
1182
- return cachedRoot;
1183
- }
1184
- },
1185
- };
1186
- return factory;
1187
- }
1188
- // Android readiness before any root changes
1189
- const App = getCore('Application') || globalThis.Application;
1190
- const isAndroid = !!(App && App.android !== undefined);
1191
- if (isAndroid) {
1192
- const isReady = () => {
1193
- try {
1194
- const a = App.android;
1195
- const act = a && (a.foregroundActivity || a.startActivity);
1196
- return !!act;
1197
- }
1198
- catch {
1199
- return false;
1200
- }
1201
- };
1202
- const waitFor = async (pred, ms = 6000, step = 60) => {
1203
- const start = Date.now();
1204
- while (Date.now() - start < ms) {
1205
- if (pred())
1206
- return true;
1207
- await new Promise((r) => setTimeout(r, step));
1208
- }
1209
- return pred();
1210
- };
1211
- const withEvents = async (ms = 6000) => {
1212
- try {
1213
- const a = App.android;
1214
- if (!a || typeof a.on !== 'function' || typeof a.off !== 'function') {
1215
- if (VERBOSE)
1216
- console.log('[hmr-client] [android] events API not available; polling');
1217
- return await waitFor(isReady, ms, 60);
1218
- }
1219
- if (isReady()) {
1220
- if (VERBOSE)
1221
- console.log('[hmr-client] [android] activity already ready');
1222
- return true;
1223
- }
1224
- return await new Promise((resolve) => {
1225
- let done = false;
1226
- const tWait = Date.now();
1227
- const finish = (ok) => {
1228
- if (done)
1229
- return;
1230
- done = true;
1231
- try {
1232
- a.off(a.activityStartedEvent || 'activityStarted', onAny);
1233
- a.off(a.activityResumedEvent || 'activityResumed', onAny);
1234
- }
1235
- catch { }
1236
- if (VERBOSE)
1237
- console.log('[hmr-client] [android] readiness result', {
1238
- ok,
1239
- elapsedMs: Date.now() - tWait,
1240
- });
1241
- resolve(ok);
1242
- };
1243
- const onAny = (evt) => {
1244
- if (VERBOSE)
1245
- console.log('[hmr-client] [android] activity event', {
1246
- type: evt?.eventName || 'unknown',
1247
- });
1248
- if (isReady())
1249
- finish(true);
1250
- };
1251
- try {
1252
- a.on(a.activityStartedEvent || 'activityStarted', onAny);
1253
- a.on(a.activityResumedEvent || 'activityResumed', onAny);
1254
- if (VERBOSE)
1255
- console.log('[hmr-client] [android] waiting for activity events…');
1256
- }
1257
- catch {
1258
- return resolve(waitFor(isReady, ms, 60));
1259
- }
1260
- setTimeout(() => finish(isReady()), ms);
1261
- });
1262
- }
1263
- catch {
1264
- return await waitFor(isReady, ms, 60);
1265
- }
1266
- };
1267
- const ok = await withEvents(6000);
1268
- if (!ok && VERBOSE)
1269
- console.warn('[hmr-client] [android] activity not ready; proceeding with best-effort');
1270
- }
1271
- // Create the new root first to determine whether it is a Page or a Frame
1272
- const rootFactory = createRootFactory();
1273
- const preparedRoot = rootFactory.create();
1274
- const isFrameRoot = (() => {
1275
- try {
1276
- const name = String(preparedRoot?.constructor?.name || '').replace(/^_+/, '');
1277
- return /^Frame(\$\d+)?$/.test(name);
1278
- }
1279
- catch {
1280
- return false;
1281
- }
1282
- })();
1283
- // Prefer resetRootView on initial boot (placeholder present) or on iOS to avoid early createRootView races
1284
- let hadPlaceholder = false;
1285
- let isIOS = false;
1286
- try {
1287
- hadPlaceholder = !!globalThis.__NS_DEV_PLACEHOLDER_ROOT_EARLY__;
1288
- }
1289
- catch { }
1290
- try {
1291
- const AppAny = getCore('Application') || globalThis.Application;
1292
- isIOS = !!(AppAny && AppAny.ios !== undefined);
1293
93
  }
1294
94
  catch { }
1295
- // Preferred policy:
1296
- // - If this is the very first mount (placeholder present), or if the new root is a Frame,
1297
- // perform a full root replacement via resetRootView so we never couple with the placeholder.
1298
- // - Otherwise (subsequent HMR updates with an authoritative Frame already in place), re-use the
1299
- // current app Frame and navigate to the new Page. This avoids a brief flash that can occur
1300
- // when swapping the entire root view on Android. The placeholder is never involved here.
1301
- const gAnyForPolicy = globalThis;
1302
- const placeholderFrame = (() => {
1303
- try {
1304
- return gAnyForPolicy.__NS_DEV_PLACEHOLDER_ROOT_VIEW__ || null;
1305
- }
1306
- catch {
1307
- return null;
1308
- }
1309
- })();
1310
- let existingAppFrame = null;
1311
- try {
1312
- existingAppFrame = getRootFrame() || getCore('Frame')?.topmost?.() || null;
1313
- }
1314
- catch { }
1315
- const isAuthoritativeFrame = !!existingAppFrame && existingAppFrame !== placeholderFrame;
1316
- if (!hadPlaceholder && !isFrameRoot && isAuthoritativeFrame && typeof existingAppFrame.navigate === 'function') {
1317
- try {
1318
- const navEntry = {
1319
- create: () => preparedRoot,
1320
- clearHistory: true,
1321
- animated: false,
1322
- };
1323
- existingAppFrame.navigate(navEntry);
1324
- setRootFrame(existingAppFrame);
1325
- return true;
1326
- }
1327
- catch (e) {
1328
- console.warn('[hmr-client] authoritative navigate fallback to resetRootView due to error', e);
1329
- }
1330
- }
1331
- if (VERBOSE)
1332
- console.log('[hmr-client] full root replacement via resetRootView (placeholder will be discarded)', { isFrameRoot, isIOS, hadPlaceholder });
1333
- // Fallback or preferred path: resetRootView with a creator that builds a fresh Frame and navigates to the new Page
1334
- try {
1335
- const App2 = getCore('Application') || globalThis.Application;
1336
- if (!App2 || typeof App2.resetRootView !== 'function') {
1337
- console.warn('[hmr-client] Application.resetRootView unavailable');
1338
- return false;
1339
- }
1340
- // iOS-specific: if the cached window was left in an invalid state (boolean false), clear it so
1341
- // setWindowContent can recreate a proper UIWindow. This can occur in rare early-boot races.
1342
- try {
1343
- const isIos = !!(App2 && App2.ios !== undefined);
1344
- if (isIos) {
1345
- let win = undefined;
1346
- try {
1347
- win = App2.window;
1348
- }
1349
- catch { }
1350
- if (win === false) {
1351
- if (VERBOSE)
1352
- console.warn('[hmr-client] iOS Application.window is boolean false; attempting to clear cached window');
1353
- try {
1354
- const g = globalThis;
1355
- const reg = g.__nsVendorRegistry;
1356
- const req = reg?.get ? g.__nsVendorRequire || g.__nsRequire || g.require : g.__nsRequire || g.require;
1357
- let helpers = null;
1358
- // Try vendor registry first
1359
- if (reg && reg.has('@nativescript/core/application/helpers-common')) {
1360
- helpers = reg.get('@nativescript/core/application/helpers-common');
1361
- }
1362
- // Fallback to device require
1363
- if (!helpers && typeof req === 'function') {
1364
- try {
1365
- helpers = req('@nativescript/core/application/helpers-common');
1366
- }
1367
- catch { }
1368
- }
1369
- const setter = helpers && (helpers.setiOSWindow || helpers.default?.setiOSWindow);
1370
- if (typeof setter === 'function') {
1371
- try {
1372
- setter(undefined);
1373
- if (VERBOSE)
1374
- console.log('[hmr-client] cleared cached iOS window via helpers-common');
1375
- }
1376
- catch { }
1377
- }
1378
- }
1379
- catch { }
1380
- }
1381
- }
1382
- }
1383
- catch { }
1384
- // Use the previously created preparedRoot
1385
- const entry = {
1386
- create: () => {
1387
- if (!isFrameRoot) {
1388
- const F = getCore('Frame');
1389
- const fr = new F();
1390
- if (VERBOSE)
1391
- console.log('[hmr-client] resetRootView:create new Frame', {
1392
- type: fr?.constructor?.name,
1393
- });
1394
- const navEntry = {
1395
- create: () => preparedRoot,
1396
- clearHistory: true,
1397
- animated: false,
1398
- };
1399
- try {
1400
- fr.navigate(navEntry);
1401
- }
1402
- catch (e) {
1403
- console.warn('[hmr-client] resetRootView:create navigate failed', e);
1404
- }
1405
- setRootFrame(fr);
1406
- return fr;
1407
- }
1408
- else {
1409
- const fr = preparedRoot;
1410
- setRootFrame(fr);
1411
- return fr;
1412
- }
1413
- },
1414
- };
1415
- // Always use an entry with a create() function to avoid cross‑realm instanceof checks on Android.
1416
- App2.resetRootView(entry);
1417
- // After authoritative reset, it's safe to detach the early placeholder launch handler
1418
- try {
1419
- const restore = globalThis.__NS_DEV_RESTORE_PLACEHOLDER__;
1420
- if (typeof restore === 'function') {
1421
- restore();
1422
- }
1423
- }
1424
- catch { }
1425
- return true;
1426
- }
1427
- catch (e) {
1428
- console.warn('[hmr-client] resetRootView failed', e);
1429
- try {
1430
- if (VERBOSE)
1431
- console.warn('[hmr-client] resetRootView stack', e?.stack);
1432
- }
1433
- catch { }
1434
- return false;
1435
- }
1436
- finally {
1437
- try {
1438
- globalThis.__NS_DEV_RESET_IN_PROGRESS__ = false;
1439
- }
1440
- catch { }
1441
- }
1442
95
  }
96
+ installCssRegister();
97
+ // Route incoming socket messages through the protocol dispatcher.
98
+ setHmrMessageHandler(handleHmrMessage);
1443
99
  export function initHmrClient(opts) {
1444
100
  if (opts?.wsUrl) {
1445
101
  setHMRWsUrl(opts.wsUrl);
@@ -1455,13 +111,30 @@ export function initHmrClient(opts) {
1455
111
  }
1456
112
  g.__NS_HMR_CLIENT_ACTIVE__ = true;
1457
113
  ensureCoreAliasesOnGlobalThis();
1458
- connectHmr();
1459
- // Best-effort: install back wrapper even before first remount; original root may be captured later
1460
- switch (__NS_TARGET_FLAVOR__) {
1461
- case 'vue':
1462
- ensureBackWrapperInstalled(performResetRoot, getCore);
1463
- break;
114
+ // Defer WebSocket connection until boot completes to avoid native V8 crashes
115
+ // caused by concurrent WebSocket message handling + HTTP fetch during early startup.
116
+ // The WebSocket is only needed for HMR updates, not the initial boot sequence.
117
+ if (g.__NS_HMR_BOOT_COMPLETE__) {
118
+ connectHmr();
119
+ }
120
+ else {
121
+ const waitForBoot = () => {
122
+ if (globalThis.__NS_HMR_BOOT_COMPLETE__) {
123
+ if (VERBOSE)
124
+ console.log('[hmr-client] boot complete, connecting HMR WebSocket');
125
+ connectHmr();
126
+ }
127
+ else {
128
+ setTimeout(waitForBoot, 100);
129
+ }
130
+ };
131
+ if (VERBOSE)
132
+ console.log('[hmr-client] deferring WebSocket connection until boot completes');
133
+ setTimeout(waitForBoot, 100);
1464
134
  }
135
+ // Best-effort: install back wrapper even before first remount; original root may be captured later.
136
+ // Deferred until the dynamically-imported strategy resolves.
137
+ void CLIENT_STRATEGY_READY.then(() => getClientStrategy()?.installBackWrapper?.(performResetRoot, getCore));
1465
138
  }
1466
139
  export default function startViteHMR(opts) {
1467
140
  if (VERBOSE)