Define the Scope of the Message Service

The Lightning message service lets you define the scope of where subscribing components receive messages in your application. You can limit the scope to the active area of the application or set the scope to the entire application.

For Lightning web components, the scoping feature is available only when using @wire(MessageContext).

The application's active area includes selected navigation tabs and items, utility items, and ES6 libraries. Utility items are always active. Navigation tabs and items include:

  • Standard navigation tabs
  • Console navigation workspace tabs
  • Console navigation subtabs
  • Console navigation items

Diagram illustrating active subscription scope regions versus application subscription scope regions

To receive messages on a message channel from anywhere in the application, import APPLICATION_SCOPE from lightning/messageService. Then, call subscribe() and pass { scope: APPLICATION_SCOPE } for the optional fourth subscriberOptions parameter.

Receiving messages from the active area is the default behavior. You don’t need to include the scope property to limit scope to the active area.

The lwc-recipes repo has several examples that demonstrate Lightning message service usage. Look for components that start with lms, such as lmsPublisherWebComponent.

See Also