Skip to content

Conversation

@longfellowone
Copy link
Contributor

Issue

Fixes #808

Summary

  • Prevents OPFS lock stalls on rapid refresh by deferring worker termination when pagehide fires while open is still in-flight.
  • Makes pagehide handling idempotent and ensures a deferred forceClose() runs after open resolves.

Changes

  • WASQLiteOpenFactory: pagehide handler now returns early if already triggered; if open is in-flight, it defers termination until after open completes, then forceClose() runs; open failures always terminate the worker.
  • WorkerWrappedAsyncDatabaseConnection: keeps forceClose() idempotent via finalizeClose().

Tests

  • pnpm --filter @powersync/web run build:tsc
  • pnpm vitest --run tests/opfs_pagehide.test.ts
  • pnpm vitest (full suite)

Notes

  • Pagehide behavior remains consistent regardless of BFCache (event.persisted); change only defers termination during open and ignores repeat pagehide events.

@changeset-bot
Copy link

changeset-bot bot commented Jan 4, 2026

🦋 Changeset detected

Latest commit: 19db84c

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@powersync/web Patch
@powersync/diagnostics-app Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@longfellowone
Copy link
Contributor Author

longfellowone commented Jan 4, 2026

Closing in favor of split PRs

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.

OPFSCoopSyncVFS: Database initialization timeout on page refresh (Safari)

1 participant