-
Notifications
You must be signed in to change notification settings - Fork 40
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
Prevent tree-shaking of side-effect imports of @u-elements/*
#2477
Comments
@u-elements/*
@u-elements/*
@u-elements/*
@u-elements/*
@u-elements/*
Hi! I could alter the I can see though that Adobe adds their own sideEffects definition in each package - I'll test generating this in It is a possibility to add a random export |
fixed by correctly marking dependencies as external Closes #2477
fixed by correctly marking dependencies as external Closes #2477
fixed by correctly marking dependencies as external Closes #2477
We got it working the first time with changing it to a having a "define" function. Isn't this is something that affects everyone using the When testing, we first got it working with editing the source code as such downstream: …
// In u-details.js
function define () {
customElements.define("u-details", UHTMLDetailsElement);
customElements.define("u-summary", UHTMLSummaryElement);
}
export { UHTMLDetailsElement, UHTMLSummaryElement, define };
// In AccordionItem
import { define } from '@u-elements/u-details'
define(); |
Turns out not to be a |
This statement is not correct 😅 just because we didn't bundle it with our package doesn't mean thats wrong. Both options are valid in the package making world, with each of its pros and cons. |
I disagree here. I have never seen a modern npm package that bundles its dependencies. Moreover, if you choose to do that, you take the responsibility of correctly marking your side-effects. By saying |
I also disagree - I have seen |
By the way, if we had chosen to keep bundling u-elements, this setting in "sideEffects": [
"**/@u-elements/**"
], As I said, the burden would be on us to do this if we chose to bundle it. |
fixed by correctly marking dependencies as external Closes #2477
Now I am confused 😅 I agree, its the best and modern approach, we shouldn't bundle dependencies with our package, which is what we are trying to achieve now with #2479? My point was that its also valid to bundle dependencies with your package if needed, although less ideal because it can cause unwanted sideffects. I know its what we were doing currently, but it was just a fault with bundling being configured wrong in our rollup. |
yeah,
but seems we all agree on the approach where we do not bundle dependencies 😊 |
…haking We incorrectly caused `import "@u-elements/u-details"` to be tree-shaked when `@digdir/designsystemet-react` was used in an application with tree- shaking enabled. This happened because we bundled several dependencies (including this one) with our library, and our library has `"sideEffects": false`, implying that any side-effect imports that happened within our library folder was safe to remove. This was fixed by correctly marking all our dependencies as external, in which case the application's build will correctly identify `"@u-elements/u-details"`` as having side-effects and thus not remove the import. Closes #2477
This ensures Accordion works when consumers have enabled tree-shaking. Because we didn't mark all our dependencies as external, `import "@u-elements/u-details"` was tree-shaked when `@digdir/designsystemet-react` was used in an application with tree-shaking enabled. This happened because we bundled several dependencies (including this one) with our library, and our library has `"sideEffects": false`, implying that any side-effect imports that happened within our library folder was safe to remove. This was fixed by correctly marking all our dependencies as external, in which case the application's build will correctly identify `"@u-elements/u-details"` as having side-effects and thus not not remove the import. Closes #2477
This ensures Accordion works when consumers have enabled tree-shaking. Because we didn't mark all our dependencies as external, `import "@u-elements/u-details"` was tree-shaked when `@digdir/designsystemet-react` was used in an application with tree-shaking enabled. This happened because we bundled several dependencies (including this one) with our library, and our library has `"sideEffects": false`, implying that any side-effect imports that happened within our library folder was safe to remove. This was fixed by correctly marking all our dependencies as external, in which case the application's build will correctly identify `"@u-elements/u-details"` as having side-effects and thus not not remove the import. Closes #2477
packages/react/src/components/Accordion/AccordionItem.tsx
has the importThis is preseved when we build the library:
However, when a consumer uses
@digdir/designsystemet-react
, the lineis tree-shaked away since we define in
"sideEffects": false
in our package.json.We need a way to prevent this from happening.
The text was updated successfully, but these errors were encountered: