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

macroCondition macros aren't removed from templates during the build phase #1694

Closed
mike-engel opened this issue Dec 1, 2023 · 1 comment

Comments

@mike-engel
Copy link
Contributor

While working on enabling staticHelpers and staticComponents in our own app, we ran into trouble with ember-animated (ember-animation/ember-animated#594). The solution should be to move the macro into the template so that it can be pruned at build time.

{{#if (macroCondition (macroDependencySatisfies 'ember-element-helper' '>= 0.6.1'))}}
  {{! use the new element helper }}
{{else}}
  {{! use the old -element helper }}
{{/if}}

I put together a PR which does exactly that, but as you can see (as of this writing) the tests fail because macroCondition and macroDependencySatisfies aren't defined at runtime, which they shouldn't be.

stack: >
            Error: Attempted to resolve `macroCondition`, which was expected to be a helper, but nothing was found.
                at resolveHelper (http://localhost:4202/assets/vendor.js:28257:15)
                at encodeOp (http://localhost:4202/assets/vendor.js:30101:18)
                at pushOp (http://localhost:4202/assets/vendor.js:30036:7)
                at http://localhost:4202/assets/vendor.js:28458:7
                at Compilers.compile (http://localhost:4202/assets/vendor.js:28443:7)
                at expr (http://localhost:4202/assets/vendor.js:28601:19)
                at http://localhost:4202/assets/vendor.js:29882:5
                at Replayable (http://localhost:4202/assets/vendor.js:29067:17)
                at ReplayableIf (http://localhost:4202/assets/vendor.js:29124:12)
                at http://localhost:4202/assets/vendor.js:29881:52
        message: >
            global failure: Error: Attempted to resolve `macroCondition`, which was expected to be a helper, but nothing was found.
        negative: >
            false
        browser log: |
            {"type":"error","text":"\n\nError occurred:\n\n- While rendering:\n  -top-level\n    application\n      index\n        transition-log-table\n          logged-sprites\n            animated-container\n\n"}
            {"type":"error","text":"\n\nError occurred:\n\n\n\n"}
            {"type":"warn","text":"Attempted to rerender, but the Ember application has had an unrecoverable error occur during render. You should reload the application after fixing the cause of the error."}

I began to research this, but ran out of time. During my research, it seems like the glimmer AST transformations aren't running on precompiled v2 addon templates. You can see this in the test app within the ember-animated addon. If you run the tests, or run the server and navigate to /demos/container-only, you'll see the error get thrown.

Hacking around in node_modules, the AST transforms are running on the test-app templates, but not for the addon templates it seems. This would seem to stem from the combo of classic builds + v2 addon precompiled templates, but I don't have the knowledge and didn't get enough time to make the connection between the two.

@mike-engel
Copy link
Contributor Author

Should be fixed with #1688 now 🎉

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

No branches or pull requests

1 participant