-
Notifications
You must be signed in to change notification settings - Fork 444
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
fix: preserve this inside addEventListener #496
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
@esjs Out of curiosity, could I know your application stack? what third party scripts are you using and which framework? |
@gioboa Sure, it's not a big secret. We have a PHP backend. On frontend we don't use any frameworks, it's just a good old jQuery (although we have a plan to get rid of it), everything is bundled together using custom Webpack build. In terms of 3rd party code, it's really hard to give you definitive list, because we have a lot of editions for different languages. As I said previously it's really hard to give you a definitive list of all 3rd party services we use, but you can check yourself here https://www.motorsport.com/. Keep in mind that there is more than one edition, full list looks like this |
OneTrust and Piano are working fine with PartyTown? |
OneTrust seems to be working fine with this fix in place. |
Thanks for sharing 😉 |
@esjs - How did you get OneTrust working with party town? Did you need to forward anything? |
@spacedawwwg let's wait @esjs response 😉 |
@gioboa I think we diagnosed this one as the OneTrust script trying to access a DOM element (a button that we have to add to every page) that does not exist (as it's trying to find it in the partytown iframe, not the 'real' DOM) - So I'm not 100% sure on a solution for this as we need to the script to bind to that button. My colleague @ajwhitehead88 thinks we need to be able to access
|
@spacedawwwg I cannot check this right now (maybe something changed and it doesn't work anymore), but it worked for me with all changes in this fork (as far as I remember there were 3 of them in total). |
Thanks @esjs |
@gioboa All of changes in fork mentioned above have merge request for main repo, so there is no need to check what is the difference if it would work. |
@gioboa Absolutely, will do 👍🏻 It'd be good discuss the nuances of working with Partytown and what to look out for/configure with more complicated third party scripts like OneTrust. @esjs It might just be that OneTrust code is different per implementation and our scripts are doing something different 🤷🏻♂️ |
What is it?
Description
This will update addEventListener method to always have correct
this
value, even when it's called without context.Use cases and why
While updating OneTrust service integration on our website to use Partytown, I've noticed that they are using addEventListener alongside window.attachEvent to support older versions of browsers.
The problem with the code they've written is that when addEventListener is called inside of WebWorker's addEventListener it has no context (
this === undefined
) and we get an errorLooks like we can easily update Partytown to support such cases by simply updating addEventListener to use arrow function (which preserves context).
P.S.
postMessage
method in this class has same problem, but I'm not sure whether we need to update as well, although I don't see any problems in doing so. I can update this PR to make it use arrow function if you think that it's a good idea.Checklist: