@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.
@@ -856,13 +856,8 @@ function _listen(query, params, opts = {}) {
856
856
  return (token || withCredentials) && (esOptions.withCredentials = !0), token && (esOptions.headers = {
857
857
  Authorization: `Bearer ${token}`
858
858
  }), new Observable((observer) => {
859
- let es;
860
- getEventSource().then((eventSource) => {
861
- es = eventSource;
862
- }).catch((reason) => {
863
- observer.error(reason), stop();
864
- });
865
- let reconnectTimer, stopped = !1;
859
+ let es, reconnectTimer, stopped = !1, unsubscribed = !1;
860
+ open();
866
861
  function onError() {
867
862
  stopped || (emitReconnect(), !stopped && es.readyState === es.CLOSED && (unsubscribe(), clearTimeout(reconnectTimer), reconnectTimer = setTimeout(open, 100)));
868
863
  }
@@ -883,18 +878,21 @@ function _listen(query, params, opts = {}) {
883
878
  shouldEmitReconnect && observer.next({ type: "reconnect" });
884
879
  }
885
880
  async function getEventSource() {
886
- const { default: EventSource } = await import("@sanity/eventsource"), evs = new EventSource(uri, esOptions);
881
+ const { default: EventSource } = await import("@sanity/eventsource");
882
+ if (unsubscribed)
883
+ return;
884
+ const evs = new EventSource(uri, esOptions);
887
885
  return evs.addEventListener("error", onError), evs.addEventListener("channelError", onChannelError), evs.addEventListener("disconnect", onDisconnect), listenFor.forEach((type) => evs.addEventListener(type, onMessage)), evs;
888
886
  }
889
887
  function open() {
890
888
  getEventSource().then((eventSource) => {
891
- es = eventSource;
889
+ eventSource && (es = eventSource);
892
890
  }).catch((reason) => {
893
891
  observer.error(reason), stop();
894
892
  });
895
893
  }
896
894
  function stop() {
897
- stopped = !0, unsubscribe();
895
+ stopped = !0, unsubscribe(), unsubscribed = !0;
898
896
  }
899
897
  return stop;
900
898
  });