`ng new --view-encapsulation` has no effect on generated components
Maintainer antworten meist innerhalb von 1 Tag
Ein zugehöriger Pull Request wurde bereits gemerged.
- #34389 von @MeAkib — gemerged
Bewertung
- Schwierigkeit
- 3/5
- Geschätzter Aufwand
- 1-2 Tage
- Anfängerfreundlichkeit
- 35/100
- Issue-Typ
- Bug
- Klarheit
- Klar beschrieben
- Aktivitätsstatus
- Veraltet
- Tech-Stack
- angular, typescript
- Bereich
- build-system, cli
Rechercherichtung
The issue identifies the ng new and ng generate application paths, the generated root App component, angular.json component schematic defaults, and main.ts bootstrap options. Trace how --view-encapsulation flows through those generation paths and compare the generated files with the reproduction steps. Done means the selected mode affects the initial component and later generated components under AOT.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
Command
new
Is this a regression?
- Yes, this behavior used to work in the previous version
The previous version in which this bug was not present was
No response
Description
The --view-encapsulation option of ng new / ng generate application is documented as "Sets the view
encapsulation mode for components in the initial project", but it currently has no effect:
- The root
Appcomponent is generated withoutencapsulation, so its styles stay scoped (Emulated). - The value is not saved to the project's
@schematics/angular:componentdefaults inangular.json, so components
generated later withng g calso use Emulated. - For
--no-standaloneapps,main.tsgetsbootstrapModule(AppModule, { defaultEncapsulation: ViewEncapsulation.X }).
defaultEncapsulationis only read by the JIT compiler, so it has no effect with AOT, which is the default for
ng buildandng serve.
This looks like #13689 again: it was fixed in 89797900db by setting the encapsulation on the root component and in
bootstrapModule, but the root component part was removed in 58bc5b8f2a (for #13742, invalid generated code), leaving
only the JIT-only option.
Minimal Reproduction
ng new ve-repro --defaults --view-encapsulation=None(same result with--no-standalone)- Add
h1 { color: red; }tosrc/app/app.css ng build --configuration development- The output contains
h1[_ngcontent-%COMP%], i.e. the styles are still encapsulated. angular.jsonhas noviewEncapsulationunderprojects.ve-repro.schematics, song g c fooalso generates an
Emulated component.
Exception or Error
Your Environment
Latest
Anything else relevant?
Possible fix: set encapsulation on the generated root component, save viewEncapsulation in the component schematic
defaults, and drop defaultEncapsulation from main.ts. Happy to send a PR.
- Vorherrschende Sprache
- TypeScript
- Sterne
- 27k
- Forks
- 11.8k
- Ø Merge
- 1 T. 5 Std.
- Gemergte PRs (30 T.)
- 240
Entwicklungsumgebung
- Kein Dockerfile und keine Docker-Compose-Datei
- Hat eine Pull-Request-Vorlage
- Beitragsleitfaden lesen
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus angular/angular-cli
-
area: @angular/build gemini-triaged
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 74/100
angular/angular-cli#33955 ·
Maintainer antworten meist innerhalb von 1 Tag
-
area: @angular/cli gemini-triaged
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
angular/angular-cli#33055 · 1 Kommentar · 3 Reaktionen ·
Maintainer antworten meist innerhalb von 1 Tag
-
area: @angular/build
Schwierigkeit 4/5 3-5 Tage Anfängerfreundlichkeit 48/100
angular/angular-cli#34515 · 3 Reaktionen ·
Maintainer antworten meist innerhalb von 1 Tag
-
area: @angular/build
Schwierigkeit 4/5 3-5 Tage Anfängerfreundlichkeit 55/100
angular/angular-cli#34514 · 2 Reaktionen ·
Maintainer antworten meist innerhalb von 1 Tag
-
ssr: string redirectTo drops trailing slash in query and fragmentEvtl. vergeben @alan-agius4 hat das heute übernommen. Offenarea: @angular/ssr
Schwierigkeit 3/5 1-2 Tage Anfängerfreundlichkeit 57/100
angular/angular-cli#34511 ·
Maintainer antworten meist innerhalb von 1 Tag
Alle Issues in angular/angular-cli
Ähnliche Issues
-
[Bug]: REST API URL starting with "http" but no scheme (e.g. httpbin.org/get) is not given an http:// prefixEvtl. vergeben @ItsDeadlyProgrammer hat das heute übernommen. Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 68/100
appsmithorg/appsmith#42471 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 2 Tagen
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
ehmpathy/rhachet-roles-bhrain#705 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 82/100
Maintainer antworten meist innerhalb von 1 Tag
-
Status: Triage
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 76/100
mermaid-js/mermaid#8546 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
braintrustdata/braintrust-sdk-javascript#2659 ·
Maintainer antworten meist innerhalb von 1 Tag