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

setComponentTemplate is run twice on decorated classes #16

Closed
davidtaylorhq opened this issue Jan 16, 2024 · 1 comment
Closed

setComponentTemplate is run twice on decorated classes #16

davidtaylorhq opened this issue Jan 16, 2024 · 1 comment

Comments

@davidtaylorhq
Copy link
Contributor

davidtaylorhq commented Jan 16, 2024

Given an Ember component definition like this:

// components/my-component.js

import Component from '@glimmer/component';

const myDecorator = (klass) => klass;

@myDecorator
export default class MyComponent extends Component {}

and a colocated template:

{{! components/my-component.hbs }}
Hello world

The transpiled output looks something like this:

const myDecorator = klass=>klass;
const MyComponent = dt7948.c(class MyComponent extends _glimmer_component__WEBPACK_IMPORTED_MODULE_0__["default"] {
}
, [myDecorator]);
/* harmony default export */
const __WEBPACK_DEFAULT_EXPORT__ = ((0,
_ember_component__WEBPACK_IMPORTED_MODULE_2__.setComponentTemplate)(_my_component_hbs__WEBPACK_IMPORTED_MODULE_1__["default"], MyComponent));
(0,
_ember_component__WEBPACK_IMPORTED_MODULE_2__.setComponentTemplate)(_my_component_hbs__WEBPACK_IMPORTED_MODULE_1__["default"], MyComponent);

Note the duplicate calls to setComponentTemplate. This causes a runtime error

Uncaught Error: Cannot call `setComponentTemplate` multiple times on the same class (`MyComponent`)

Minimal reproduction here: davidtaylorhq/decorator-transform-test@d01d5c4

Potential fix here: #18

ef4 added a commit that referenced this issue Jan 16, 2024
This test demonstrates the failure from #16

I think the fix will go in `@embroider/shared-internals` but once it does this will tell us if we got it right.
ef4 added a commit that referenced this issue Jan 16, 2024
This test demonstrates the failure from #16

I think the fix will go in `@embroider/shared-internals` but once it does this will tell us if we got it right.
ef4 added a commit to embroider-build/embroider that referenced this issue Jan 16, 2024
It's not possible to have more than one colocated template for a given JS file, so we never need to run again.

Fixes ef4/decorator-transforms#16
@ef4
Copy link
Owner

ef4 commented Oct 31, 2024

I think this is fixed via embroider-build/embroider#1758

@ef4 ef4 closed this as completed Oct 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants