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

Ensure polyfill works properly with Ember 3.27+ #75

Merged
merged 3 commits into from
May 19, 2021

Conversation

mydea
Copy link
Contributor

@mydea mydea commented May 12, 2021

Based on ef4's comment here: #70 (comment)

This PR changes how the polyfill works by simply rewriting import { cached } from '@glimmer/tracking' to import { cached } from 'ember-cached-decorator-polyfill'.

It uses a simple regex to do so - I added some tests covering all the different import scenarios I could think of (as @glimmer/tracking only has a single other relevant import tracked, it is relatively straightforward).

I hope I didn't miss anything critical 😅 but the tests are passing and it seems to be working just fine.

@mydea mydea changed the title refactor: Use preprocessor for polyfill Use preprocessor for polyfill May 12, 2021
@mydea
Copy link
Contributor Author

mydea commented May 12, 2021

FYI, I have tried this in our medium-sized app with ember-source 3.27 (and TypeScript) and it worked fine!

@ef4
Copy link
Contributor

ef4 commented May 12, 2021

Thanks for working on this.

My concern with this PR is that the regex-based rewriting looks pretty fragile. If @glimmer/tracking adds any new exported names, it's likely to break.

Instead of replacing the existing babel plugin with a regex, I think it would be better to modify the plugin so it does the rewriting of the imported path.

@mydea
Copy link
Contributor Author

mydea commented May 12, 2021

OK, I made a second try, now rewriting the import via the babel AST. I did not cover re-exporting it, but IMHO that seems OK to me. I did not 100% see through how I would make the re-export declaration work, I am not necessarily a babel-AST-pro 😅

Copy link
Member

@rwjblue rwjblue left a comment

Choose a reason for hiding this comment

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

Thanks for picking this up! I left one minor comment (removing that new dependency that we don't need any more), but it should be good to go once that is fixed.

package.json Outdated Show resolved Hide resolved
@mydea mydea requested a review from rwjblue May 19, 2021 05:58
acorncom added a commit to acorncom/cached-decorator-babel-issues-reproduction that referenced this pull request May 19, 2021
@acorncom
Copy link

@mydea just pushed up a simple repro I'd built to test things as part of #77 Ran it against your branch here and it seems to still be failing

@mydea
Copy link
Contributor Author

mydea commented May 19, 2021

True, I can see the same in our app. I will check it out and see if I can make it work..!

@mydea
Copy link
Contributor Author

mydea commented May 19, 2021

I can also reproduce it by updating the addon itself to [email protected] (which at least makes fixing it easier, I guess)

@mydea
Copy link
Contributor Author

mydea commented May 19, 2021

OK, seems from ember-cli-babel 7.23->7.24 the _getEmberModulesAPIPolyfill hook is dropped, leading to the whole babel plugin not running.

Also update addon's ember-cli-babel version to latest
@mydea
Copy link
Contributor Author

mydea commented May 19, 2021

So, I have now refactored it again, it is much nicer now actually :D I am using ember-cli-babel-plugin-helpers to just add the plugin in a regular fashion, without patching anything. I have also updated ember-cli-babel in this addon itself to latest, and the tests are passing fine. Can @acorncom you try it again in the repro?

@acorncom
Copy link

Confirmed that it's no longer crashing in my repro and that the @cache decorator seems to be working smoothly

Copy link
Member

@rwjblue rwjblue left a comment

Choose a reason for hiding this comment

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

This is much better, thank you @mydea!

@rwjblue rwjblue added the bug Something isn't working label May 19, 2021
@rwjblue rwjblue changed the title Use preprocessor for polyfill Ensure polyfill works properly with Ember 3.27+ May 19, 2021
@rwjblue rwjblue merged commit ed8a3e9 into ember-polyfills:main May 19, 2021
@nightire
Copy link

Unfortunately, I am still seeing the error:

Uncaught TypeError: decorator is not a function

I'm pretty sure I had the latest ember-cached-decorator-polyfill installed, and worse is it failed even with [email protected]

image

@mydea
Copy link
Contributor Author

mydea commented May 20, 2021

Unfortunately, I am still seeing the error:

Uncaught TypeError: decorator is not a function

I'm pretty sure I had the latest ember-cached-decorator-polyfill installed, and worse is it failed even with [email protected]

image

Hmm, I just tried it in our app:

[email protected]
[email protected]
[email protected]

And I have tried it with:

[email protected]
[email protected]
[email protected]

Both of these setups worked fine for me.

@nightire
Copy link

Hmm, I just tried it in our app:

[email protected]
[email protected]
[email protected]

And I have tried it with:

[email protected]
[email protected]
[email protected]

Both of these setups worked fine for me.

I have tried these combinations as well but still no luck, I even use resolutions to constraint these versions, and the error still remains. I'm out of options now.😕

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants