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

Fix: do not depend on navigator.onLine; code optimizations #1004

Merged
merged 5 commits into from
Mar 2, 2021

Conversation

shuding
Copy link
Member

@shuding shuding commented Mar 1, 2021

As mentioned in the code comments, navigator.onLine isn't always reliable due to this bug. Instead of depending on it, we have to use another approach to always assume it's online (since the page loads, it's very likely to be online). And when we receive the offline event from window, we set the internal state to offline.

With this change, SWR will still try to revalidate even it's offline, if both requirements are meet:

  • the app is running with Service Worker (or RN), and it's offline.
  • Chrome (or the navigator) is having the bug mentioned above.

It's an extremely rare case.

Also did some code optimizations (results in a smaller bundle with ncc) and updated tests.

@codesandbox-ci
Copy link

codesandbox-ci bot commented Mar 1, 2021

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 25f1f66:

Sandbox Source
SWR-Basic Configuration
SWR-States Configuration
SWR-Infinite Configuration

@shuding shuding merged commit 8c0461c into master Mar 2, 2021
@shuding shuding deleted the fix-online-check branch March 2, 2021 10:21
@shuding
Copy link
Member Author

shuding commented Mar 2, 2021

Released 0.4.3-beta.1.

This was referenced Mar 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants