Skip to content

Commit 6628560

Browse files
committed
feat: ensure css applied on hmr http booted realm
1 parent c98184e commit 6628560

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

packages/angular/src/lib/application.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,18 @@ export function runNativeScriptAngularApp<T, K>(options: AppRunOptions<T, K>) {
241241
};
242242
let launchEventDone = true;
243243
let targetRootView: View = null;
244+
const refreshRootViewCss = (expectedRoot?: View) => {
245+
setTimeout(() => {
246+
const currentRoot = Application.getRootView();
247+
if (!currentRoot || (expectedRoot && currentRoot !== expectedRoot)) {
248+
return;
249+
}
250+
251+
try {
252+
(currentRoot as any)._onCssStateChange?.();
253+
} catch {}
254+
}, 0);
255+
};
244256
const setRootView = (ref: NgModuleRef<T | K> | ApplicationRef | View) => {
245257
console.log('[ng-hmr] setRootView called, bootstrapId:', bootstrapId, 'ref type:', ref?.constructor?.name);
246258
if (bootstrapId === -1) {
@@ -271,6 +283,7 @@ export function runNativeScriptAngularApp<T, K>(options: AppRunOptions<T, K>) {
271283
Application.run({ create: () => ref });
272284
} else if (launchEventDone) {
273285
Application.resetRootView({ create: () => ref });
286+
refreshRootViewCss(ref);
274287
} else {
275288
targetRootView = ref;
276289
}
@@ -300,6 +313,7 @@ export function runNativeScriptAngularApp<T, K>(options: AppRunOptions<T, K>) {
300313
childCount: (newRoot as any)?.getChildrenCount?.() ?? 'N/A',
301314
});
302315
Application.resetRootView({ create: () => newRoot });
316+
refreshRootViewCss(newRoot);
303317
console.log('[ng-hmr] setRootView: Application.resetRootView returned');
304318
// Check root view after reset
305319
setTimeout(() => {

0 commit comments

Comments
 (0)