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

Evaluate code in playground #415

Draft
wants to merge 13 commits into
base: master
Choose a base branch
from

Conversation

tom-sherman
Copy link

Closes #414

  • Create an Eval module that uses a Worker under the hood, it exposes a state machine
  • Figure out some way of bundling the whole of rescript std lib and including it in the worker file
  • Wire it up to the UI

@@ -13,16 +13,16 @@ module Make: (Config: Config) =>
include Config

module App: {
let postMessage: (worker, fromApp) => unit
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without these changes I was getting type errors. I posted about it on the forum: https://forum.rescript-lang.org/t/regarding-src-bindings-worker-res-in-the-rescript-lang-org-repo/2004/2

src/common/Eval.res Outdated Show resolved Hide resolved
@@ -0,0 +1,10 @@
// Required because workers may receive messages intended for other workers eg. react dev tools
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, stuck again. This module seems to be being executed inside of the window and not actually in a worker. Very confused at this point...

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All of the examples I've seen online in Webpack5 and Next.js are passing URL instances to new Worker whereas I am passing url.toString(), changing it to be let make = () => %raw(new Worker(new URL("./EvalWorker.mjs", import.meta.url))) breaks with the following error:

webpack/runtime/compat
The "path" argument must be of type string. Received undefined

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm, where does path come from? weird

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found this issue which seems kinda related but is about dynamic imports inside a worker: vercel/next.js#22581

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That issue is the exact problem and the config workaround does the trick. See my comment here: vercel/next.js#22581 (comment)

Definitely not an ideal solution, I'll look into testing the attached PR and hopefully we can get a patch merged.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, this is definitely fixed with vercel/next.js#26372

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For now I've added a monkey patch in the next config...

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 this pull request may close these issues.

Evaluate code in playground
2 participants