Salesforce Decode
Salesforcedecode
Back to questions
LWCAdvancedeventsshadow-domcomposition

Architect shadow DOM event retargeting for nested custom elements

Real World Scenario

Nested LWCs inside a third-party wrapper fail to bubble click events to document-level analytics listeners in Experience Cloud.

Expected Answer

• Understand composed: true on CustomEvent for shadow boundary crossing • Prefer semantic custom events over relying on native click retargeting • Document which events cross boundaries for integration partners • Use event.stopPropagation deliberately only when encapsulation required • Test analytics in Experience Cloud vs Lightning — Locker differences • Provide callback @api or LMS channel for analytics instead of DOM listeners where possible • Version event payload schema for backward compatible analytics

Follow-Up Questions & Answers

Click to expand — each follow-up includes a direct, interview-ready answer

Main difference: use case and scale. Understand composed: true on CustomEvent for shadow boundary crossing. Prefer semantic custom events over relying on native click retargeting. Pick based on your integration pattern and team capability. Analytics architecture should not depend on fragile DOM event bubbling from encapsulated LWCs. Optimize for scale and operational observability.

Architect Perspective

Analytics architecture should not depend on fragile DOM event bubbling from encapsulated LWCs.