Skip to content

add relative sqlite worker#4

Merged
airen1986 merged 1 commit intomainfrom
feature/pr-setup
Mar 11, 2026
Merged

add relative sqlite worker#4
airen1986 merged 1 commit intomainfrom
feature/pr-setup

Conversation

@airen1986
Copy link
Owner

@airen1986 airen1986 commented Mar 11, 2026

Summary by CodeRabbit

  • Chores
    • Updated application resource loading configuration to improve portability across different deployment environments.

@coderabbitai
Copy link

coderabbitai bot commented Mar 11, 2026

📝 Walkthrough

Walkthrough

The pull request changes the SQLite web worker instantiation path in scl-app.js from an absolute URL (/js/sqlite-worker.js) to a relative URL (./js/sqlite-worker.js), affecting how the runtime resolves the worker script location.

Changes

Cohort / File(s) Summary
Web Worker Path
src/common/js/scl-app.js
Changed SQLite worker script path from absolute to relative URL for proper resource resolution.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Poem

🐰 A path adjustment, small but true,
From absolute to relative anew,
The worker hops along with ease,
Finding sqlite where it please,
One little dot, a change so small,
Makes all the paths align in all!

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: converting the sqlite worker path from absolute to relative URL.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feature/pr-setup

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

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.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: f207ffca-3826-4892-b88b-723c87f01a3f

📥 Commits

Reviewing files that changed from the base of the PR and between 61a417f and 3c2f947.

📒 Files selected for processing (1)
  • src/common/js/scl-app.js


// ===== 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`).

@airen1986 airen1986 merged commit 249c8b1 into main Mar 11, 2026
2 checks passed
@coderabbitai coderabbitai bot mentioned this pull request Mar 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant