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

GH-38936: [JS] initialize overrides for DOM and Node in IIFE #39472

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

domoritz
Copy link
Member

@domoritz domoritz commented Jan 5, 2024

@domoritz domoritz requested a review from trxcllnt as a code owner January 5, 2024 14:23
Copy link

github-actions bot commented Jan 5, 2024

⚠️ GitHub issue #38936 has been automatically assigned in GitHub to PR creator.

@domoritz
Copy link
Member Author

domoritz commented Jan 5, 2024

@nrabinowitz can you test this change? If we get it in my Monday, it will be in the next release.

@trxcllnt
Copy link
Contributor

trxcllnt commented Jan 5, 2024

@domoritz I think the IIFE here works because it's initializing a static property on the class, so bundlers can't throw away the side effects. I think we'd have to do something similar here.

@domoritz
Copy link
Member Author

domoritz commented Jan 5, 2024

I see. The issue with my code is that the method might still be thrown away?

@trxcllnt
Copy link
Contributor

trxcllnt commented Jan 5, 2024

@domoritz yes, I believe so. I'm not sure if there's a clean way to do this...

@trxcllnt
Copy link
Contributor

trxcllnt commented Jan 5, 2024

What impact would setting sideEffects: true have?

@domoritz
Copy link
Member Author

domoritz commented Jan 6, 2024

My understanding is that it makes tree shaking much less effective but we should check to see the impact. Or is there some way to remove the side effect for example by extending the builder and batch reader base classes with the node and dom specific methods and then exporting an extended class?

@trxcllnt
Copy link
Contributor

trxcllnt commented Jan 8, 2024

extending the builder and batch reader base classes with the node and dom specific methods and then exporting an extended class

The internal factory functions that create builders will be creating instances of the non-extended class, but we could definitely use this strategy as a way to patch the prototypes w/ the static-property-initialized-by-an-IIFE style that defeats tree-shaking.

@nrabinowitz
Copy link

@nrabinowitz can you test this change? If we get it in my Monday, it will be in the next release.

Sorry I missed this until now. Based on the discussion here, do you still want me to test this fix as it stands or should I wait for another approach?

FWIW, my current workaround is to use a Webpack override to specify sideEffects: true. This works, but I agree with the assessment that tree-shaking will not be as effective (and may not be used at all).

@domoritz
Copy link
Member Author

domoritz commented Jan 9, 2024

Based on the discussion here, do you still want me to test this fix as it stands or should I wait for another approach?

I'm curious whether it works or not.

The internal factory functions that create builders will be creating instances of the non-extended class, but we could definitely use this strategy as a way to patch the prototypes w/ the static-property-initialized-by-an-IIFE style that defeats tree-shaking.

How could that work? If someone imports only makeBuilder or builderThroughIterable for example, they might not import Builder and so we wouldn't execute the

@domoritz domoritz marked this pull request as draft January 20, 2024 01:20
@domoritz domoritz removed the awaiting committer review Awaiting committer review label Mar 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[JS] The package.json file incorrectly specifies sideEffects: false
3 participants