Skip to content

Conversation

clydin
Copy link
Member

@clydin clydin commented Nov 4, 2024

When using the development server with the application builder (default for new projects), Angular components using ShadowDOM view encapsulation will now cause a full page reload. This ensures that these components styles are correctly updated during watch mode. Vite's CSS hot replacement client code currently does not support searching and replacing <link> elements inside shadow roots. When support is available within Vite, an HMR based update for ShadowDOM components can be supported as other view encapsulation modes are now.

When using the development server with the application builder (default for new projects),
Angular components using ShadowDOM view encapsulation will now cause a full page reload.
This ensures that these components styles are correctly updated during watch mode. Vite's
CSS hot replacement client code currently does not support searching and replacing `<link>`
elements inside shadow roots. When support is available within Vite, an HMR based update
for ShadowDOM components can be supported as other view encapsulation modes are now.
@clydin clydin added action: review The PR is still awaiting reviews from at least one requested reviewer target: rc This PR is targeted for the next release-candidate labels Nov 4, 2024
@clydin clydin requested a review from alan-agius4 November 4, 2024 16:35
@clydin clydin added this to the v19 Candidates milestone Nov 4, 2024
const trackingId = componentId || shadow;
if (usedIds === undefined) {
usedComponentStyles.set(pathname, new Set([componentId]));
usedComponentStyles.set(pathname, new Set([trackingId]));
Copy link
Collaborator

Choose a reason for hiding this comment

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

It might be clearer if we structure the data differently rather than using true/false/string, as a object to make it easier to follow:

{
    encapsulation?: string;
    componentId?: string;
}

I can foresee that, in the future, this can be a bit confusing whlist debugging that as component ids we store booleans

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm hoping we can revert this workaround sooner rather than later. Post v19 i may also look into patching the Vite client code to add support for shadow DOM with a potential followup Vite PR.

Copy link
Collaborator

@alan-agius4 alan-agius4 left a comment

Choose a reason for hiding this comment

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

LGTM. one NIT.

@clydin clydin added action: merge The PR is ready for merge by the caretaker and removed action: review The PR is still awaiting reviews from at least one requested reviewer labels Nov 5, 2024
@alan-agius4 alan-agius4 merged commit e6ff801 into angular:main Nov 5, 2024
35 checks passed
@alan-agius4
Copy link
Collaborator

The changes were merged into the following branches: main, 19.0.x

@clydin clydin deleted the hmr/shadow-dom-style-workaround branch November 5, 2024 16:28
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Dec 6, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

action: merge The PR is ready for merge by the caretaker area: @angular/build target: rc This PR is targeted for the next release-candidate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants