Add singleTab option for Worker in tab-less contexts like Capacitor apps#832
Open
jacob-8 wants to merge 1 commit intoelectric-sql:mainfrom
Open
Add singleTab option for Worker in tab-less contexts like Capacitor apps#832jacob-8 wants to merge 1 commit intoelectric-sql:mainfrom
jacob-8 wants to merge 1 commit intoelectric-sql:mainfrom
Conversation
Author
|
FYI, cloning down the repo (with submodules), pglite main ❯ pnpm ts:build
> @ ts:build /home/jacob/code/examples/pglite
> pnpm -r --filter "./packages/**" build
Scope: 9 of 13 workspace projects
packages/pg-protocol build$ tsup
[18 lines collapsed]
│ CJS dist/messages.cjs.map 11.69 KB
│ CJS ⚡️ Build success in 22ms
│ DTS Build start
│ DTS ⚡️ Build success in 555ms
│ DTS dist/index.d.cts 1.67 KB
│ DTS dist/messages.d.cts 762.00 B
│ DTS dist/messages-CaXcfh5Z.d.cts 12.65 KB
│ DTS dist/index.d.ts 1.67 KB
│ DTS dist/messages.d.ts 761.00 B
│ DTS dist/messages-CaXcfh5Z.d.ts 12.65 KB
└─ Done in 1s
packages/pglite build$ pnpm build:js
│ > @electric-sql/pglite@0.3.11 build:js /home/jacob/code/examples/pglite/packages/pglite
│ > tsup && tsx scripts/bundle-wasm.ts
│ Cannot find release/pglite.js
│ CLI Building entry: src/index.ts, src/templating.ts, src/contrib/amcheck.ts, src/contrib/auto_explain.ts, src/contrib/bloom.ts, src/contrib/btree_gin.ts, src/contrib/btree_gist.ts, …
│ CLI Using tsconfig: tsconfig.json
│ CLI tsup v8.3.0
│ CLI Using tsup config: /home/jacob/code/examples/pglite/packages/pglite/tsup.config.ts
│ CLI Target: es2020
│ CLI Cleaning output folder
│ ESM Build start
│ CJS Build start
│ ✘ [ERROR] Could not resolve "../release/pglite"
│ src/postgresMod.ts:1:31:
│ 1 │ import PostgresModFactory from '../release/pglite'
│ ╵ ~~~~~~~~~~~~~~~~~~~
│ ✘ [ERROR] Could not resolve "../release/pglite"
│ src/postgresMod.ts:1:31:
│ 1 │ import PostgresModFactory from '../release/pglite'
│ ╵ ~~~~~~~~~~~~~~~~~~~
│ ESM Build failed
│ CJS Build failed
│ DTS Build start
│ src/postgresMod.ts(1,32): error TS2307: Cannot find module '../release/pglite' or its corresponding type declarations.
│ DTS Build error
│ ELIFECYCLE Command failed with exit code 1.
└─ Failed in 6.4s at /home/jacob/code/examples/pglite/packages/pglite
/home/jacob/code/examples/pglite/packages/pglite:
ERR_PNPM_RECURSIVE_RUN_FIRST_FAIL @electric-sql/pglite@0.3.11 build: `pnpm build:js`
Exit status 1
ELIFECYCLE Command failed with exit code 1. |
Collaborator
|
You need to do `pnpm build:all`. It's in the README.
…On Thu, Oct 30, 2025, 11:23 Jacob Bowdoin ***@***.***> wrote:
*jacob-8* left a comment (electric-sql/pglite#832)
<#832 (comment)>
FYI, cloning down the repo (with submodules), pnpm install and then pnpm
ts:build doesn't work. I'm on Linux.
pglite main ❯ pnpm ts:build
> @ ts:build /home/jacob/code/examples/pglite> pnpm -r --filter "./packages/**" build
Scope: 9 of 13 workspace projects
packages/pg-protocol build$ tsup
[18 lines collapsed]
│ CJS dist/messages.cjs.map 11.69 KB
│ CJS ⚡️ Build success in 22ms
│ DTS Build start
│ DTS ⚡️ Build success in 555ms
│ DTS dist/index.d.cts 1.67 KB
│ DTS dist/messages.d.cts 762.00 B
│ DTS dist/messages-CaXcfh5Z.d.cts 12.65 KB
│ DTS dist/index.d.ts 1.67 KB
│ DTS dist/messages.d.ts 761.00 B
│ DTS dist/messages-CaXcfh5Z.d.ts 12.65 KB
└─ Done in 1s
packages/pglite build$ pnpm build:js
│ > @***@***.*** build:js /home/jacob/code/examples/pglite/packages/pglite
│ > tsup && tsx scripts/bundle-wasm.ts
│ Cannot find release/pglite.js
│ CLI Building entry: src/index.ts, src/templating.ts, src/contrib/amcheck.ts, src/contrib/auto_explain.ts, src/contrib/bloom.ts, src/contrib/btree_gin.ts, src/contrib/btree_gist.ts, …
│ CLI Using tsconfig: tsconfig.json
│ CLI tsup v8.3.0
│ CLI Using tsup config: /home/jacob/code/examples/pglite/packages/pglite/tsup.config.ts
│ CLI Target: es2020
│ CLI Cleaning output folder
│ ESM Build start
│ CJS Build start
│ ✘ [ERROR] Could not resolve "../release/pglite"
│ src/postgresMod.ts:1:31:
│ 1 │ import PostgresModFactory from '../release/pglite'
│ ╵ ~~~~~~~~~~~~~~~~~~~
│ ✘ [ERROR] Could not resolve "../release/pglite"
│ src/postgresMod.ts:1:31:
│ 1 │ import PostgresModFactory from '../release/pglite'
│ ╵ ~~~~~~~~~~~~~~~~~~~
│ ESM Build failed
│ CJS Build failed
│ DTS Build start
│ src/postgresMod.ts(1,32): error TS2307: Cannot find module '../release/pglite' or its corresponding type declarations.
│ DTS Build error
│ ELIFECYCLE Command failed with exit code 1.
└─ Failed in 6.4s at /home/jacob/code/examples/pglite/packages/pglite
/home/jacob/code/examples/pglite/packages/pglite:
ERR_PNPM_RECURSIVE_RUN_FIRST_FAIL @***@***.*** build: `pnpm build:js`
Exit status 1
ELIFECYCLE Command failed with exit code 1.
—
Reply to this email directly, view it on GitHub
<#832 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AI62W6QVQUVYT3WHVHQCHPD32HRJ3AVCNFSM6AAAAACKURUVXCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZTINRXGE4TKNBVHA>
.
You are receiving this because you are subscribed to this thread.Message
ID: ***@***.***>
|
samwillis
requested changes
Nov 3, 2025
Collaborator
samwillis
left a comment
There was a problem hiding this comment.
Hi @jacob-8, I think this is a good addition, but we should add tests that it is working correctly.
Could you modify packages/pglite/tests/targets/web/base.js such that it does something like:
export function tests(env, dbFilename, target) {
describe.each([
{ singleTab: false },
{ singleTab: true },
])(`targets ${target} singleTab=$singleTab `, ({ singleTab }) => { db = new PGliteWorker(
new Worker(WORKER_PATH, {
type: 'module',
}),
{
dataDir: dbFilename,
singleTab
},
)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Capacitor apps use an instance of webview that don't have the
navigator.locksAPI, thus the PGlite worker doesn't work in these contexts. It throws an error: "Cannot read properties of undefined (reading 'request')."I propose updating the code to allow for singleTab worker usage. I would say that 90% of the benefit of the worker is the background thread ability and only 10% is multi-tab stuff. This allows us to still use the worker in apps built using Capacitor and other similar frameworks.