Skip to content

feat: searched params attached to workers are now preserved - #22280

Merged
sapphi-red merged 6 commits into
vitejs:mainfrom
jurerotar:feat/worker-search-params
Aug 21, 2026
Merged

feat: searched params attached to workers are now preserved#22280
sapphi-red merged 6 commits into
vitejs:mainfrom
jurerotar:feat/worker-search-params

Conversation

@jurerotar

@jurerotar jurerotar commented Apr 21, 2026

Copy link
Copy Markdown
Contributor

This PR adds support for preserving search params passed to workers. This means that user-provided search params are now appended next to vite-generated ones.

The reason we need this functionality is because we currently have a blocker in sqlite-wasm repository related to this. The short version is that certain database features rely on passing search params to workers on initialization. These search params are currently stripped.

You can find a more in-depth explanation of the issue we're attempting to resolve in this comment.

@sapphi-red sapphi-red added the p2-to-be-discussed Enhancement under consideration (priority) label Apr 23, 2026
@sapphi-red

Copy link
Copy Markdown
Member
switch(vfsName){
  case 'opfs':
    return new Worker(new URL("sqlite3-opfs-async-proxy.js?vfs=opfs", import.meta.url));
  case 'opfs-wl':
    return new Worker(new URL("sqlite3-opfs-async-proxy.js?vfs=opfs-wl", import.meta.url));
}

To confirm, is this what you have in the source code? Is the expected build output to be like the following?

switch(vfsName){
  case 'opfs':
    return new Worker(new URL("path-to-sqlite-worker.js?vfs=opfs", import.meta.url));
  case 'opfs-wl':
    return new Worker(new URL("path-to-sqlite-worker.js?vfs=opfs-wl", import.meta.url));
}

@jurerotar

Copy link
Copy Markdown
Contributor Author

To confirm, is this what you have in the source code? Is the expected build output to be like the following?

Correct! The worker internally relies on vfs search param being passed to it. Because it was getting stripped during bundling, our tests failed.

Since this PR was raised, we have managed to find a workaround. It currently works like this:

const url = new URL('sqlite3-opfs-async-proxy.js', import.meta.url);
url.searchParams.set('vfs', vfsName);
return new Worker(url.toString());

vfs param is now correctly preserved. I am not sure if this is the intended way of passing search params to workers, but if it is, I'd be happy to document this in the docs instead 😄

@github-project-automation github-project-automation Bot moved this to Discussing in Team Board Apr 23, 2026
@sapphi-red sapphi-red moved this from Discussing to Approved in Team Board Aug 5, 2026
@sapphi-red sapphi-red added this to the 8.3 milestone Aug 5, 2026
@sapphi-red
sapphi-red merged commit 517b97f into vitejs:main Aug 21, 2026
18 checks passed
This was referenced Sep 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feat: web workers p2-to-be-discussed Enhancement under consideration (priority)

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

new URL("/my/file.js?wow", import.meta.url) doesn't provide "?wow" param to a plugin

2 participants