Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🌐 Web query:
How are string URLs passed tonew 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 URLIn browsers, the
urlstring you pass tonew 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 thenew Worker(...)call. Also, the worker script must be same-origin with the document (unless it’s ablob:/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: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 requiresnew URL()to appear directly insidenew Worker(...), with static option values. [2]Sources: [1] MDN
Worker()constructor docs, [2] Vite “Web Workers” guide.🏁 Script executed:
Repository: 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:
Repository: airen1986/sqlite-client
Length of output: 117
🏁 Script executed:
Repository: airen1986/sqlite-client
Length of output: 83
🏁 Script executed:
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:
Repository: airen1986/sqlite-client
Length of output: 437
🏁 Script executed:
Repository: airen1986/sqlite-client
Length of output: 18052
🏁 Script executed:
Repository: airen1986/sqlite-client
Length of output: 119
🏁 Script executed:
Repository: airen1986/sqlite-client
Length of output: 470
Use
import.meta.urlfor 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 withnew URL()andimport.meta.urlfor more robust, build-independent asset resolution.♻️ Proposed change
🤖 Prompt for AI Agents
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.jspath is the correct approach for your deployment. I'll drop this suggestion.✏️ Learnings added
🧠 Learnings used