-
Notifications
You must be signed in to change notification settings - Fork 51
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
RFC: Side-effect free addon registries #439
Comments
This makes really good sense to me—I have independently landed on the option of explicitly doing an interface merge like this which uses the In terms of the open questions, I like having it be
I believe that allows people to switch over incrementally; merging the same interface twice is totally legal (playground). So the consumer's migration path would be:
(Also, there are definitely some addons doing this, but if we do this change quickly, there aren't that many—as you say, mostly internal!) |
Merging a compatible type to the same interface twice is legal, but merging two incompatible types under the same field on the interface isn't. If you've got a local override for something in an addon, reusing |
I didn't run yet into the issues you described here myself, but the proposed change totally make sense for me, so I approve! 👍
Same.
Also, besides type conflicts, if you have imported the module with the registry side effect, you wouldn't be able to remove entries from it, right? Basically this use case Dan mentioned above would be impossible AFAIK:
FWIW, I have two addons (ember-stargate and ember-responsive-image) published with Glint support as it was designed before. In anticipation of things still being volatile, I explicitly called out that Glint support to be experimental and not covered by Semver (e.g. here. So I wouldn't really mind if this was a breaking change tbh. I have exactly one app where I have consumed these types myself, which is easy to fix, and I would be surprised if this was already used by a lot of other users, if by any at all. 🤷 |
That's a good callout—I think every public addon I've seen so far with Glint support has gone that route. Since that's the case, and this is an easy break for consumers to absorb, I'm on board with sticking with |
I'm definitely in favor of this! I'd like to vote for IMHO this reads better: // import CoolAddon's template registry
import CoolAddonRegistry from 'cool-addon/template-registry';
declare module '@glint/environment-ember-loose/registry' {
// merge it into Glint's registry
export default interface Registry extends CoolAddonRegistry {}
} I also like the aforementioned advantages:
But like others have said, those alone probably aren't enough to justify a new file. I just think, conceptually, we should have a new file that accurately describes what's in it (which now won't necessarily be specific Glint). |
I can relate to James' arguments here, seems reasonable! |
Good points on the issues with Given that take, and summarizing @dfreeman's original proposal with that specific direction, we would end up with:
This seems… pretty good! |
👍 Sounds good to me! All of this has only ever been convention, so we won't need to change anything about how Glint functions, "just" update the documentation and announce the change/encourage folks to migrate. |
Update addon docs with the outcome of #439
I'd like to explore a slight tweak to the conventions we prescribe for addons to contribute entries to the global template registry in loose-mode environments.
Current Design
In #303 and #313, several folks (with @simonihmig leading the charge!) put together an initial proposal for how addons should contribute to the template registry. That pattern has largely worked well, and has enabled addons to start shipping with Glint-native support (including a number of our internal packages at Salsify!)
At a high level, addons expose an
$addon-name/glint
module that, when imported, adds all their template entities to the global registry.By providing this module at a dedicated import path, consumers can easily do a side-effect import of that module to automatically add all the addon's template entities to the registry:
This design also still gives consumers the option to instead import and add entries individually if it has its own local overrides or only wants to allow usage of a subset of an addon's template entities:
Shortcomings
After about six months of real-world usage and battle testing, and as we start looking toward a 1.0 release, I'd like to propose one change to this convention. The place users have run into trouble is that adding the
declare module
statement implicitly makes the addon aware of@glint/environment-ember-loose
and adds a required point of coordination between the addon and its host.For that declaration to work, the addon must be able to "see" the host's copy of
@glint/environment-ember-loose
, which might not be the case if:If any of those situations occur, the addon's entries won't be visible to the host in its own copy of the registry. In practice a number of folks have run into this and needed help debugging in Discord or here in the issue tracker.
Proposed Change
Rather than including a
declare module
statement themselves, addons could instead construct their own registry type representing the template entities they expose.Consumers would then import that registry and extend the
environment-ember-loose
declaration ofRegistry
to include those entries:You can see the rough shape of this in practice in this TS playground.
There are a few potential advantages to this convention (some more immediate and some more hypothetical):
@glint/environment-ember-loose
, resolution issues are no longer a problem@ember/glint-environment
in the future, only the app's registry setup needs to change; addons will work without needing to be updatesOpen Questions
import { CoolAddonRegistry } from 'cool-addon';
?import { TemplateRegistry as CoolAddonRegistry } from 'cool-addon';
? (maybe this isinject
all over again)import CoolAddonRegistry from 'cool-addon/template-registry';
?import CoolAddonRegistry from 'cool-addon/glint';
?$addon-name/glint
?$addon-name/glint
as the registry import path, then just keeping/glint
around but deprecated seems like it should provide consumers with a reasonable path forward.Thoughts from anyone who's worked with Glint in addons are welcome, but in particular I expect this is of interest to @chriskrycho @jamescdavis @simonihmig @NullVoxPopuli
The text was updated successfully, but these errors were encountered: