-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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 doesn't refresh after file changes #20104
Comments
This seems to work in the browser index.html <script type="module">
export let worker = new Worker(new URL("./worker.js", import.meta.url), {
type: "module",
});
const button = document.createElement("button")
button.onclick = updateWorker
button.textContent = "update"
document.body.appendChild(button)
export function updateWorker() {
console.log(worker)
worker = new Worker(new URL("./worker.js", import.meta.url), {
type: "module",
});
}
</script> worker.js // worker.js
const now = Date.now();
const number = 33;
console.log(now, number); updating worker.js then clicking the button correctly reflects the new change |
I'm somewhat surprised this works in the browser. The reason that it doesn't work as you expect is that Deno will have the file after it's fetched initially and it won't be fetched again until the process restarts. You can "cache bust" by appending a querystring to the URL that will force Deno to treat it as different module: new Worker(new URL(`./worker.js?cachebust=${Date.now()}`, import.meta.url), { type: 'module' }); |
@bartlomieju thanks for the reply. Unfortunately, cache busting doesn't fix the problem because not only the For example, I have the following module: // mod.js
export const now = Date.now();
export const number = 33; And the woker.js file import it to log the numbers // worker.js
import { now, number } from "./mod.js";
console.log(now, number); The result is the same:
The number never changes, but the Date does. I guess Deno only cache the file content, not the values exported by the module that are re-evaluated again in the Worker. My use case is to create a way to safely refresh the build (from Lume) after any change in a JS/TS file. Something like the Deno's AFAIK, Workers are the only way in JavaScript to run code in separated threads, completely independent to the main script and other Workers. So I think they shouldn't share the same file cache. |
I just realized that this bug was fixed in #23634 , so I'm closing this. |
Hi. I have the following code:
In a different file, this is the code to run it using workers. There's a watcher to detect changes in the
worker.js
file and reload the worker to reflect these changes:After running the code, if I change something in the
worker.js
file, the new Worker is created but the file content is freezed, so it always logs the current date and the same number, even if it was changed:I think this is an unfortunate behavior (probably a bug?)
The text was updated successfully, but these errors were encountered: