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

🚀 Feature Request: Allow unsafe eval to run code in a separate I/O context #3218

Closed
dario-piotrowicz opened this issue Dec 6, 2024 · 4 comments
Assignees
Labels
feature request Request for Workers team to add a feature

Comments

@dario-piotrowicz
Copy link
Member

In our Vite plugin, during development instead of normally importing modules, we use workerd's unsafe eval to evaluate and run their code.

This is so that we can integrate with the Vite Environment API and correctly integrate with Vite's dev modules handling (Vite doesn't work with real ESModules and has it's own custom modules structure, with that they can have more control over them, allow modules invalidations, etc...)

The issue here is that there might be differences between the evaluation of anonymous functions and actual ESModules importing, in particular we know that I/O operations can't be performed on the top level of a dynamically imported modules inside workerd.

This is problematic because this means that we end up with diverging behaviors during dev and production.

I am opening this issue to see if we could have some sort of API or any way to get unsafe eval to actually run code in the same manner as code run in imported modules, allowing us to cleanly reproduce the production during development as well.

For more context: flarelabs-net/vite-plugin-cloudflare#83 (comment)

@jasnell
Copy link
Member

jasnell commented Dec 6, 2024

Not "separate I/O context" but "no I/O context". The idea is that we do not want anything running in the unsafe eval to be able to schedule i/o.

@jasnell jasnell added the feature request Request for Workers team to add a feature label Dec 6, 2024
@jasnell jasnell self-assigned this Dec 6, 2024
@dario-piotrowicz
Copy link
Member Author

Not "separate I/O context" but "no I/O context". The idea is that we do not want anything running in the unsafe eval to be able to schedule i/o.

ah yes, thanks for the correction 🙂

@dario-piotrowicz
Copy link
Member Author

dario-piotrowicz commented Dec 10, 2024

PS: We had some further discussion about this and preventing I/O operations in unstafe evaled code could actually not even work for us as we do rely on some global state anyways 😕 (for context: flarelabs-net/vite-plugin-cloudflare#83 (comment))

So this might actually not be a valid/valuable idea at all 😕

@dario-piotrowicz
Copy link
Member Author

Closing this issue since, as we discussed in flarelabs-net/vite-plugin-cloudflare#83 (flarelabs-net/vite-plugin-cloudflare#83 (comment)) what I proposed here is something that wouldn't even really work for us, thanks and sorry for the inconvenience James 🙏

@dario-piotrowicz dario-piotrowicz closed this as not planned Won't fix, can't repro, duplicate, stale Dec 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request Request for Workers team to add a feature
Projects
None yet
Development

No branches or pull requests

2 participants