Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/common/js/scl-app.js
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ async function sqlCompletionSource(context) {
}

// ===== Worker =====
const worker = new Worker('/js/sqlite-worker.js', { type: 'module' });
const worker = new Worker('./js/sqlite-worker.js', { type: 'module' });
Copy link

@coderabbitai coderabbitai bot Mar 11, 2026

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🌐 Web query:

How are string URLs passed to new Worker(...) resolved in browsers, and what is Vite's recommended pattern for loading module workers from ES modules?

💡 Result:

1) How browsers resolve new Worker("...") when you pass a string URL

In browsers, the url string you pass to new Worker(url) is parsed as a URL and, if it’s relative, it’s resolved relative to the current HTML page’s location (i.e., the document/base URL), not relative to the JS module/file that contains the new Worker(...) call. Also, the worker script must be same-origin with the document (unless it’s a blob:/data: URL). [1]

2) Vite’s recommended pattern for module workers from ES modules

Vite recommends creating workers using the standards-aligned “constructor + new URL(..., import.meta.url)” pattern, and setting { type: "module" } for module workers:

const worker = new Worker(new URL('./worker.js', import.meta.url), { type: 'module' })

This makes the worker path resolve relative to the current ES module (via import.meta.url), which is more reliable for bundling. Vite’s worker detection requires new URL() to appear directly inside new Worker(...), with static option values. [2]

Sources: [1] MDN Worker() constructor docs, [2] Vite “Web Workers” guide.


🏁 Script executed:

find . -name "sqlite-worker.js" -o -name "*sqlite*worker*" | head -20

Repository: airen1986/sqlite-client

Length of output: 99


🏁 Script executed:

sed -n '235,245p' src/common/js/scl-app.js

Repository: airen1986/sqlite-client

Length of output: 313


🏁 Script executed:

cat -n src/vite.config.js

Repository: airen1986/sqlite-client

Length of output: 117


🏁 Script executed:

find . -name "vite.config.js" -o -name "vite.config.ts"

Repository: airen1986/sqlite-client

Length of output: 83


🏁 Script executed:

cat -n vite.config.js

Repository: airen1986/sqlite-client

Length of output: 1547


🏁 Script executed:

find src -maxdepth 1 -name "*.html"

Repository: airen1986/sqlite-client

Length of output: 81


🏁 Script executed:

ls -la src/public/ 2>/dev/null || echo "No public directory or no files"
ls -la src/js/ 2>/dev/null || echo "No src/js directory"

Repository: airen1986/sqlite-client

Length of output: 437


🏁 Script executed:

cat -n src/index.html

Repository: airen1986/sqlite-client

Length of output: 18052


🏁 Script executed:

find src -type d -name "js" | head -10

Repository: airen1986/sqlite-client

Length of output: 119


🏁 Script executed:

ls -la src/ | grep -E "js|public"
tree -L 2 src/

Repository: airen1986/sqlite-client

Length of output: 470


Use import.meta.url for the worker path to make it module-relative.

The string literal './js/sqlite-worker.js' is resolved relative to the page URL, not the module. Use Vite's recommended pattern with new URL() and import.meta.url for more robust, build-independent asset resolution.

♻️ Proposed change
-const worker = new Worker('./js/sqlite-worker.js', { type: 'module' });
+const worker = new Worker(new URL('../../public/js/sqlite-worker.js', import.meta.url), {
+  type: 'module',
+});
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/common/js/scl-app.js` at line 240, The worker instantiation uses a
page-relative path; change the Worker constructor to resolve the module-relative
URL via new URL('./js/sqlite-worker.js', import.meta.url). Replace the string
literal passed to new Worker (the variable/instance named worker created with
new Worker('./js/sqlite-worker.js', { type: 'module' })) with the result of new
URL(..., import.meta.url) so the worker script is resolved relative to the
current module.

Copy link
Owner Author

Choose a reason for hiding this comment

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

i want it relative to page url only, as I am hosting this site ona different root

Copy link

Choose a reason for hiding this comment

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

@airen1986, understood! Since you're hosting the app on a non-root path and need the worker URL resolved relative to the page, the ./js/sqlite-worker.js path is the correct approach for your deployment. I'll drop this suggestion.


✏️ Learnings added
Learnt from: airen1986
Repo: airen1986/sqlite-client PR: 4
File: src/common/js/scl-app.js:240-240
Timestamp: 2026-03-11T10:06:57.038Z
Learning: In `src/common/js/scl-app.js`, the Web Worker is intentionally instantiated with a page-relative URL (`./js/sqlite-worker.js`) rather than using `new URL(..., import.meta.url)`. This is by design because the site is hosted on a non-root path, and the worker path must resolve relative to the page URL.

Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.


🧠 Learnings used
Learnt from: CR
Repo: airen1986/sqlite-client PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-03-11T07:34:38.987Z
Learning: Applies to src/**/*.js : All environment variables must be prefixed with `VITE_` and accessed via `import.meta.env.VITE_*`. Never hardcode API URLs — always use `VITE_API_BASE_URL` through the `api.js` client.

Learnt from: CR
Repo: airen1986/sqlite-client PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-03-11T07:34:38.987Z
Learning: Applies to src/**/*.js : Use `src/common/js/api.js` for all HTTP requests (which uses `VITE_API_BASE_URL`).


worker.onmessage = (e) => {
const { id, error } = e.data;
Expand Down
Loading