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

Handles ES5 transpilation #943

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open

Conversation

massinissanm
Copy link

@massinissanm massinissanm commented Dec 19, 2022

This PR allows ES5 transpilation.
We've recently been using Sentry on our apps and it caught this exception on multiple occasions

SyntaxError: Unexpected token '.' at definition.actionssessionIdperform (webpack://[name]Destination/./src/destinations/amplitude-plugins/sessionId/index.ts:60:23

To fix this issue I suggest to convert the code into ES5 compatible browser.

Testing

Include any additional information about the testing you have completed to
ensure your changes behave as expected. For a speedy review, please check
any of the tasks you completed below during your testing.

  • Added unit tests for new functionality
  • Tested end-to-end using the local server
  • [Segmenters] Tested in the staging environment

@massinissanm massinissanm requested review from a team as code owners December 19, 2022 11:03
@massinissanm massinissanm requested a review from a team December 19, 2022 11:03
@silesky
Copy link
Contributor

silesky commented Dec 19, 2022

Thanks. This makes sense to me, as, on the analytics SDK, we transpile to ES5.

silesky
silesky previously approved these changes Jan 2, 2023
@silesky
Copy link
Contributor

silesky commented Jan 2, 2023

@dlasky I'm approving, but the full CI test suite should be run against this branch for a change like this (for example, the tsc build will break if some action tries to use certain features like es6 private fields). How should we handle this?

@chrisradek
Copy link
Contributor

Sorry to be chiming in on this late (been on vacation the last 2 weeks).

Can you share what browser environment is encountering this error? I'm wondering if it is really necessary to go all the way back to ES5, or if there's a compromise where we can go with ES2015.

I also think we should be handling the transpilation via webpack, not the tsconfig. This would only impact the web bundles then, and would not require cloud mode destinations to run ES5 code. I also think this is safer long-term in case we have dependencies outside of our control that drop ES5 support (assuming that's really needed), and lets cloud mode destinations continue to take advantage of runtime improvements that target newer ES standards.

@massinissanm
Copy link
Author

massinissanm commented Jan 3, 2023

Sorry to be chiming in on this late (been on vacation the last 2 weeks).

Hi!

Can you share what browser environment is encountering this error? I'm wondering if it is really necessary to go all the way back to ES5, or if there's a compromise where we can go with ES2015.

it happened with Chrome mobile, Safari Mobile, Edge, Firefox, Chrome, Headless Chrome... basically every common browser possible.

I also think we should be handling the transpilation via webpack, not the tsconfig.

To be honest, that is the first thing i tried but i failed in doing so (not very familiar with webpack). But i'll give it another try today.

EDIT : i tried to remove the tsconfig targets and added a target in the unobfuscatedOutput. But i doens't built to es5 this way. I can still see the faulty line in the browser-destinations/dist/destinations/amplitude-plugins/sessionId/index.js
if (context.event.integrations?.All !== false || context.event.integrations['Actions Amplitude'])
which should have transpiled to
if (((_b = context.event.integrations) === null || _b === void 0 ? void 0 : _b.All) !== false || context.event.integrations['Actions Amplitude'])
to work seamlessy with es5 browsers...

@dlasky
Copy link
Contributor

dlasky commented Jan 3, 2023

@dlasky I'm approving, but the full CI test suite should be run against this branch for a change like this (for example, the tsc build will break if some action tries to use certain features like es6 private fields). How should we handle this?

I'm concerned about how this will impact cloud as well, I would prefer if we figured out the webpack approach since that only affects the bundles built for browser + CDN and not the actual published npm libs which are internally consumed in several other places and have a current expectation of being 2018.

We can of of course test that, but it's a fairly concerning change given the surface area that is potentially impacted.

@massinissanm
Copy link
Author

massinissanm commented Jan 4, 2023

ok. I think i waas looking at the wrong file trying to see if the transpilation went well.
As i updated webpack config with a target:['web', 'es5'], the dist folder impacted was browser-destinations/dist/web not browser-destinations/dist/destinations/amplitude-plugins/sessionId/index.js.
But now i don't know where to look in the aforementioned folder to check if it transpiled as intended... any clue ?

Copy link
Contributor

@dlasky dlasky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would like to see a webpack only approach here

@massinissanm
Copy link
Author

massinissanm commented Jan 4, 2023

would like to see a webpack only approach here

Hi Dan, here it is ;) 87bcc3b

@silesky silesky self-requested a review January 4, 2023 16:01
@silesky silesky dismissed their stale review January 4, 2023 19:12

Discussion

@massinissanm
Copy link
Author

Hi ! does the webpack only approach fits the bill ?
Best

@dlasky
Copy link
Contributor

dlasky commented Jan 6, 2023

Yep, i'll approve, but given the nature of the change we'll need to do some fairly extensive testing prior to merging.

Thanks for your patience!

@chrisradek
Copy link
Contributor

Yes I'll take a look as well. I do think we should be able to get away with transpiling to 2015 instead of es5 - it seems like the issue this is directly fixing is around our use of the nullish operator which isn't supported until later versions of ES.

@massinissanm
Copy link
Author

Yep, i'll approve, but given the nature of the change we'll need to do some fairly extensive testing prior to merging.

Thanks for your patience!

@dlasky Great! thanks

Yes I'll take a look as well. I do think we should be able to get away with transpiling to 2015 instead of es5 - it seems like the issue this is directly fixing is around our use of the nullish operator which isn't supported until later versions of ES.

@chrisradek Do you want me to update the PR ?

@massinissanm
Copy link
Author

Yes I'll take a look as well. I do think we should be able to get away with transpiling to 2015 instead of es5 - it seems like the issue this is directly fixing is around our use of the nullish operator which isn't supported until later versions of ES.

Hi @chrisradek ! i was going to fix my PR and saw in Webpack documentation that

When no information about the target or the environment features is provided, then ES2015 will be used.

(https://webpack.js.org/configuration/target/#:~:text=When%20no%20information%20about%20the%20target%20or%20the%20environment%20features%20is%20provided%2C%20then%20ES2015%20will%20be%20used.)

So i guess that won't fix the issue. Have you had any time to run the extensive tests you had in mind ?

@massinissanm
Copy link
Author

Yes I'll take a look as well. I do think we should be able to get away with transpiling to 2015 instead of es5 - it seems like the issue this is directly fixing is around our use of the nullish operator which isn't supported until later versions of ES.

Hi @chrisradek ! i was going to fix my PR and saw in Webpack documentation that

When no information about the target or the environment features is provided, then ES2015 will be used.

(https://webpack.js.org/configuration/target/#:~:text=When%20no%20information%20about%20the%20target%20or%20the%20environment%20features%20is%20provided%2C%20then%20ES2015%20will%20be%20used.)

So i guess that won't fix the issue. Have you had any time to run the extensive tests you had in mind ?

Hi @dlasky , @chrisradek ! How are you doing ? Do you guys have had time to look at that PR and messages here ?
Best

@massinissanm
Copy link
Author

Hi @dlasky , @chrisradek ! How are you doing ? Do you guys have had time to look at that PR and messages here ?
Best

@massinissanm
Copy link
Author

Hi @dlasky , @chrisradek ! Could you tell me please if there's anything else i can do ?

@vthibault
Copy link

Is this going to be merged ?
We missed events from 16k users because of this. We are thinking to move to server-side calls instead to avoid problems :/

@silesky
Copy link
Contributor

silesky commented Apr 20, 2023

cc @SyedWasiHaider

@silesky
Copy link
Contributor

silesky commented Apr 20, 2023

@chrisradek This would only impact the web bundles then, and would not require cloud mode destinations to run ES5 code.
Since only browser-destinations/tsconfig.json, it shouldn't affect cloud mode destinations?

Can we just go back to the fix of making browser-destinations/tsconfig.json target ES2015?

@massinissanm
Copy link
Author

@chrisradek This would only impact the web bundles then, and would not require cloud mode destinations to run ES5 code.
Since only browser-destinations/tsconfig.json, it shouldn't affect cloud mode destinations?

Can we just go back to the fix of making browser-destinations/tsconfig.json target ES2015?

Can we ?

@silesky
Copy link
Contributor

silesky commented Apr 26, 2023

@massinissanm Ahh, I remember why we prefer to use webpack -- there are shared / core dependencies that we also want to bundle, and just changing the target of this one repo won't do that. We don't want to have to change the tsconfig build targets of those shared dependencies -- since they are also run in node.js. We want to bundle and transpile everything together and we need webpack for that.

@Jackman3005
Copy link

Hey all, we're still having issues that this PR was hoping to resolve. Things look like they have stalled with this PR, is it possible to get it across the finish line or is another approach required?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants