-
Notifications
You must be signed in to change notification settings - Fork 36
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
[RDKit_minimal.js]: Assign initRDKitModule
to WorkerGlobalScope if possible
#326
Comments
Hi @xuzuodong, just by curiosity, have you tried writing: import initRDKitModule from "./RDKit_minimal.js"; In other runtime like node.js, importing like above actually assigns initRDKitModule to globalThis, so I would guess it would be the same in a worker context. I must confess I have limited experience with web workers however, @atfera and @RamziWeslati seem to have use this in their rdkit-provider implementation , maybe they would have some thoughts on your issue here? |
@MichelML I tried this and won't work. It turns out that if we want to use an outside function in an ES module web worker , we should either:
I think the second way would be better, because before implementing either way, we should first determine if user's runtime environment supports ESM, and it seems strenuous to do so in the first way. |
I just created a demo, with Vite correctly handles the module worker. A drawback is that So this only works on development mode; on build time, As a workaround, I used vite-plugin-static-copy to copy However, it's just not worthy to do so, since it brings more complexity to user's codebase than it trying to reduce. It should be perfectly fixed if So I guess now the true problem is that is it possible for RDKit.js distribute as an ES Module Build? If not, do you guys have plans to support it? If not, maybe this issue can be closed for now. 😃 |
@xuzuodong sorry it took so long to answer here, @ptosco would you have any thoughts/comments on his last question? |
repoke @atfera @RamziWeslati here too |
@xuzuodong I will have a look at this myself real soon, sorry for the delays |
Thank you so much for your continued attention to my issue! 🫶 I want to let you know that |
Is your feature request related to a problem? Please describe.
We can only use
RDKit.js
inside a web worker in a legacy way:While there is a preferred way to use web worker: use
module
type:In this way, we can't use
importScripts
anymore since nowworker.js
file is considered a module, and an error would occur:So, I instead we should use
import
:Now here's the problem: I can't access the
initRDKitModule
function anymore since it didn't assigned toWorkerGlobalScope
, so we can't directly do something like below, which I think would be an ideal way to use RDKit.js:Describe the solution you'd like
initRDKitModule
function should be assigned toWorkerGlobalScope
inRDKit_minimal.js
.I tried and it seems to work by just adding these lines at the end of
RDKit_minimal.js
:I think it should be added directly in the source code before JavaScript code generation, I don't know how to do it since it's written in c++.
Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.
Additional context
Add any other context or screenshots about the feature request here.
The text was updated successfully, but these errors were encountered: