Let’s say I’m using a Glimmer component from an addon that’s initialized like this: <PowerSelect .../>. This addon is using a co-located template named components/power-select/trigger.hbs. I want to override this template (use custom html).
Previously when the template wasn’t co-located, I could just override the template by creating a file app/templates/components/power-select/trigger.hbs. I’ve tried the same here (app/components/power-select/trigger.hbs), but that’s failing with Uncaught (in promise) TypeError: can't redefine non-configurable property "default". I think that because creating that file, I’m creating a template-only component, instead of augmenting the addon’s component.
How would I go about replacing an addon’s template?
Yeah I should have looked in the actual addon first, should be
export { default } from 'ember-power-select/components/power-select/trigger';
Basically you just want to match the re-export that’s already in the addon. I’m not 100% sure this will even work but if the problem is that Ember thinks you’re overriding the power select trigger with a template only component this seems like the easiest way to get it to use the class for the addon version and the template for yours
One caveat here is that each component JavaScript file should export a value that is unique to that file. For example, this should be avoided :
// app/components/foo-bar.js
import MyParentComponent from "./my-parent";
// BAD: don't do this!
export default MyParentComponent;
This is problematic because setComponentTemplate will be called on MyParentComponent directly, affecting the parent component and all of its descendants. This can be avoided by subclassing, even when no customization is required:
// app/components/foo-bar.js
import MyParentComponent from "./my-parent";
// GOOD: do this instead!
export default class extends MyParentComponent {}
With that in mind, I’ve changed my code to read like this:
import Trigger from 'ember-power-select/components/power-select/trigger';
export default class extends Trigger { }
And now my custom template is being used!
As a separate issue I cannot seem to find the magical incantation to get TypeScript to allow the import. TypeScript insists on adding /addon/, which fails run time. This might be due to the following caveat listed in ember-cli-typescript:
Similarly, apps must use .js to override addon defaults in app , since the different file extension means apps no long consistently “win” over addon versions (a limitation of how Babel + app merging interact).