mirror of
https://github.com/angular/angular
synced 2026-05-24 09:28:37 +00:00
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
This commit is contained in:
parent
e8df770141
commit
17510becb0
7 changed files with 17 additions and 24 deletions
|
|
@ -33,9 +33,9 @@ export function bootstrapApplication(rootComponent: Type<unknown>, options?: App
|
|||
|
||||
// @public
|
||||
export class BrowserModule {
|
||||
constructor(providersAlreadyPresent: boolean | null);
|
||||
constructor();
|
||||
// (undocumented)
|
||||
static ɵfac: i0.ɵɵFactoryDeclaration<BrowserModule, [{ optional: true; skipSelf: true; }]>;
|
||||
static ɵfac: i0.ɵɵFactoryDeclaration<BrowserModule, never>;
|
||||
// (undocumented)
|
||||
static ɵinj: i0.ɵɵInjectorDeclaration<BrowserModule>;
|
||||
// (undocumented)
|
||||
|
|
|
|||
|
|
@ -28,7 +28,6 @@
|
|||
"ApplicationRef",
|
||||
"BROWSER_ANIMATIONS_PROVIDERS",
|
||||
"BROWSER_MODULE_PROVIDERS",
|
||||
"BROWSER_MODULE_PROVIDERS_MARKER",
|
||||
"BROWSER_NOOP_ANIMATIONS_PROVIDERS",
|
||||
"BaseAnimationRenderer",
|
||||
"BehaviorSubject",
|
||||
|
|
|
|||
|
|
@ -9,7 +9,6 @@
|
|||
"ApplicationModule",
|
||||
"ApplicationRef",
|
||||
"BROWSER_MODULE_PROVIDERS",
|
||||
"BROWSER_MODULE_PROVIDERS_MARKER",
|
||||
"BehaviorSubject",
|
||||
"BrowserDomAdapter",
|
||||
"BrowserModule",
|
||||
|
|
|
|||
|
|
@ -13,7 +13,6 @@
|
|||
"ApplicationModule",
|
||||
"ApplicationRef",
|
||||
"BROWSER_MODULE_PROVIDERS",
|
||||
"BROWSER_MODULE_PROVIDERS_MARKER",
|
||||
"BaseControlValueAccessor",
|
||||
"BehaviorSubject",
|
||||
"BrowserDomAdapter",
|
||||
|
|
|
|||
|
|
@ -14,7 +14,6 @@
|
|||
"ApplicationModule",
|
||||
"ApplicationRef",
|
||||
"BROWSER_MODULE_PROVIDERS",
|
||||
"BROWSER_MODULE_PROVIDERS_MARKER",
|
||||
"BaseControlValueAccessor",
|
||||
"BehaviorSubject",
|
||||
"BrowserDomAdapter",
|
||||
|
|
|
|||
|
|
@ -9,7 +9,6 @@
|
|||
"ApplicationModule",
|
||||
"ApplicationRef",
|
||||
"BROWSER_MODULE_PROVIDERS",
|
||||
"BROWSER_MODULE_PROVIDERS_MARKER",
|
||||
"BehaviorSubject",
|
||||
"BrowserDomAdapter",
|
||||
"BrowserModule",
|
||||
|
|
|
|||
|
|
@ -13,25 +13,20 @@ import {
|
|||
ɵPLATFORM_BROWSER_ID as PLATFORM_BROWSER_ID,
|
||||
} from '@angular/common';
|
||||
import {
|
||||
APP_ID,
|
||||
ApplicationConfig as ApplicationConfigFromCore,
|
||||
ApplicationModule,
|
||||
ApplicationRef,
|
||||
createPlatformFactory,
|
||||
ErrorHandler,
|
||||
Inject,
|
||||
InjectionToken,
|
||||
ModuleWithProviders,
|
||||
NgModule,
|
||||
NgZone,
|
||||
Optional,
|
||||
PLATFORM_ID,
|
||||
PLATFORM_INITIALIZER,
|
||||
platformCore,
|
||||
PlatformRef,
|
||||
Provider,
|
||||
RendererFactory2,
|
||||
SkipSelf,
|
||||
StaticProvider,
|
||||
Testability,
|
||||
TestabilityRegistry,
|
||||
|
|
@ -42,6 +37,7 @@ import {
|
|||
ɵsetDocument,
|
||||
ɵTESTABILITY as TESTABILITY,
|
||||
ɵTESTABILITY_GETTER as TESTABILITY_GETTER,
|
||||
inject,
|
||||
} from '@angular/core';
|
||||
|
||||
import {BrowserDomAdapter} from './browser/browser_adapter';
|
||||
|
|
@ -264,18 +260,20 @@ const BROWSER_MODULE_PROVIDERS: Provider[] = [
|
|||
exports: [CommonModule, ApplicationModule],
|
||||
})
|
||||
export class BrowserModule {
|
||||
constructor(
|
||||
@Optional()
|
||||
@SkipSelf()
|
||||
@Inject(BROWSER_MODULE_PROVIDERS_MARKER)
|
||||
providersAlreadyPresent: boolean | null,
|
||||
) {
|
||||
if ((typeof ngDevMode === 'undefined' || ngDevMode) && providersAlreadyPresent) {
|
||||
throw new RuntimeError(
|
||||
RuntimeErrorCode.BROWSER_MODULE_ALREADY_LOADED,
|
||||
`Providers from the \`BrowserModule\` have already been loaded. If you need access ` +
|
||||
`to common directives such as NgIf and NgFor, import the \`CommonModule\` instead.`,
|
||||
);
|
||||
constructor() {
|
||||
if (typeof ngDevMode === 'undefined' || ngDevMode) {
|
||||
const providersAlreadyPresent = inject(BROWSER_MODULE_PROVIDERS_MARKER, {
|
||||
optional: true,
|
||||
skipSelf: true,
|
||||
});
|
||||
|
||||
if (providersAlreadyPresent) {
|
||||
throw new RuntimeError(
|
||||
RuntimeErrorCode.BROWSER_MODULE_ALREADY_LOADED,
|
||||
`Providers from the \`BrowserModule\` have already been loaded. If you need access ` +
|
||||
`to common directives such as NgIf and NgFor, import the \`CommonModule\` instead.`,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue