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

Worker.js outputted in wrong location for web_worker_fib demo project #3030

Closed
1 of 3 tasks
kaisalmon opened this issue Dec 11, 2022 · 8 comments · Fixed by #3057
Closed
1 of 3 tasks

Worker.js outputted in wrong location for web_worker_fib demo project #3030

kaisalmon opened this issue Dec 11, 2022 · 8 comments · Fixed by #3057
Labels

Comments

@kaisalmon
Copy link
Contributor

Problem
The example project showing how to use web workers does not seem to function, as the worker.js file is not outputted in the correct location. It looks like it's being outputted to https://examples.yew.rs/web_worker_fib/worker.js, but the client is trying to load it from https://examples.yew.rs/worker.js

Steps To Reproduce
Steps to reproduce the behavior:

  1. Go to the webworker yew demo
  2. Open dev tools and open the networking tab
  3. Notice the worker.js has failed to load. (And, by extension ,the demo does not work)

(bonus step 4). Go to /web_worker_fib/worker.js and admire the code that was built.

Expected behavior
The file should have been loaded as a webworker and the location it was built to and the location it was attempted to be loaded from should be the same

Screenshots
image

Environment:

  • Browser and version, if relevant: Google Chrome Version 108.0.5359.99 (Official Build) (64-bit)

Questionnaire

  • I'm interested in fixing this myself but don't know where to start
  • I would like to fix and I have a solution
  • I don't have time to fix this right now, but maybe later
@kaisalmon kaisalmon added the bug label Dec 11, 2022
@kaisalmon
Copy link
Contributor Author

kaisalmon commented Dec 11, 2022

I ran into this issue when I was investigating why my own project was not outputting any worker.js file at all.

EDIT: Whatever my local issue is will be unrelated to this demo bug, but I'm sure I won't be the first person who tries to use this demo to help debug their own projects!

@SpanishPear
Copy link
Contributor

SpanishPear commented Dec 11, 2022

Does this work when you clone the repo and run it manually? Having run into this before, it may be that however the hosted example is built, it is not built with correct "public url" semantics, allowing it to be hosted at a subpath.

EDIT: It works for me locally, so is hopefully public url semantics.

@WorldSEnder
Copy link
Member

WorldSEnder commented Dec 11, 2022

I think the worker.js is treated as an URL relative to the root path, instead of relative to the example's base path (as would be specified by the baseUrl set in our build script)

@hamza1311
Copy link
Member

I ran into this issue when I was investigating why my own project was not outputting any worker.js file at all

You need to register the worker in the index.html for trunk to compile it. I'm guessing that you missed this step, as I can't think of any other reason why the worker won't be built.

The issue you ran into is different from the issue with example. The example fails because the root path is not / so unless you were also trying to run your application, at a path other than /, you wouldn't run into it

@kaisalmon
Copy link
Contributor Author

kaisalmon commented Dec 12, 2022

@hamza1311 I'm aware my own issue is unrelated, I should have made that clearer. I was just giving some context to what lead me (and future people in my situation) to check this example.

...I was also fishing for someone to help me out with my own issue which didn't have enough details to ask for help properly! Which you did, and I really appreciate!

@vpochapuis
Copy link

vpochapuis commented Dec 14, 2022

Hello!
I am having a similar issue when using webworkers.

I registered it using

<link data-trunk rel="rust" href="../Cargo.toml" data-bin="app" data-type="main" />
<link data-trunk rel="rust" href="../Cargo.toml" data-bin="worker" data-type="worker" />

I have made the bin/worker.rs accordingly, with the call to gloo_worker::worker::private::register while importing yew_agent::PrivateWorker;

My Trunk.toml has the public_url correctly set to /app/ which is my SPA end point.

However I get this error when loading the page:

Loading script from “https://localhost/main.js” with importScripts() was blocked because of a disallowed MIME type (“text/html”).

The rest of the SPA is loading correctly.

I am quite new to this, so I don't really have any idea of why this is happening. Hopefully we could improve the Yew-Agent documentation afterwards.

EDIT:

I just saw the file name is main.js and not worker.js, most likely a different issue, sorry. most likely related to #2999

EDIT:

Issue was that I didnt implement the

 fn name_of_resource() -> &'static str

of the Worker Trait .

Also, just putting

 fn name_of_resource() -> &'static str {
       "worker.js"
 }

Doesnt work as it isnt taking in account the public_url from the Trunk.toml and I had to hardcode

 fn name_of_resource() -> &'static str {
       "/app/worker.js"
 }

@SpanishPear
Copy link
Contributor

@vpochapuis you may want https://docs.rs/yew-agent/0.1.0/yew_agent/trait.Agent.html#method.resource_path_is_relative if your worker is not at the root as well - I remember having to do that for a previous project

@kaisalmon
Copy link
Contributor Author

@SpanishPear I'm fairly sure that's what's wrong with the demo as well. PR in coming

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
5 participants