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: support multiple useSWRInfinite hooks in a page #1009

Merged
merged 19 commits into from
Mar 13, 2021

Conversation

koba04
Copy link
Collaborator

@koba04 koba04 commented Mar 5, 2021

fixes #976
This PR fixes issues caused by using multiple useSWRInfinite on a page.
You can see the issues in the following link (v0.42).

This PR also fixes #976.
https://codesandbox.io/s/swr-basic-forked-mbx6y

I guess this is a naive implementation and would change some behaviors of useSWRInfinite, so it should be merged carefully.

@codesandbox-ci
Copy link

codesandbox-ci bot commented Mar 5, 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 1b111ef:

Sandbox Source
SWR-Basic Configuration
SWR-States Configuration
SWR-Infinite Configuration
SWR-Basic (forked) PR
SWR-Basic (forked) PR
SWR-Basic (forked) PR
agitated-drake-3hzu3 Issue #976

@koba04
Copy link
Collaborator Author

koba04 commented Mar 5, 2021

Why has the CodeSandbox build been failed?

ModuleNotFoundError
Could not find module in path: 'swr' relative to '/src/App.js'

@promer94
Copy link
Collaborator

promer94 commented Mar 5, 2021

After #995 codesandbox ci seems broken 🥲 . I am working on it

@promer94
Copy link
Collaborator

promer94 commented Mar 5, 2021

swr/tsconfig.json

Lines 25 to 28 in 66aaefd

"include": [
"src/**/*",
"./jest-setup.ts"
],

Adding new item in include filed would change the esm directory structure 🙈
should be fixed in #1011

@koba04
Copy link
Collaborator Author

koba04 commented Mar 5, 2021

@promer94 I got it, thank you!

@koba04 koba04 force-pushed the fix-multiple-use-swr-infinite branch from 2e43289 to d670348 Compare March 5, 2021 14:06
@koba04
Copy link
Collaborator Author

koba04 commented Mar 5, 2021

I've confirmed that this doesn't work, so I'll investigate more.
https://codesandbox.io/s/swr-basic-forked-s0dgl?file=/src/App.js

@koba04 koba04 force-pushed the fix-multiple-use-swr-infinite branch 3 times, most recently from 3c6ed90 to 16ac68f Compare March 6, 2021 16:24
@koba04 koba04 changed the title fix: revalidate all multiple useSWRInfinite fix: supprt multiple useSWRInfinite hooks in a page Mar 6, 2021
@koba04 koba04 marked this pull request as ready for review March 6, 2021 16:36
src/use-swr-infinite.ts Outdated Show resolved Hide resolved
src/use-swr-infinite.ts Outdated Show resolved Hide resolved
@koba04 koba04 force-pushed the fix-multiple-use-swr-infinite branch from f3b375c to abf9c5c Compare March 9, 2021 16:27
@koba04
Copy link
Collaborator Author

koba04 commented Mar 10, 2021

all tests now have been passed 🎉 But I have to refactor the implementation to get this merged.

@koba04 koba04 force-pushed the fix-multiple-use-swr-infinite branch from 175b782 to 4ef0de7 Compare March 10, 2021 16:06
src/use-swr-infinite.ts Outdated Show resolved Hide resolved
src/use-swr-infinite.ts Outdated Show resolved Hide resolved
@huozhi huozhi changed the title fix: supprt multiple useSWRInfinite hooks in a page fix: support multiple useSWRInfinite hooks in a page Mar 11, 2021
@koba04
Copy link
Collaborator Author

koba04 commented Mar 11, 2021

I wanted to re-use useIsomorphicLayoutEffect in useSWRInfinite, but I didn't want to expose it from use-swr, so I've moved it to web-presets and imported it.

@koba04
Copy link
Collaborator Author

koba04 commented Mar 12, 2021

This is now ready for review again 🚀

src/libs/web-preset.ts Outdated Show resolved Hide resolved
This was referenced Mar 15, 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.

useSwrInfinite order of calling hooks and setSize matters
3 participants