Skip to content

fix(@schematics/angular): apply viewEncapsulation to generated application components - #34389

Merged
clydin merged 1 commit into
angular:mainfrom
MeAkib:fix/view-encapsulation
Oct 19, 2026
Merged

clydin merged 1 commit into
angular:mainfrom
MeAkib:fix/view-encapsulation

Conversation

@MeAkib

@MeAkib MeAkib commented Oct 18, 2026

Copy link
Copy Markdown
Contributor

The viewEncapsulation option of the application schematic had no effect. The root component template did not set encapsulation, the value was not added to the component schematic defaults, so components generated later used the default encapsulation, and the defaultEncapsulation option added to bootstrapModule in main.ts for NgModule applications is only used by the JIT compiler.

Set encapsulation on the root component, add viewEncapsulation to the component schematic defaults in angular.json, and remove the ineffective defaultEncapsulation option from main.ts.

Fixes #34388

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates the Angular application schematic to configure viewEncapsulation directly on the root component (via the @component decorator) instead of setting defaultEncapsulation globally in main.ts during bootstrapping. It also ensures that viewEncapsulation is added to the component schematic defaults in the workspace configuration when provided, and includes comprehensive unit tests to verify these changes. There are no review comments, so I have no feedback to provide.

@alan-agius4 alan-agius4 added P0 Issue that causes an outage, breakage, or major function to be unusable, with no known workarounds target: patch This PR is targeted for the next patch release action: merge The PR is ready for merge by the caretaker and removed P0 Issue that causes an outage, breakage, or major function to be unusable, with no known workarounds labels Oct 19, 2026
…ication components

The `viewEncapsulation` option of the application schematic had no effect. The root
component template did not set `encapsulation`, the value was not added to the
component schematic defaults, so components generated later used the default
encapsulation, and the `defaultEncapsulation` option added to `bootstrapModule` in
`main.ts` for NgModule applications is only used by the JIT compiler.

Set `encapsulation` on the root component, add `viewEncapsulation` to the component
schematic defaults in `angular.json`, and remove the ineffective `defaultEncapsulation`
option from `main.ts`.

Fixes angular#34388
@alan-agius4
alan-agius4 force-pushed the fix/view-encapsulation branch from 5277be5 to 6d084cb Compare October 19, 2026 08:38
@clydin
clydin merged commit 1c1fe4e into angular:main Oct 19, 2026
39 checks passed
@clydin

clydin commented Oct 19, 2026

Copy link
Copy Markdown
Member

This PR was merged into the repository. The changes were merged into the following branches:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

action: merge The PR is ready for merge by the caretaker area: @schematics/angular target: patch This PR is targeted for the next patch release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ng new --view-encapsulation has no effect on generated components

3 participants