Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions packages/zero-client/src/client/server-option.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import {getBrowserGlobal} from '../../../shared/src/browser-env.js';
import type {HTTPString} from './http-string.js';

function validateServerParam(paramName: string, server: string): HTTPString {
Expand Down Expand Up @@ -56,6 +57,13 @@ function validateServerParam(paramName: string, server: string): HTTPString {
export function getServer(
server: string | undefined | null,
): HTTPString | null {
const WS = getBrowserGlobal('WebSocket');
if (!WS) {
console.warn(
'Zero started in an unsupported environment, no data will be synced.',
);
return null;
}
if (server === undefined || server === null) {
console.warn(
'Zero starting up with no server URL. This is supported for unit testing ' +
Expand Down
7 changes: 7 additions & 0 deletions packages/zero-client/src/client/zero.ts
Original file line number Diff line number Diff line change
Expand Up @@ -565,6 +565,13 @@ export class Zero<const S extends Schema> {
return createLogOptions(options);
}

/**
* The server URL that this Zero instance is configured with.
*/
get server(): HTTPString | null {
return this.#server;
}

/**
* The name of the IndexedDB database in which the data of this
* instance of Zero is stored.
Expand Down
8 changes: 6 additions & 2 deletions packages/zero-react/src/use-query.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,14 @@ export function useQuery<
const view = viewStore.getView(
z.clientID,
q as AdvancedQuery<TSchema, TReturn>,
enable,
enable && z.server !== null,
);
// https://react.dev/reference/react/useSyncExternalStore
return useSyncExternalStore(view.subscribeReactInternals, view.getSnapshot);
return useSyncExternalStore(
view.subscribeReactInternals,
view.getSnapshot,
view.getSnapshot,
);
}

const emptyArray: unknown[] = [];
Expand Down
Loading