Skip to content

Commit 5dfc2a8

Browse files
committed
fix: update app.component and test-setup for zoneless
1 parent b8d6da7 commit 5dfc2a8

File tree

2 files changed

+35
-7
lines changed

2 files changed

+35
-7
lines changed

projects/www/src/app/app.component.ts

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
import { Component, Injector, PLATFORM_ID, inject } from '@angular/core';
1+
import {
2+
Component,
3+
Injector,
4+
PLATFORM_ID,
5+
inject,
6+
OnDestroy,
7+
} from '@angular/core';
28
import { RouterOutlet } from '@angular/router';
39
import { isPlatformBrowser } from '@angular/common';
410
import { MenuComponent } from './components/menu.component';
@@ -11,7 +17,6 @@ import { FooterComponent } from './components/footer.component';
1117

1218
@Component({
1319
selector: 'ngrx-root',
14-
standalone: true,
1520
imports: [
1621
RouterOutlet,
1722
MenuComponent,
@@ -47,39 +52,56 @@ import { FooterComponent } from './components/footer.component';
4752
`,
4853
],
4954
})
50-
export class AppComponent {
51-
injector = inject(Injector);
52-
platformId = inject(PLATFORM_ID);
55+
export class AppComponent implements OnDestroy {
56+
private isAlive = true;
57+
private injector = inject(Injector);
58+
private platformId = inject(PLATFORM_ID);
5359

5460
constructor() {
5561
if (isPlatformBrowser(this.platformId)) {
5662
this.installCustomElements();
5763
}
5864
}
5965

66+
ngOnDestroy(): void {
67+
this.isAlive = false;
68+
}
69+
6070
async installCustomElements() {
71+
if (!this.isAlive) return;
72+
6173
const { createCustomElement } = await import('@angular/elements');
6274

75+
if (!this.isAlive) return;
76+
6377
const symbolLinkElement = createCustomElement(MarkdownSymbolLinkComponent, {
6478
injector: this.injector,
6579
});
6680
customElements.define('ngrx-docs-symbol-link', symbolLinkElement);
6781

82+
if (!this.isAlive) return;
83+
6884
const alertElement = createCustomElement(AlertComponent, {
6985
injector: this.injector,
7086
});
7187
customElements.define('ngrx-docs-alert', alertElement);
7288

89+
if (!this.isAlive) return;
90+
7391
const codeExampleElement = createCustomElement(CodeExampleComponent, {
7492
injector: this.injector,
7593
});
7694
customElements.define('ngrx-code-example', codeExampleElement);
7795

96+
if (!this.isAlive) return;
97+
7898
const codeTabsElement = createCustomElement(CodeTabsComponent, {
7999
injector: this.injector,
80100
});
81101
customElements.define('ngrx-code-tabs', codeTabsElement);
82102

103+
if (!this.isAlive) return;
104+
83105
const stackblitzElement = createCustomElement(StackblitzComponent, {
84106
injector: this.injector,
85107
});

projects/www/src/test-setup.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
11
import '@angular/compiler';
2-
import '@analogjs/vite-plugin-angular/setup-vitest';
2+
import '@analogjs/vitest-angular/setup-snapshots';
33

4+
import { provideZonelessChangeDetection, NgModule } from '@angular/core';
45
import {
56
BrowserTestingModule,
67
platformBrowserTesting,
78
} from '@angular/platform-browser/testing';
89
import { getTestBed } from '@angular/core/testing';
910

11+
@NgModule({
12+
providers: [provideZonelessChangeDetection()],
13+
})
14+
export class ZonelessTestModule {}
15+
1016
getTestBed().initTestEnvironment(
11-
BrowserTestingModule,
17+
[BrowserTestingModule, ZonelessTestModule],
1218
platformBrowserTesting()
1319
);

0 commit comments

Comments
 (0)