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

fix: async not transpiled on babel for older browser #174

Closed
wants to merge 4 commits into from

Conversation

chenxeed
Copy link

@chenxeed chenxeed commented Aug 6, 2024

About the changes

  • old browser (chrome v50) gets error from the async await
  • despite attempt to transpile with babel-plugin-transform-async-to-generator, it still not transpiled on my compiler
  • solution is to update the codebase, since there is no value to return, might as well directly return the method result if it's a Promise

Closes #173

Important files

Discussion points

Technically if updateContext have nothing to return, then we don't need to use async as well to wrap the function here. CMIIW.

- old browser (chrome v50) gets error from the async await
- despite attempt to transpile with babel-plugin-transform-async-to-generator, it still not transpiled on my compiler
- solution is to update the codebase, since there is no value to return, might as well directly return the method result if it's a Promise
@gastonfournier gastonfournier requested a review from Tymek August 7, 2024 07:32
src/FlagProvider.tsx Outdated Show resolved Hide resolved
@@ -107,7 +107,7 @@ const FlagProvider: FC<PropsWithChildren<IFlagProvider>> = ({
() => ({
on: ((event, callback, ctx) => client.current.on(event, callback, ctx)) as IFlagContextValue['on'],
off: ((event, callback) => client.current.off(event, callback)) as IFlagContextValue['off'],
updateContext: async (context) => await client.current.updateContext(context),
updateContext: (context) => client.current.updateContext(context),
Copy link

Choose a reason for hiding this comment

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

Suggested change
updateContext: (context) => client.current.updateContext(context),
updateContext: (context) => client.current.updateContext(context),

Choose a reason for hiding this comment

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

Hi @pr28jat I can't spot any difference in this suggestion? Can you try #174 (comment) ?

Copy link
Author

Choose a reason for hiding this comment

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

Hi @gastonfournier , sorry for delay. I've updated it as suggested. Thanks!

Copy link

@gastonfournier gastonfournier Sep 2, 2024

Choose a reason for hiding this comment

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

Thanks! The tests are failing though, I've tried locally and they also fail. Currently, this is not a priority to us because Chrome v50 is really old and doesn't seem to have a huge market share. If you manage to fix the tests in a simple way, we will consider merging this, but we don't want to fix support for an old versions if this risks correctness of our SDK

Copy link
Author

Choose a reason for hiding this comment

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

I see the test-case expects the value to be a promise, which if it's not necessary then I can update the unit test as well.

If you manage to fix the tests in a simple way, we will consider merging this, but we don't want to fix support for an old versions if this risks correctness of our SDK

That's fine for me @gastonfournier , for now I'm using patch-package to modify the code on node_modules upon install.

Choose a reason for hiding this comment

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

I just looked at the test, modified it locally, and all tests go green. I'm curious why the previous behavior was ok... or if it was intentional 2 years ago: iamchanii@5ca3a02#diff-465cbe85eff4124dbbe0c763221ff0ae31086b17e85a53b1dd244397a45da94dR183

In any case both [object Promise] and undefined feel wrong, but I think it doesn't hurt to change that (because everything works and that seems to be an edge case).

So something like this: chenxeed#1 would do it. And then I can probably merge this one

Copy link

Choose a reason for hiding this comment

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

Thanks for the update @gastonfournier , sorry for coming back late.

I've approved your PR. Appreciate for the help!

Choose a reason for hiding this comment

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

Cool, I still don't have permissions to merge it because it's in your repository, would you mind merging it into this PR, I hope that solves the problem 🙏

Copy link
Author

Choose a reason for hiding this comment

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

I'm sorry @gastonfournier I just saw it and just merged it today. Thanks again for the PR!

Copy link

stale bot commented Oct 19, 2024

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Oct 19, 2024
@@ -148,7 +148,7 @@ test('A consumer should be able to get a variant when the client is passed into
'consuming value isEnabled true'
);
expect(screen.getByText(/consuming value updateContext/)).toHaveTextContent(
'consuming value updateContext [object Promise]'
'consuming value updateContext undefined'

Choose a reason for hiding this comment

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

Now the promise is consumed and because setting the context returns no value, this seems correct to me

Copy link
Member

@Tymek Tymek Oct 21, 2024

Choose a reason for hiding this comment

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

It will change the SDK behavior in a subtle way. We have a this binding in client.updateContext. I'm against changing it for the sake of end-of-life browsers.

async syntax is equivalent to

  updateContext: (context) => new Promise(
      (resolve) => (client.current.updateContext(context))?.then(resolve)
  ),

@stale stale bot removed the stale label Oct 21, 2024
Copy link

@gastonfournier gastonfournier left a comment

Choose a reason for hiding this comment

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

@Tymek would you mind sanity checking me?

@@ -148,7 +148,7 @@ test('A consumer should be able to get a variant when the client is passed into
'consuming value isEnabled true'
);
expect(screen.getByText(/consuming value updateContext/)).toHaveTextContent(
'consuming value updateContext [object Promise]'
'consuming value updateContext undefined'
Copy link
Member

@Tymek Tymek Oct 21, 2024

Choose a reason for hiding this comment

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

It will change the SDK behavior in a subtle way. We have a this binding in client.updateContext. I'm against changing it for the sake of end-of-life browsers.

async syntax is equivalent to

  updateContext: (context) => new Promise(
      (resolve) => (client.current.updateContext(context))?.then(resolve)
  ),

Copy link

stale bot commented Nov 22, 2024

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Nov 22, 2024
@stale stale bot closed this Dec 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Unleash NextJS not working on old browser like Chrome v50
4 participants