Skip to content

fix: mark isValidating as false when key is falsy #757

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

Merged
merged 2 commits into from
Nov 17, 2020

Conversation

huozhi
Copy link
Member

@huozhi huozhi commented Nov 10, 2020

Fix #199

* tear down work when key turns to empty, unmount state should be false if it's mounted before.
* dispatch isValidating as false

scenario: key: v1 -> v2 -> ''

in this case, when transfer to empty key the unmountedRef will be set to true, which lead dispatch take no effect. so I set it to true if it's not really unmounted.
then dispatch isValidating to false to ignore the ongoing requests.
update keyRef to match key, then isValidating getter will retrive states from stateRef

forcedly return false when key is falsy

@codesandbox-ci
Copy link

codesandbox-ci bot commented Nov 17, 2020

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 b21e3ea:

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

@@ -719,7 +719,7 @@ function useSWR<Data = any, Error = any>(
isValidating: {
get: function() {
stateDependencies.current.isValidating = true
return stateRef.current.isValidating
return key ? stateRef.current.isValidating : false
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can only come up with this simple solution that return false when key is falsy.

since when key changes swr will always clean up and unmountedRef.current changes to true. so dispatch won't work and in won't pass the internal condition.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fix sounds good until we have a better and complete refactoring to the codebase. 👍

@huozhi huozhi changed the title fix: tear down when key turns to empty fix: mark isValidating as false when key is falsy Nov 17, 2020
Copy link
Member

@shuding shuding left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the effort!

@shuding shuding merged commit 5e48f4b into vercel:master Nov 17, 2020
@huozhi huozhi deleted the issue-199 branch November 17, 2020 11:08
shuding added a commit that referenced this pull request Dec 16, 2020
* 0.3.8

* replace rIC with rAF (#744)

* Fix race condition when calling mutate synchronously (#735)

* fix race condition when calling mutate synchronously

* fix test

* add comment

* fix code reviews

* refactor: support SSR in Deno (#754)

* refactor: support SSR in Deno

* refactor: improve Deno determining

* Add @ts-ignore

Co-authored-by: Shu Ding <[email protected]>

Co-authored-by: Shu Ding <[email protected]>

* fix eslint error (#768)

* Fix `mutateCallback` types (#745)

* Fix `mutateCallback` types

* WIP

* Add CodeSandbox CI (#769)

* add CodeSandbox CI

* add new line

* fix install cmd

Co-authored-by: Paco <[email protected]>

* dispatch's payload type is actionType and run lint (#772)

* chore: payload is actionType

* chore: move a ts-ignore comment

* Fix suspense (#777)

* fix #494

* add comment

* rename to initialMountedRef

* 0.3.9

* fix: mark isValidating as false when key is falsy (#757)

* fix: tear down when key turns to empty

* use false for empty key

* Fix README.md typo (#783)

'/api/data' => '/api/user' in "Multiple Arguments"

* fix: do mount check in config callback (#787)

* Update api-hooks example README.md (#790)

Updated the Vercel deploy link to the correct directory

* Return '@null' if args is null ASAP (#767)

* chore: return 'null' if arg[i] is null ASAP

* chore: update comment

* chore: use continue

* Bump ini from 1.3.5 to 1.3.8 (#806)

Bumps [ini](https://github.com/isaacs/ini) from 1.3.5 to 1.3.8.
- [Release notes](https://github.com/isaacs/ini/releases)
- [Commits](npm/ini@v1.3.5...v1.3.8)

Signed-off-by: dependabot[bot] <[email protected]>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* update test

Co-authored-by: Shu Ding <[email protected]>
Co-authored-by: X <[email protected]>
Co-authored-by: Umidbek Karimov <[email protected]>
Co-authored-by: Paco <[email protected]>
Co-authored-by: matamatanot <[email protected]>
Co-authored-by: Jiachi Liu <[email protected]>
Co-authored-by: sAy <[email protected]>
Co-authored-by: William Crutchfield <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
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.

[Bug] The isValidating flag gets stuck on true if a request is cancelled
2 participants