Skip to content

Commit ce28bff

Browse files
arturovtkirjs
authored andcommitted
refactor(platform-browser): drop BROWSER_MODULE_PROVIDERS_MARKER in production (#59412)
In this commit, we switch from decorators (which also produce redundant metadata, such as in the `declareFactory` instruction) to the `inject` function to drop the `BROWSER_MODULE_PROVIDERS_MARKER` token in production. This token is actually provided only in development mode but is still referenced in the constructor due to the `@Inject(BROWSER_MODULE_PROVIDERS_MARKER)` decorator. PR Close #59412
1 parent dec8f91 commit ce28bff

File tree

7 files changed

+17
-24
lines changed

7 files changed

+17
-24
lines changed

goldens/public-api/platform-browser/index.api.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ export function bootstrapApplication(rootComponent: Type<unknown>, options?: App
3333

3434
// @public
3535
export class BrowserModule {
36-
constructor(providersAlreadyPresent: boolean | null);
36+
constructor();
3737
// (undocumented)
38-
static ɵfac: i0.ɵɵFactoryDeclaration<BrowserModule, [{ optional: true; skipSelf: true; }]>;
38+
static ɵfac: i0.ɵɵFactoryDeclaration<BrowserModule, never>;
3939
// (undocumented)
4040
static ɵinj: i0.ɵɵInjectorDeclaration<BrowserModule>;
4141
// (undocumented)

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
"ApplicationRef",
2929
"BROWSER_ANIMATIONS_PROVIDERS",
3030
"BROWSER_MODULE_PROVIDERS",
31-
"BROWSER_MODULE_PROVIDERS_MARKER",
3231
"BROWSER_NOOP_ANIMATIONS_PROVIDERS",
3332
"BaseAnimationRenderer",
3433
"BehaviorSubject",

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
"ApplicationModule",
1010
"ApplicationRef",
1111
"BROWSER_MODULE_PROVIDERS",
12-
"BROWSER_MODULE_PROVIDERS_MARKER",
1312
"BehaviorSubject",
1413
"BrowserDomAdapter",
1514
"BrowserModule",

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
"ApplicationModule",
1414
"ApplicationRef",
1515
"BROWSER_MODULE_PROVIDERS",
16-
"BROWSER_MODULE_PROVIDERS_MARKER",
1716
"BaseControlValueAccessor",
1817
"BehaviorSubject",
1918
"BrowserDomAdapter",

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
"ApplicationModule",
1515
"ApplicationRef",
1616
"BROWSER_MODULE_PROVIDERS",
17-
"BROWSER_MODULE_PROVIDERS_MARKER",
1817
"BaseControlValueAccessor",
1918
"BehaviorSubject",
2019
"BrowserDomAdapter",

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
"ApplicationModule",
1010
"ApplicationRef",
1111
"BROWSER_MODULE_PROVIDERS",
12-
"BROWSER_MODULE_PROVIDERS_MARKER",
1312
"BehaviorSubject",
1413
"BrowserDomAdapter",
1514
"BrowserModule",

packages/platform-browser/src/browser.ts

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,25 +13,20 @@ import {
1313
ɵPLATFORM_BROWSER_ID as PLATFORM_BROWSER_ID,
1414
} from '@angular/common';
1515
import {
16-
APP_ID,
1716
ApplicationConfig as ApplicationConfigFromCore,
1817
ApplicationModule,
1918
ApplicationRef,
2019
createPlatformFactory,
2120
ErrorHandler,
22-
Inject,
2321
InjectionToken,
24-
ModuleWithProviders,
2522
NgModule,
2623
NgZone,
27-
Optional,
2824
PLATFORM_ID,
2925
PLATFORM_INITIALIZER,
3026
platformCore,
3127
PlatformRef,
3228
Provider,
3329
RendererFactory2,
34-
SkipSelf,
3530
StaticProvider,
3631
Testability,
3732
TestabilityRegistry,
@@ -42,6 +37,7 @@ import {
4237
ɵsetDocument,
4338
ɵTESTABILITY as TESTABILITY,
4439
ɵTESTABILITY_GETTER as TESTABILITY_GETTER,
40+
inject,
4541
} from '@angular/core';
4642

4743
import {BrowserDomAdapter} from './browser/browser_adapter';
@@ -264,18 +260,20 @@ const BROWSER_MODULE_PROVIDERS: Provider[] = [
264260
exports: [CommonModule, ApplicationModule],
265261
})
266262
export class BrowserModule {
267-
constructor(
268-
@Optional()
269-
@SkipSelf()
270-
@Inject(BROWSER_MODULE_PROVIDERS_MARKER)
271-
providersAlreadyPresent: boolean | null,
272-
) {
273-
if ((typeof ngDevMode === 'undefined' || ngDevMode) && providersAlreadyPresent) {
274-
throw new RuntimeError(
275-
RuntimeErrorCode.BROWSER_MODULE_ALREADY_LOADED,
276-
`Providers from the \`BrowserModule\` have already been loaded. If you need access ` +
277-
`to common directives such as NgIf and NgFor, import the \`CommonModule\` instead.`,
278-
);
263+
constructor() {
264+
if (typeof ngDevMode === 'undefined' || ngDevMode) {
265+
const providersAlreadyPresent = inject(BROWSER_MODULE_PROVIDERS_MARKER, {
266+
optional: true,
267+
skipSelf: true,
268+
});
269+
270+
if (providersAlreadyPresent) {
271+
throw new RuntimeError(
272+
RuntimeErrorCode.BROWSER_MODULE_ALREADY_LOADED,
273+
`Providers from the \`BrowserModule\` have already been loaded. If you need access ` +
274+
`to common directives such as NgIf and NgFor, import the \`CommonModule\` instead.`,
275+
);
276+
}
279277
}
280278
}
281279
}

0 commit comments

Comments
 (0)