Conversation
📝 WalkthroughWalkthroughThe pull request changes the SQLite web worker instantiation path in scl-app.js from an absolute URL ( Changes
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~3 minutes Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/common/js/scl-app.js`:
- 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.
|
|
||
| // ===== Worker ===== | ||
| const worker = new Worker('/js/sqlite-worker.js', { type: 'module' }); | ||
| const worker = new Worker('./js/sqlite-worker.js', { type: 'module' }); |
There was a problem hiding this comment.
🧩 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 -20Repository: airen1986/sqlite-client
Length of output: 99
🏁 Script executed:
sed -n '235,245p' src/common/js/scl-app.jsRepository: airen1986/sqlite-client
Length of output: 313
🏁 Script executed:
cat -n src/vite.config.jsRepository: 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.jsRepository: 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.htmlRepository: airen1986/sqlite-client
Length of output: 18052
🏁 Script executed:
find src -type d -name "js" | head -10Repository: 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.
There was a problem hiding this comment.
i want it relative to page url only, as I am hosting this site ona different root
There was a problem hiding this comment.
@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`).
Summary by CodeRabbit