Skip to content

Sync from docs: disconnect/disconnectAndClear nuance and connect once-per-session rule (powersync-docs #602) - #86

Open
bean1352 wants to merge 1 commit into
mainfrom
drift/docs-602-reducing-usage
Open

Sync from docs: disconnect/disconnectAndClear nuance and connect once-per-session rule (powersync-docs #602)#86
bean1352 wants to merge 1 commit into
mainfrom
drift/docs-602-reducing-usage

Conversation

@bean1352

@bean1352 bean1352 commented Sep 1, 2026

Copy link
Copy Markdown
Collaborator

Generated by Claude. Review carefully before merging.

Source docs PR: powersync-ja/powersync-docs#602

What changed in docs

PR #602 added a new "Reducing Usage" page (resources/usage-and-billing/reducing-usage.mdx) covering data synced and data hosted optimization strategies, and extensively reworked the usage FAQ with more precise guidance on disconnect() vs disconnectAndClear(), the single-connect-per-session pattern, and causes of high sync operation counts.

Skill updates in this PR

  • skills/powersync/SKILL.md: Split the disconnectAndClear() Key Rule into a conditional rule covering both cases. Added a new Key Rule that .connect() must be called once per session, not on focus events or token refreshes.
  • skills/powersync/references/powersync-debug.md: Updated the "when to use each" list in the disconnectAndClear() section to include same-user sign-out as a valid disconnect() case, matching the nuance introduced in the new docs page.

Notes for reviewer

disconnect() vs disconnectAndClear() on sign-out: The new docs clarify that disconnectAndClear() is not always required on sign-out. If the same user will return to their own device and security permits retaining local data, disconnect() is preferable because the client resumes from its saved sync position instead of re-downloading everything. The existing debug file implied disconnectAndClear() for any logout, which contradicted the new guidance. Both files now distinguish user-account switches (always use disconnectAndClear()) from same-user sign-outs (use disconnect() when safe).

.connect() once per session: The docs FAQ added guidance that opening one PowerSyncDatabase and calling .connect() once, rather than reconnecting on window focus or token refresh, prevents unnecessary concurrent client counts and reconnect overhead. This pattern was not previously documented in the Key Rules.

Items intentionally left untouched: The new docs page also covers compacting, defragmenting, bucket fan-out, large column patterns, auto_subscribe behavior, and no-op update footguns. The compacting/defragmenting and bucket fan-out topics already appear in powersync-debug.md and powersync-service.md. The auto_subscribe behavior is covered in sync-config.md. No-op updates are a new addition to the docs but are operationally focused (a DBA concern rather than a code-generation concern); adding them to the debug reference may be worth considering in a follow-up.

Snyk scan: The snyk-agent-scan demo endpoint returned 403 (proxy blocked in the sandbox). The node scripts/validate.mjs validation passed. The changed lines contain no connection strings, hex IDs, literal credentials, or credential-harvesting wording, so the scan would be expected to pass.


Generated by Claude Code

…connect() once-per-session rule

- SKILL.md: split disconnectAndClear() rule to cover same-user sign-out case
  where keeping local data is safe, prefer disconnect() to avoid a full
  re-sync on the next sign-in.
- SKILL.md: add rule that .connect() must be called once per session; calling
  it on focus events, token refreshes, or network changes opens redundant sync
  connections.
- powersync-debug.md: update disconnect()/disconnectAndClear() 'when to use each'
  list to include same-user sign-out as a valid disconnect() case, clarifying
  that disconnectAndClear() is required only when another user accesses the
  device or security requires wiping local data.

Source: powersync-ja/powersync-docs#602 (reducing-usage page and FAQ rework)
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.

2 participants