Skip to content

Commit

Permalink
PKG -- [fcl] Skip network requests when polling on service if documen…
Browse files Browse the repository at this point in the history
…t is not visible (#1640)

* PKG -- [fcl] Skip network requests when polling on service if document is not visible

* PKG -- [fcl] Skip network requests when polling on service if document is not visible
  • Loading branch information
JeffreyDoyle authored May 16, 2023
1 parent 2f10082 commit b9b957c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
5 changes: 5 additions & 0 deletions .changeset/selfish-parents-argue.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@onflow/fcl": patch
---

PKG -- [fcl] Skip network requests when polling on service if document is not visible
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,19 @@ export async function poll(service, canContinue = () => true) {

let resp
try {
resp = await fetchService(service, {
method: serviceMethod(service),
}).then(normalizePollingResponse)
} catch (error) {
if (
typeof document !== "undefined" &&
document.visibilityState === "hidden"
) {
await new Promise(r => setTimeout(r, 500))
return poll(service, canContinue)
} else {
throw error
}

resp = await fetchService(service, {
method: serviceMethod(service),
}).then(normalizePollingResponse)
} catch (error) {
throw error
}

switch (resp.status) {
Expand Down

0 comments on commit b9b957c

Please sign in to comment.