Question presented to candidate:
"Take one small component and compile it three times, with Emulated, ShadowDom and None. Walk me through what the compiler emits for each, and what ends up in the DOM at runtime."
What a strong answer should cover:
- Emulated (default): the compiler rewrites each selector to require
[_ngcontent-%COMP%], and:hostbecomes[_nghost-%COMP%]; at runtime%COMP%is replaced by a component id likeng-c3599773454, the host gets_nghost-…and template elements get_ngcontent-…; styles go into a<style>in<head>. - None: CSS is emitted unchanged with
encapsulation: 2; it lands in<head>and is global;:hostmatches nothing. - ShadowDom: CSS also unchanged with
encapsulation: 3; Angular callsattachShadowand puts styles inside the shadow root; no generated attributes. - Gotcha: in ShadowDom mode Angular also copies the other components' styles into the shadow root, so a None rule can still reach inside;
ExperimentalIsolatedShadowDom(v21, experimental) stops that. - A component with no styles is compiled with
encapsulation: 2regardless, so no attributes are stamped.
Clarifying questions expected:
- "Do you want the compiler's
ɵcmpdefinition, the runtime DOM, or both?" - "Is the Shadow DOM component meant to be isolated from global styles too?"
Code / implementation expected: Yes — the three components plus a dump of the generated CSS and DOM.