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

Set an environment variable with the JS file that needs to be loaded for workers #604

Open
ranile opened this issue Aug 29, 2023 · 5 comments

Comments

@ranile
Copy link
Contributor

ranile commented Aug 29, 2023

Trunk supports web workers as assets and can generate a loader shim:

<link data-trunk rel="rust" href="Cargo.toml" data-bin="worker" data-type="worker" data-weak-refs data-loader-shim />

When using these workers, it is mandatory to know the path. For example, with gloo-worker:

let mut bridge = MarkdownWorker::spawner().spawn_with_loader("/example_markdown_worker_loader.js");

This can be solved by trunk if an environment variable is set which names the loader file. That would make the loading:

let mut bridge = MarkdownWorker::spawner().spawn_with_loader(env!("WORKER_LOADER"));

The name of the environment variable will be inferred by the asset configuration. It will also be possible to override the environment variable name

@github-actions
Copy link

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

@github-actions github-actions bot added the Stale label Sep 29, 2023
@github-actions
Copy link

github-actions bot commented Oct 4, 2023

This issue was closed because it has been stalled for 5 days with no activity.

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Oct 4, 2023
@ranile
Copy link
Contributor Author

ranile commented Oct 4, 2023

Can this be reopened?

@ctron
Copy link
Collaborator

ctron commented Dec 7, 2023

@github-actions github-actions bot removed the Stale label Dec 8, 2023
@ctron
Copy link
Collaborator

ctron commented Dec 18, 2023

I've started to take a look at this. Here's a thing:

  • The env-var value (and name) is required during the compilation of the wasm code
  • If the env-var value should be hashed (see Web worker cache invalidation #405) it's hash value would need to be known upfront

This would mean two things: a) it cannot be processes in parallel (which it might likely can't anyway because of cargo build locks) and b) there must be an order of imports (worker first, then main), which might get tricky and problematic if there's a circular dependency situation (not sure that worth supporting).

We would resolve this by having fixed shim names, and then fetching with no-cache, as suggested here: #405 (comment)

That would of course mean that shim loaders would because a requirement for solving #405.

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

No branches or pull requests

2 participants