Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Data update after idling for too long uses a different fetch method #960

Closed
ParticleCore opened this issue Mar 11, 2024 · 2 comments
Closed
Labels
Milestone

Comments

@ParticleCore
Copy link
Owner

The issue initially discussed in #916 is still present in 2.0.7, but likely not in 2.0.6. This is because in the previous version there was an override around the handleResponse method that covered the scenario.

However, in 2.0.7 this override was not only redundant for the most part, but also taxing the performance, and was removed.

I was able to finally track down the source of the problem and it relies on the XMLHttpRequest instead of the window.fetch, and simply mimics the async nature of window.fetch.

    fI.prototype.fetch = function (a, b, c) {
      var d = this,
      e = $ya(a, b, c); <---
      return new Promise(
        function (f, h) {
          function l() {
            if (null == c ? 0 : c.zv) try {
              var n = d.handleResponse(a, e.status, e.response, c); <---
              f(n)
            } catch (p) {
              h(p)
            } else f(d.handleResponse(a, e.status, e.response, c))  <---
          }
          e.onerror = l;
          e.onload = l;
          var m;
          e.send(null != (m = b.body) ? m : null)
        }
      )
    };
    $ya = function (a, b, c) {
      var d = new XMLHttpRequest;
      if (null == c ? 0 : c.JA) d.onreadystatechange = function (f) {
        c.JA(d, f)
      };
      var e;
      d.open(null != (e = b.method) ? e : 'GET', a, !0);
      d.responseType = 'text';
      d.withCredentials = !0;
      if (b.headers) for (
        a = g.u(Object.entries(b.headers)),
        b = a.next();
        !b.done;
        b = a.next()
      ) e = g.u(b.value),
      b = e.next().value,
      e = e.next().value,
      d.setRequestHeader(b, e);
      return d
    };

The solution will be to also override the xhr onreadystatechange and onload methods in order to apply any modifications before the data is consumed.

@ParticleCore ParticleCore added this to the 2.0.8 milestone Mar 11, 2024
@ParticleCore
Copy link
Owner Author

Opted to restore a previous override method but filtered just for specific cases to reduce overhead, but should finally address the original issue, otherwise I will go with the xhr method as a last resort.

@ParticleCore
Copy link
Owner Author

Limited testing showed the issue appears to be corrected, unfortunately every time I need to test this takes about 6h so it can take a long time to nail it down.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
1 participant