@sanity/client 6.17.0 → 6.17.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -873,13 +873,8 @@ function _listen(query, params, opts = {}) {
873
873
  return (token || withCredentials) && (esOptions.withCredentials = !0), token && (esOptions.headers = {
874
874
  Authorization: `Bearer ${token}`
875
875
  }), new rxjs.Observable((observer) => {
876
- let es;
877
- getEventSource().then((eventSource) => {
878
- es = eventSource;
879
- }).catch((reason) => {
880
- observer.error(reason), stop();
881
- });
882
- let reconnectTimer, stopped = !1;
876
+ let es, reconnectTimer, stopped = !1, unsubscribed = !1;
877
+ open();
883
878
  function onError() {
884
879
  stopped || (emitReconnect(), !stopped && es.readyState === es.CLOSED && (unsubscribe(), clearTimeout(reconnectTimer), reconnectTimer = setTimeout(open, 100)));
885
880
  }
@@ -900,18 +895,21 @@ function _listen(query, params, opts = {}) {
900
895
  shouldEmitReconnect && observer.next({ type: "reconnect" });
901
896
  }
902
897
  async function getEventSource() {
903
- const { default: EventSource } = await import("@sanity/eventsource"), evs = new EventSource(uri, esOptions);
898
+ const { default: EventSource } = await import("@sanity/eventsource");
899
+ if (unsubscribed)
900
+ return;
901
+ const evs = new EventSource(uri, esOptions);
904
902
  return evs.addEventListener("error", onError), evs.addEventListener("channelError", onChannelError), evs.addEventListener("disconnect", onDisconnect), listenFor.forEach((type) => evs.addEventListener(type, onMessage)), evs;
905
903
  }
906
904
  function open() {
907
905
  getEventSource().then((eventSource) => {
908
- es = eventSource;
906
+ eventSource && (es = eventSource);
909
907
  }).catch((reason) => {
910
908
  observer.error(reason), stop();
911
909
  });
912
910
  }
913
911
  function stop() {
914
- stopped = !0, unsubscribe();
912
+ stopped = !0, unsubscribe(), unsubscribed = !0;
915
913
  }
916
914
  return stop;
917
915
  });
@@ -1432,7 +1430,7 @@ function defineDeprecatedCreateClient(createClient2) {
1432
1430
  return printNoDefaultExport(), createClient2(config);
1433
1431
  };
1434
1432
  }
1435
- var name = "@sanity/client", version = "6.17.0";
1433
+ var name = "@sanity/client", version = "6.17.1";
1436
1434
  const middleware = [
1437
1435
  middleware$1.debug({ verbose: !0, namespace: "sanity:client" }),
1438
1436
  middleware$1.headers({ "User-Agent": `${name} ${version}` }),