Skip to content

initFocus doesn't not remove listeners when unmounting SWRConfig #1456

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

Closed
thgh opened this issue Sep 13, 2021 · 2 comments · Fixed by #1449
Closed

initFocus doesn't not remove listeners when unmounting SWRConfig #1456

thgh opened this issue Sep 13, 2021 · 2 comments · Fixed by #1449

Comments

@thgh
Copy link

thgh commented Sep 13, 2021

Bug report

Description / Observed Behavior

I was looking through the source code but couldn't find the code where it calls the unsubscribe function that's returned in initFocus . It seems like it will never be called.

This is not a blocking issue, just an inconsistency in the docs/code.

Expected Behavior

It should call the function that's returned from initFocus() when unmounting the provider (SWRConfig).
OR
it should call the function that's returned from initFocus() when there are no active useSWR() hooks.

Repro Steps / Code Example

Derived from https://swr.vercel.app/docs/advanced/react-native#global-setup

<SWRConfig 
  value={{
    initFocus: () => {
      return () => alert('This function is never called')
    }
  }}
>
  <App>
</SWRConfig>

Additional Context

SWR version 1

Relevant code:

swr/src/utils/cache.ts

Lines 57 to 58 in 3285cc4

if (!IS_SERVER) {
opts.initFocus(

Mentioned in #417 (comment)

@shuding
Copy link
Member

shuding commented Sep 13, 2021

Thank you! We've just fixed it in #1449. 🎉

@shuding shuding closed this as completed Sep 13, 2021
@huozhi huozhi linked a pull request Sep 13, 2021 that will close this issue
@Myzel394
Copy link

For me, initFocus is even never called at all

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 a pull request may close this issue.

3 participants