-
Notifications
You must be signed in to change notification settings - Fork 147
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
fix: clearTimeout
illegal invocation with bundler (#187)
#283
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interestingly, the current timer implementation (in master) does not seem to work with wasm-pack test --node
either when I tried it. Maybe this will also fix it?
CI should turn green when if you rebase from the master branch.
FYI, ran into this with https://github.com/paritytech/jsonrpsee. What weird is, current version (gloo-timers 0.2.5) only works in tests, not in real cases. In wasm-pack test --chrome it works (when I open the browser to run tests). But if the it is compiled to wasm (with wasm-pack) and required by JavaScript, there's an illegal invocation error. |
@futursolo good catch. It turns out the return type is different between browser ( |
@DogLooksGood @futursolo I take a deep look at
It's a clearly true And
while So, it's a bad side-effect introduced by bundler. The currently
I think we can hack the binding further into
which generates
|
refer rustwasm#283 (comment) for background
clearTimeout
illegal invocation in browser (#187)clearTimeout
illegal invocation with bundler (#187)
@flisky I just tried with your master version, the issue hasn't solved in my case. The generated code is still
|
@DogLooksGood, could you please double check? Make sure that:
|
@futursolo, could you please take another review? There're two binding changes:
I don't know how to run the same testcases in nodejs & browser with |
The implementation looks good to me. I will approve this once I hear back from @DogLooksGood.
You can apply a feature flag to // It might be better to use not(node_tests) than browser_tests because most existing tests are browser tests.
#[cfg(not(feature = "node_tests"))]
wasm_bindgen_test_configure!(run_in_browser); // Runs browser tests
wasm-pack test --firefox
// Runs node tests
wasm-pack test --features=node_tests --node In addition, would you mind to also update GitHub Actions to run node tests? |
@futursolo @flisky Sorry, it's my fault. It works. |
@futursolo the current CI is heavily based on
|
Whilst I think it's still possible to combine tests with a compiler flag, I am fine with merging this pull request as-is. We can merge the tests together in the future. |
Released in gloo-timers 0.2.6 🎉 |
Add support different WASM environments (such as workers, NodeJS) that don't have a `window` global by binding to the global `setInterval` and `clearInterval` functions directly. This uses the same approach as used by gloo-timers implemented in [rustwasm/gloo#185](rustwasm/gloo#185) and [rustwasm/gloo#283](rustwasm/gloo#283) given the `web-sys` lack of interes to support this (see discussion in [this issue](rustwasm/wasm-bindgen#1046)). Co-authored-by: sisou <hello@soerenschwert.de>
Add support different WASM environments (such as workers, NodeJS) that don't have a `window` global. This is done by binding to the global `setInterval` and `clearInterval` functions directly. This uses the same approach used by gloo-timers implemented in [rustwasm/gloo#185](rustwasm/gloo#185) and [rustwasm/gloo#283](rustwasm/gloo#283) given the `web-sys` lack of interes to support this (see discussion in [this issue](rustwasm/wasm-bindgen#1046)). Co-authored-by: sisou <hello@soerenschwert.de>
It's a regression from #96 introduced by #185, and I have no idea why callingclearTimeout
is failed in browser, but my patch definitely resolves the error.It's a side effect introduced by bundler, and we workaround it. more details in #283 (comment)