3

I've just moved some logic from one LWC into a "headless" @api invoke() LWC that is configured as an Action that appears as a button in the standard "Highlights Panel" LWC. The method is called, but the LMS message does not make it to the subscribing components.

This documentation says:

... you can take advantage of all of the great services provided in the LWC framework. For example you can use Lightning Data Services to get data from Salesforce, you can use Apex to perform complex operations and you can use Lightning Navigation Service to navigate to other pages in Salesforce.

and this documentation

... communicate across the DOM between Visualforce pages, Aura components, and Lightning web components, including components in a pop-out utility bar.

Reading this Define the Scope of the Message Service hasn't answered this question for me, and no joy Googling so far. Oh and the description of APPLICATION_SCOPE there isn't clear for me.

Some debugging revealed (first value is messageContext, second value is messageChannel__default['default']):

// For the action LWC publish
Symbol(MessageContext_597a18b7_ed66_43b1_bef1_04a6d1ba2b36)
81c785fd_958c_4725_b81f_4c3ac302b7a3

// For a component in the flexi-page body publish
Symbol(MessageContext_0aeda8b3_b4aa_4ad6_a926_78c3ac1736ce)
81c785fd_958c_4725_b81f_4c3ac302b7a3

// For a second component in the flexi-page body publish
Symbol(MessageContext_a3db5e30_9587_4d75_a447_52709b626c0e)
81c785fd_958c_4725_b81f_4c3ac302b7a3

so no obvious difference there.

I assumed that LMS should work in this context and the problem is something I've messed up on. But now I'm not so sure. Can anyone confirm?

1 Answer 1

4

Yes, Lightning Message Service (LMS) does work from a Lightning Web Component Action. The APPLICATION_SCOPE does not necessarily have to be set.

(My problem was that a component I had removed from the UI at the same time contained the subscriber. This code was written by someone else, and the subscriber component being "hidden" within the component I removed was a surprise to me.)

4
  • 1
    Really glad it was user error rather than a product limitation :)
    – Phil W
    Commented Oct 11, 2021 at 9:04
  • 1
    Yeah @PhilW me too. One of those cases where nothing in the docs so that added a bit of uncertainty.
    – Keith C
    Commented Oct 11, 2021 at 9:19
  • Is there a way to go around the requirement to have a Lightning Web Component Action? For example I want to pass a simple string state value each time it has changed. Commented Jan 30 at 13:26
  • Will it work on change or focus events for example? Commented Jan 30 at 13:27

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .