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

[enhance] use the latest version of the config callbacks #515

Closed
Lam9090 opened this issue Jul 13, 2020 · 4 comments
Closed

[enhance] use the latest version of the config callbacks #515

Lam9090 opened this issue Jul 13, 2020 · 4 comments

Comments

@Lam9090
Copy link
Contributor

Lam9090 commented Jul 13, 2020

Related issue: #508

Currently,the config callbacks captured by the eventsRef is the callbacks created in the initial render of the component.
If the config callbacks is pure, everything is fine.
but if the config callbacks rely on some variables of the components , it would cause some bugs related to the stale closure.

solution

I think if the useSWR hook read the config callbacks via useRef would be great, but this may bring some bugs if some APP rely on the current behavior of the config callbacks.

  const eventsRef = useRef({
    emit: (event, ...params) => {
      if (unmountedRef.current) return
      configRef.current[event](...params)
    }
  })

what do you think?

@Lam9090
Copy link
Contributor Author

Lam9090 commented Jul 13, 2020

cc @shuding

@sergiodxa
Copy link
Contributor

This looks like a good idea, would you like to send a PR with the change? It would even great to run the whole test suite against it and probably add a few tests to ensure it works as you expect

@Lam9090
Copy link
Contributor Author

Lam9090 commented Jul 13, 2020

@sergiodxa
sure, would love to take it.

@akafaneh
Copy link

I've been struggling with an issue because of this, i'm relying on some redux state that gets updated a lot in the onError callback, and the fact that it only capture and and save the callback on first render made it impossible to get around the issue with a clean solution, so this fix would save a lot for me.

thanks

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

No branches or pull requests

3 participants