Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LWC EmpApi does not work when there is an Aura component using EmpApi #1618

Closed
AllanOricil opened this issue Nov 16, 2019 · 34 comments
Closed
Labels
External: Lightning Web Security / Locker Categorizes issue or PR as related to LWS or Lightning Locker.

Comments

@AllanOricil
Copy link
Contributor

AllanOricil commented Nov 16, 2019

Description

LWC can't subscribe to a Platform Event if there is an Aura component that is subscribing to a Platform event in the same Lightning Page.

Steps to Reproduce

Place an Aura component that subscribes to a Platform Event 1 and a LWC that subscribes to a Platform Event 2 in a Lightning Page. The Aura component subscribed without any problem. The LWC did not subscribe and also did not display any error message or exception. Once I removed the Aura component from the Lightning Page, saved it, and reloaded it, the LWC subscribed to the Platform Event. Bear in mind I did not change anything in the LWC. I just removed the Aura component from the Lightning Page.

I followed the instructions to build the LWC component from here:
https://developer.salesforce.com/docs/component-library/bundle/lightning-emp-api/documentation

And I made the correction to my component that is described here:
https://developer.salesforce.com/forums/ForumsMain?id=9062I000000Xm9eQAC

Again, the LWC code is working! but only if I remove the Aura component from the Lightning Page.

Expected Results

LWC should subscribe to the Platform Event

Actual Results

LWC does not subscribe to the Platform Event and also does not show an errror message or exception

@AllanOricil
Copy link
Contributor Author

To solve my issue for now I just put my LWC into another Lightning Page. It works but an odd behavior happens.

When I load a page which has an Aura component that subscribes to a Platform Event using empApi and then move to another lightning page that has a LWC using empApi, this page throws an exception. If I reload this last lightning page the error is gone.

This is the exception that I have:
image

@miteshmsharma
Copy link

miteshmsharma commented Nov 17, 2019 via email

@AllanOricil
Copy link
Contributor Author

AllanOricil commented Nov 17, 2019

The components don't not communicate with each other! They are completly separated and both subscribe to different platform events. And both work when they are in separated Lightning Pages.
But if I switch from a Lightning page that has an Aura to a Lightning page that has the LWC it throws that above exception. Then if I reload the Lightning Page with the LWC the error is just gone...

My workaround was to transform my Aura to a LWC and everything worked perfectly. So my conclusion is, don't mix Aura and LWC components in a Lightning Page when they are both subscribing to Platform Events. This seems to be a bug.

@joeferraro
Copy link

joeferraro commented Apr 6, 2020

We're having this exact same issue in console. Our steps to reproduce:

  1. Open a console app
  2. Open a console main tab that has a non-namespaced Aura component that subscribes to the empApi when it initializes
  3. Open a separate console main tab that has a namespaced LWC component that subscribes to the empApi when a button is clicked
  4. Click the button in the namespaced LWC component that subscribes to the empApi
  5. Receive the following exception:
Method Promise.prototype.then called on incompatible receiver [object Object]

cc @cdelmoral @adamsheets89 @yippie

@caridy
Copy link
Collaborator

caridy commented Apr 6, 2020

By looking at the error message, this seems like a problem with proxies. Promise.prototype.then expects a branded promise object, but it is receiving a proxy of it most likely, which is not branded. This could be locker service doing the wrong thing.

@joeferraro
Copy link

I have a suspicion this may have something to do with namespaces (at least in relation to the steps to reproduce I laid out above). I am unable to reproduce this issue when the Aura component subscribing is using the same namespace as the LWC component.

@caridy
Copy link
Collaborator

caridy commented Apr 8, 2020

cc @seksenov @manuel-jasso to see if he can re-route this issue to the proper queue, this is definitely not LWC.

@manuel-jasso
Copy link

@seksenov @caridy Tracking on W-7429747

@pmdartus pmdartus added the External: Lightning Web Security / Locker Categorizes issue or PR as related to LWS or Lightning Locker. label May 27, 2020
@vc4u
Copy link

vc4u commented May 30, 2020

Any updates on when this could be fixed? In my use case, I could reproduce this in Summer pre-release org as well.

My environment is set to use an already existing Background Utility Item Aura Component. And I'm building a new LWC component which needs to subscribe to a Change Data Event, now, both are conflicting, and LWC emp-api component is throwing the same error as mentioned above:

Method Promise.prototype.then called on incompatible receiver

@AllanOricil
Copy link
Contributor Author

When I discovered this issue I wasn't using namespaces.

@arneper
Copy link

arneper commented May 31, 2020

seeing exactly same issue even when it is only component on page. @AllanOricil
Thanks for any help!

@seksenov
Copy link

seksenov commented Jun 1, 2020

The Lightning Locker team is tracking and investigating the issue. When we have an update to share on potential resolutions and timeline we will do so.

@arneper
Copy link

arneper commented Jun 1, 2020

@seksenov thanks! It is appreciated

@manuel-jasso
Copy link

Hi @AllanOricil, I am from Locker team, I would like to reproduce this issue, is there an environment you can point me to and steps to reproduce? Ideally, I would like to do that on my local, do you have a repo with code that I can clone and run? I understand this may be part of a large app, I'm just trying to see if we can narrow it down. Also looks like others like @joeferraro may have a similar/simpler way to reproduce?

@AllanOricil
Copy link
Contributor Author

AllanOricil commented Jul 9, 2020

Hi @AllanOricil, I am from Locker team, I would like to reproduce this issue, is there an environment you can point me to and steps to reproduce? Ideally, I would like to do that on my local, do you have a repo with code that I can clone and run? I understand this may be part of a large app, I'm just trying to see if we can narrow it down. Also looks like others like @joeferraro may have a similar/simpler way to reproduce?

HI @manuel-jasso. I did it a long time ago. I will try to find the environment. But you can follow these steps to get the error.

  • Create Platform Event 1 and Platform Event 2.
  • Create a Lightning Page.
  • Add an Aura Component that subscribes to Platform Event 1 to this page.
  • Add a LWC that subscribes to Platform Event 2 to this page. Don't forget to apply the fix that was posted here to your LWC.
  • Check that the Aura Component subscribed and the LWC did not. Also, the LWC didn't display any error message.

To understand that this was a problem caused by mixing LWC and Aura components to the same lightning page, and not my code, I placed both in separate Lightning Pages, and both worked perfectly fine. But then an unexpected behavior started to happen.

To reproduce this one do the following:

  • Go to your Lightning Page 1, which has the Aura component that subscribes to the Platform Event 1.
  • Then "navigate to" the Lightning Page 2, that has a LWC that subscribes to the Platform Event 2.
  • The error message will appear.
  • Reload the Lightning Page 2 and check that the error is gone.

@manuel-jasso
Copy link

Thanks @AllanOricil, kudos to @p-wu-214 (also from Locker) who was able to repro internally, so we can debug...

@AllanOricil
Copy link
Contributor Author

Thanks @AllanOricil, kudos to @p-wu-214 (also from Locker) who was able to repro internally, so we can debug...

@manuel-jasso no problem. I hope it is not too hard to fix it. But you guys can do it! Good luck. Hope to hear the issue was solved soon.

@arcadeteddy
Copy link
Contributor

arcadeteddy commented Jul 21, 2020

@AllanOricil Hey! An update: We debugged the problem, which was an unwrapped promise, and have a fix. Once the fix is in, we will repro the error you are running into and make sure it is working. Will keep you updated when it is tested in the environment and we backport it to an earlier release. Thank you!

@AllanOricil
Copy link
Contributor Author

@AllanOricil Hey! An update: We debugged the problem, which was an unwrapped promise, and have a fix. Once the fix is in, we will repro the error you are running into and make sure it is working. Will keep you updated when it is tested in the environment and we backport it to an earlier release. Thank you!

@arcadeteddy nice! well done guys.

@gyadav4
Copy link

gyadav4 commented Aug 4, 2020

Hey there, any updates?

@arcadeteddy
Copy link
Contributor

@gyadav4 Hey, so the fixes are in! We decided on not back porting it because it touches a critical part of the filtering mechanism.

@AllanOricil
Copy link
Contributor Author

@gyadav4 Hey, so the fixes are in! We decided on not back porting it because it touches a critical part of the filtering mechanism.

What do you mean "not back porting"? Does it mean we can't work with aura and lwc on the same page when using the emp api?

@caridy
Copy link
Collaborator

caridy commented Aug 5, 2020

@AllanOricil it means that we will not fix it in current production code, but in the upcoming release only, which might take a while to hit production.

@AllanOricil
Copy link
Contributor Author

AllanOricil commented Aug 6, 2020

@AllanOricil it means that we will not fix it in current production code, but in the upcoming release only, which might take a while to hit production.

Thanks for clarifying it @caridy
I understood it wrong. Sorry for that.

@iarecuezero
Copy link

Can this issue also occur when a custom LWC component uses emp-api and and an Aura component uses emp-api where the Aura component is in a managed package?

@AllanOricil
Copy link
Contributor Author

Can this issue also occur when a custom LWC component uses emp-api and and an Aura component uses emp-api where the Aura component is in a managed package?

@iarecuezero This can happen if you place both components on the same page.

@fredgaume
Copy link

@caridy Hi there. Seems that we still have the issue. Could you confirm that it has not been fixed in the Winter release? Or am I wrong?

@pazhukh
Copy link

pazhukh commented Apr 13, 2021

Can this issue also occur when a custom LWC component uses emp-api and and an Aura component uses emp-api where the Aura component is in a managed package?

Looks like I have the same problem :(

@AllanOricil
Copy link
Contributor Author

Can this issue also occur when a custom LWC component uses emp-api and and an Aura component uses emp-api where the Aura component is in a managed package?

Looks like I have the same problem :(

If your Aura component is simple, migrate it to LWC. Just don't mix both "frameworks" and you will never have this problem

@KeithClarke
Copy link

KeithClarke commented Dec 24, 2021

Just added a wrapping Aura component to implement lightning:isUrlAddressable for navigation purposes and no longer receiving a platform event in an LWC in the same managed package namespace located in a different page that was previously working. No subscription in the Aura component.

@AllanOricil, I think there may be no work-around for this case?

@AllanOricil
Copy link
Contributor Author

No subsc
@KeithClarke
Don't mix aura with lwc in the same lighting page

@KeithClarke
Copy link

KeithClarke commented Dec 24, 2021

Hi @AllanOricil,

My point was that there is no way to use the documented lightning:isUrlAddressable technique without Aura as well and LWC.

But came back here to delete my comment as this is now all working correctly in a new scratch org so my problem was not this and the Aura/LWC mix is working for me. Sorry for the noise.

@berginrp
Copy link

I have a similar problem.
My lwc is wrapped by an aura component, and is placed within an existing VF page in Service Cloud console.

I'm trying to subscribe to platform event using empApi in my lwc component, but its not subscribing.
When I put the exact thing in a lwc within a Lightning page, the subscription to the event works.

My requirement is to take action based on the event received.

With my usecase, I have to put this lwc into an VF page and have to use aura component to achieve this.
Is there any workaround? any help in this regard is appreciated. thank you!

@AllanOricil AllanOricil closed this as not planned Won't fix, can't repro, duplicate, stale Mar 3, 2023
@ChuckJonas
Copy link

Can this issue also occur when a custom LWC component uses emp-api and and an Aura component uses emp-api where the Aura component is in a managed package?

If your Aura component is simple, migrate it to LWC. Just don't mix both "frameworks" and you will never have this problem

@AllanOricil That's not how Salesforce works... If the Aura component is part of a managed package, you obviously cannot migrate it...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
External: Lightning Web Security / Locker Categorizes issue or PR as related to LWS or Lightning Locker.
Projects
None yet
Development

No branches or pull requests