Skip to content

Migrate react-ditto to Ditto v5#94

Merged
Aaron Leopold (aaronleopold) merged 9 commits into
masterfrom
aaronleopold/forge-1921-react-ditto-migration-to-ditto-v5
Jun 9, 2026
Merged

Migrate react-ditto to Ditto v5#94
Aaron Leopold (aaronleopold) merged 9 commits into
masterfrom
aaronleopold/forge-1921-react-ditto-migration-to-ditto-v5

Conversation

@aaronleopold

Copy link
Copy Markdown
Member

This PR supersedes #65

v5 drops the query builder and the *Identity types, so the old query-builder and identity hooks had to go. In their place are two DQL hooks, useQuery and useExecuteQuery, taken from #65 and brought up to the v5 API. Providers now open instances with Ditto.open/DittoConfig and key them off the configured persistence directory.

Also reworked the vite example for the v5 init and auth flow, switched its tests from jest to vitest, and refreshed the README, CHANGELOG, CI, etc.

v5 drops the query builder and the Identity types, so the old query-builder
and identity hooks had to go. In their place are two DQL hooks, useQuery and
useExecuteQuery, taken from the stale DQL PR and brought up to the v5 API.
Providers now open instances with Ditto.open/DittoConfig and key them off the
configured persistence directory.

Also reworked the vite example for the v5 init and auth flow, switched its
tests from jest to vitest, and refreshed the README, CHANGELOG and CI.
CI was dying because headless Chrome won't start without --no-sandbox on the
runners, so the karma launcher passes it now.

Review follow-ups: useExecuteQuery leaves items/mutatedDocumentIDs undefined
instead of using a null sentinel (matches how TanStack and similar libs
behave), dropped the doc-only type imports that only existed to satisfy
eslint-disable lines, and pointed the README at support@ditto.com.
These imports back the {@link} references in the JSDoc, and the no-unused-vars
disables are what keep eslint quiet about them. Putting them back the way they
were.
The example opened both instances on load, so the placeholder server config
threw validation/invalid-ditto-config and took down the whole app. Now it runs
offline out of the box and only spins up the server instance once real portal
credentials are filled in.
v5 renamed App ID to Database ID, so the docs and example now talk about
creating a database in the portal and grabbing its settings, rather than an
app. Left the genuine 'app' references (your React app, the example app) alone.
useQuery and useRemotePeers can hand back a null ditto, and useExecuteQuery an
undefined one, before anything has loaded; storeObserver is undefined until the
query is configured. The return types now reflect that instead of pretending
the values are always present. Also rebuild useQuery's reset when localOnly
changes so the sync subscription tracks the flag.
@aaronleopold Aaron Leopold (aaronleopold) marked this pull request as ready for review June 8, 2026 18:50
Comment thread src/queries/useExecuteQuery.spec.tsx
The try/catch reject tests passed silently when execute() didn't throw. Added
expect.fail() after the await (rethrowing the assertion through the catch). That
surfaced that the lazy 'invalid instance' test never actually rejected — the
wrapper created an instance for any path — so it now uses a setup that returns
null to genuinely exercise the rejection path.
Comment thread src/queries/useExecuteQuery.ts Outdated
Comment thread src/queries/useExecuteQuery.ts Outdated
So the query result type flows end-to-end instead of degrading to any
internally.
@aaronleopold Aaron Leopold (aaronleopold) merged commit 3e2204d into master Jun 9, 2026
1 check passed
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.

3 participants