-
Notifications
You must be signed in to change notification settings - Fork 137
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
addon owned service with staticAddonTrees breaks DI #1498
Comments
First, a rant: This use case has never been documented as public API and it has no benefit over just doing the normal thing. Doing the unconventional thing here lets you make a one character change over the conventional thing: -@service('ember-scroll-modifiers-observer-manager') observerManager;
+@service('ember-scroll-modifiers@observer-manager') observerManager; Is that really worth being weird? But second, yes, we should try to make it work since that is the whole point of embroider. Absorbing the weirdness so other people don't have to. 😅 Doing the obvious fix for this would make every app a little bigger, even though the vast majority of them do stick to the conventional thing and don't need this behavior. I'd feel better about a fix for this if it was done as a If we did the same thing for service injections we could make |
To be clear, when I say "make every app a little bigger" I'm mostly referring to the cost of the extra registrations. The implementations of the services are already in there for sure right now. Whereas a staticServices flag would actually let services get shaken out when unused and get split along with routes, which is not a thing we have today and would be a potentially large benefit for some apps. |
…ices should always be forced into the build fixes embroider-build#1498
so I'm extra confused now
can you please go into a bit more detail on what is the conventional thing here? from my testing it looks like unless you do you could only use the I'm a bit surprised that if you don't have it re-exported you cannot use @service('service-name') within the addon to access it for the solution are you saying when staticAddonTrees is true also read a new also opened the below pr so we can explore what I'm proposing as the solution I can see right now |
Yes. If you
This is consistent with how everything works in traditional ember. You also cannot invoke your own helpers or components or modifiers if they're not re-exported into the app. It would be weird for this one thing to be package-scoped when nothing else is.
No, I don't really want to complicated Our max compatibility mode already supports this weird use case because I mentioned Another workaround is to use a compat adapter for the offending addon that puts the service into // ember-cli-build.js
const { V1Addon, compatBuild } = require('@embroider/compat')
// ...
compatBuild(app, Webpack, {
compatAdapters: new Map([
['ember-scroll-modifiers', class extends V1Addon {
get packageMeta() {
let meta = super.packageMeta;
meta['implicit-modules'] = [...(meta['implicit-modules'] ?? []), './services/observer-manager.js'];
return meta;
}
}]
])
});
This is correct, I'm saying that staticAddonTrees would keep doing what it does in stage1. The service would not be put into implicit-modules automatically. But in stage3, during babel, when we look at did-intersect.js we would see import "#embroider_compat/services/ember-scroll-modifiers@observer-manager" into that file, which we would handle with a new case here that generates the code necessary to import and |
thanks for the quick feedback,
it feels to me that the best thing to do would be item 3 but also the most work for it |
@mansona strictly speaking this is a bug as seen from a classic build perspective where something used to work and it no longer does |
Uses ember-scroll-modifiers
this relies on a service
https://github.com/elwayman02/ember-scroll-modifiers/blob/master/addon/services/observer-manager.js
which is NOT re-exported but only used in the modifier inside the addon itself
https://github.com/elwayman02/ember-scroll-modifiers/blob/master/addon/modifiers/did-intersect.js#L14
reproduction can be found here
git clone https://github.com/void-mAlex/full_static_flags_reproduction.git
cd full_static_flags_reproduction/static_embroider_v3
pnpm install
pnpm ember serve
will see a js exception in the console and brokewn text on screen
to 'fix'
in
ember-cli-build.js
comment outstaticAddonTrees
andstaticAddonTestSupportTrees
and restart ember server and it will show it workscore of the issue seems to be the mechanism by which DI system works
scroll modifiers exports a
did-intersect
modifier which when used in the host app gets an owner of the host appwhen service injection looks up the requested service from inside the modifier it checks only on the owner where
due to staticAddonTrees we no longer register services from addons (re-exported or otherwise)
short of major enhancement of the DI system I am proposing we allow services to still be registered with staticAddonTrees enabled
any objections @ef4 ?
looking to expand on void-mAlex@ac1d96e
The text was updated successfully, but these errors were encountered: