`ng new --view-encapsulation` has no effect on generated components
Mantenedores costumam responder em até 1 dia
Um pull request relacionado já foi integrado.
- #34389 de @MeAkib — integrado
Avaliação
- Dificuldade
- 3/5
- Tempo estimado
- 1-2 dias
- Facilidade para iniciantes
- 35/100
- Tipo de issue
- Bug
- Clareza
- Claramente especificada
- Status de atividade
- Estagnada
- Stack de tecnologia
- angular, typescript
- Domínio
- build-system, cli
Direção de pesquisa
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.
Escrita pelo modelo de indexação a partir do texto da issue.
Descrição
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.
- Linguagem predominante
- TypeScript
- Estrelas
- 27k
- Forks
- 11.8k
- Merge médio
- 1d 6h
- PRs com merge (30d)
- 224
Preparar o ambiente
- Sem Dockerfile nem arquivo Docker Compose
- Tem um modelo de pull request
- Ler o guia de contribuição
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Mais de angular/angular-cli
-
area: @angular/build gemini-triaged
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 74/100
angular/angular-cli#33955 ·
Mantenedores costumam responder em até 1 dia
-
area: @angular/cli gemini-triaged
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 72/100
angular/angular-cli#33055 · 1 comentário · 3 reações ·
Mantenedores costumam responder em até 1 dia
-
area: @angular/ssr
Dificuldade 4/5 3-5 dias Facilidade para iniciantes 53/100
angular/angular-cli#34474 ·
Mantenedores costumam responder em até 1 dia
-
`ng generate app-shell` and `ng generate module --route` produce broken imports when a component `type` is configuredTalvez já em andamento @MeAkib assumiu há 2 dias. Abertaarea: @schematics/angular
Dificuldade 3/5 1-2 dias Facilidade para iniciantes 35/100
angular/angular-cli#34449 ·
Mantenedores costumam responder em até 1 dia
-
Tailwind CSS v4 classes in new or moved files are not picked up by ng serve until another rebuildTalvez já em andamento @MeAkib assumiu há 2 dias. Abertaarea: @angular/build
Dificuldade 4/5 3-5 dias Facilidade para iniciantes 35/100
angular/angular-cli#34446 ·
Mantenedores costumam responder em até 1 dia
Todas as issues de angular/angular-cli
Issues semelhantes
-
Dificuldade 1/5 Menos de uma hora Facilidade para iniciantes 68/100
cursor/community-plugins#465 ·
Mantenedores costumam responder em até 1 dia
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 66/100
vetro-protocol/vetro-monorepo#978 ·
Mantenedores costumam responder em até 1 dia
-
ai-generated bug category:security effort:s priority:p3
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 67/100
LanternOps/breeze#9697 ·
Mantenedores costumam responder em até 1 dia
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 68/100
maniator/verticopolis#1303 · 1 comentário ·
Mantenedores costumam responder em até 1 dia
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 73/100
components-web-app/docs#297 ·