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

There should be a way to disable sideEffects: false #972

Closed
RReverser opened this issue Feb 11, 2021 · 1 comment · Fixed by #1224
Closed

There should be a way to disable sideEffects: false #972

RReverser opened this issue Feb 11, 2021 · 1 comment · Fixed by #1224

Comments

@RReverser
Copy link
Member

🐛 Bug description

Custom JS snippets can contain top-level side-effects. Right now, wasm-pack generated package.json includes sideEffects: false which marks every file as side-effect free, leading to potential bugs after bundling.

🤔 Expected Behavior

When JS snippet files are generated, they should be put into the sideEffects array, and only the JS file generated by wasm-bindgen should be assumed to be side-effect free since it's the only one wasm-bindgen has control over.

package.json allows to list potentially side-effect-y files as

{
  "sideEffects": [
    "path/to/snippet.js"
  ]
}

This will avoid bugs for snippets with top-level side-effects, while it won't decrease optimization level for common scenarios where the module is used via its main entry point.

@stephanemagnenat
Copy link

stephanemagnenat commented Jan 11, 2023

The problem is indeed significant. Because of side effects are ignored by default, the "main" Rust function annotated with #[wasm_bindgen(start)] is sometimes not called, because the call to wasm.__wbindgen_start(); in index.js is dropped during tree shaking. See #989.

Liamolucko added a commit to Liamolucko/wasm-pack that referenced this issue Feb 5, 2023
This is a less extreme version of rustwasm#1208, which only marks snippets and the main file on the bundler target as having side effects instead of all files.

This means that the shim file which contains the vast majority of the JS code is still properly marked as having no side effects, allowing bundlers to get rid of things like unused `new TextEncoder` calls which could theoretically have side effects but don't.

Fixes rustwasm#972.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants