Skip to content

Commit 6e1599d

Browse files
atscottmmalerba
authored andcommitted
refactor(router): Add internal flag to control async vs rxjs recognize (angular#62994)
To aid in hitting external breaking change deadlines without pressure of fixing everything in g3 first, add an internal opt out flag. This also adds a privately exported provider to revert to the old rxjs-based behavior, which can be synchronous, until any issues that come up are addressed. PR Close angular#62994
1 parent 5b53535 commit 6e1599d

File tree

9 files changed

+922
-44
lines changed

9 files changed

+922
-44
lines changed

packages/core/test/acceptance/injector_profiler_spec.ts

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,7 @@ describe('getInjectorMetadata', () => {
456456
});
457457
afterEach(() => setInjectorProfiler(null));
458458

459-
it('should be able to determine injector type and name', fakeAsync(() => {
459+
it('should be able to determine injector type and name', async () => {
460460
class MyServiceA {}
461461
@NgModule({providers: [MyServiceA]})
462462
class ModuleA {}
@@ -500,8 +500,7 @@ describe('getInjectorMetadata', () => {
500500
});
501501

502502
const root = TestBed.createComponent(MyStandaloneComponent);
503-
TestBed.inject(Router).navigateByUrl('/lazy');
504-
tick();
503+
await TestBed.inject(Router).navigateByUrl('/lazy');
505504
root.detectChanges();
506505

507506
function afterLazyComponentRendered(lazyComponent: LazyComponent) {
@@ -537,7 +536,7 @@ describe('getInjectorMetadata', () => {
537536
expect(injectorMetadata[4]!.type).toBe('environment');
538537
expect(injectorMetadata[5]!.type).toBe('environment');
539538
}
540-
}));
539+
});
541540

542541
it('should return null for injectors it does not recognize', () => {
543542
class MockInjector extends Injector {
@@ -814,7 +813,7 @@ describe('getInjectorProviders', () => {
814813
expect(myServiceBProvider!.importPath![2]).toBe(ModuleC);
815814
});
816815

817-
it('should be able to determine import paths after module provider flattening in the standalone component case with lazy components', fakeAsync(() => {
816+
it('should be able to determine import paths after module provider flattening in the standalone component case with lazy components', async () => {
818817
class MyService {}
819818

820819
@NgModule({providers: [MyService]})
@@ -850,8 +849,7 @@ describe('getInjectorProviders', () => {
850849
],
851850
});
852851
const root = TestBed.createComponent(MyStandaloneComponent);
853-
TestBed.inject(Router).navigateByUrl('/lazy');
854-
tick();
852+
await TestBed.inject(Router).navigateByUrl('/lazy');
855853
root.detectChanges();
856854

857855
const myStandaloneComponentNodeInjector = root.componentRef.injector;
@@ -883,9 +881,9 @@ describe('getInjectorProviders', () => {
883881
expect(myServiceProviderRecord!.importPath!.length).toBe(2);
884882
expect(myServiceProviderRecord!.importPath![0]).toBe(MyStandaloneComponentB);
885883
expect(myServiceProviderRecord!.importPath![1]).toBe(ModuleA);
886-
}));
884+
});
887885

888-
it('should be able to determine providers in a lazy route that has providers', fakeAsync(() => {
886+
it('should be able to determine providers in a lazy route that has providers', async () => {
889887
class MyService {}
890888

891889
@Component({selector: 'my-comp-b', template: 'hello world'})
@@ -915,8 +913,7 @@ describe('getInjectorProviders', () => {
915913
],
916914
});
917915
const root = TestBed.createComponent(MyStandaloneComponent);
918-
TestBed.inject(Router).navigateByUrl('/lazy');
919-
tick();
916+
await TestBed.inject(Router).navigateByUrl('/lazy');
920917
root.detectChanges();
921918

922919
const myStandalonecomponentB = root.componentRef.instance!.routerOutlet!
@@ -935,7 +932,7 @@ describe('getInjectorProviders', () => {
935932
expect(myServiceProviderRecord).toBeTruthy();
936933
expect(myServiceProviderRecord!.provider).toBe(MyService);
937934
expect(myServiceProviderRecord!.token).toBe(MyService);
938-
}));
935+
});
939936

940937
it('should be able to determine providers in an injector that was created manually', fakeAsync(() => {
941938
class MyService {}
@@ -1034,7 +1031,7 @@ describe('getDependenciesFromInjectable', () => {
10341031
});
10351032
afterEach(() => setInjectorProfiler(null));
10361033

1037-
it('should be able to determine which injector dependencies come from', fakeAsync(() => {
1034+
it('should be able to determine which injector dependencies come from', async () => {
10381035
class MyService {}
10391036
class MyServiceB {}
10401037
class MyServiceC {}
@@ -1109,8 +1106,7 @@ describe('getDependenciesFromInjectable', () => {
11091106
});
11101107

11111108
const root = TestBed.createComponent(MyStandaloneComponent);
1112-
TestBed.inject(Router).navigateByUrl('/lazy');
1113-
tick();
1109+
await TestBed.inject(Router).navigateByUrl('/lazy');
11141110
root.detectChanges();
11151111

11161112
const myStandalonecomponentB = root.componentRef.instance!.routerOutlet!
@@ -1232,9 +1228,9 @@ describe('getDependenciesFromInjectable', () => {
12321228
// The NodeInjector that provides MyService is not in the host path of this injector.
12331229
expect(deps!.dependencies[0].providedIn).toBeUndefined();
12341230
}
1235-
}));
1231+
});
12361232

1237-
it('should be able to recursively determine dependencies of dependencies by using the providedIn field', fakeAsync(() => {
1233+
it('should be able to recursively determine dependencies of dependencies by using the providedIn field', async () => {
12381234
@Injectable()
12391235
class MyService {
12401236
myServiceB = inject(MyServiceB);
@@ -1318,7 +1314,7 @@ describe('getDependenciesFromInjectable', () => {
13181314
host: false,
13191315
});
13201316
expect(routerDependency.providedIn).toBe((standaloneInjector as R3Injector).parent);
1321-
}));
1317+
});
13221318
});
13231319

13241320
describe('getInjectorResolutionPath', () => {
@@ -1328,7 +1324,7 @@ describe('getInjectorResolutionPath', () => {
13281324
});
13291325
afterEach(() => setInjectorProfiler(null));
13301326

1331-
it('should be able to inspect injector hierarchy structure', fakeAsync(() => {
1327+
it('should be able to inspect injector hierarchy structure', async () => {
13321328
class MyServiceA {}
13331329
@NgModule({providers: [MyServiceA]})
13341330
class ModuleA {}
@@ -1368,8 +1364,7 @@ describe('getInjectorResolutionPath', () => {
13681364
],
13691365
});
13701366
const root = TestBed.createComponent(MyStandaloneComponent);
1371-
TestBed.inject(Router).navigateByUrl('/lazy');
1372-
tick();
1367+
await TestBed.inject(Router).navigateByUrl('/lazy');
13731368
root.detectChanges();
13741369

13751370
function onLazyComponentCreated() {
@@ -1464,5 +1459,5 @@ describe('getInjectorResolutionPath', () => {
14641459

14651460
expect(path[6]).toBeInstanceOf(NullInjector);
14661461
}
1467-
}));
1462+
});
14681463
});

packages/core/test/bundling/router/bundle.golden_symbols.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"chunks": {
33
"main": [
4+
"ABSOLUTE_REDIRECT_ERROR_NAME",
45
"AFTER_RENDER_SEQUENCES_TO_ADD",
56
"ANIMATIONS_DISABLED",
67
"APP_BASE_HREF",
@@ -177,6 +178,7 @@
177178
"NOT_FOUND_CHECK_ONLY_ELEMENT_INJECTOR",
178179
"NOT_YET",
179180
"NO_CHANGE",
181+
"NO_MATCH_ERROR_NAME",
180182
"NO_PARENT_INJECTOR",
181183
"NULL_INJECTOR",
182184
"Navigation",
@@ -232,6 +234,7 @@
232234
"REACTIVE_LVIEW_CONSUMER_NODE",
233235
"REACTIVE_NODE",
234236
"REACTIVE_TEMPLATE_CONSUMER",
237+
"RECOGNIZE_IMPL",
235238
"REFERENCE_NODE_BODY",
236239
"REFERENCE_NODE_HOST",
237240
"REF_EXTRACTOR_REGEXP",
@@ -865,7 +868,7 @@
865868
"iterator",
866869
"joinWithSlash",
867870
"last",
868-
"last2",
871+
"last3",
869872
"lastNodeWasCreated",
870873
"lastSelectedElementIdx",
871874
"leaveDI",
@@ -1114,6 +1117,7 @@
11141117
"take",
11151118
"takeLast",
11161119
"takeUntil",
1120+
"takeUntilAbort",
11171121
"tap",
11181122
"textBindingInternal",
11191123
"throwError",

0 commit comments

Comments
 (0)