-
Notifications
You must be signed in to change notification settings - Fork 164
Optimized useTracker hook #273
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
Conversation
….warn if available
…fecycle deprecation notice
…ithTracker behavior - compare deps in order to keep API consistency to React.useEffect()
…cker() can be omitted - also React.memo() already has a check for prop change so there is no need to check for changed deps again
I also recommend silencing the warning by switching to the UNSAFE prefixed lifecycle methods for v1.0.0 |
@StorytellerCZ @dburles Feel free to ping me if you don't hear back soon (say, this week). Seems good for Tiny to go through the exercise of publishing a core package, but of course I can do it too if need be. |
I think so too. There's a bit to take in here, but we have a fairly good idea on the process to release now so we can help with that side. @CaptainN I think it would make sense to open a new PR for Edit: I forgot this is a monorepo, that is a bit of a pain. I think there was some discussion around moving this package into its own repo as it's by far the most used, if not the only one these days. Perhaps |
I agree about keeping a v1 branch maintained, and maybe even backward compatible with older react version (somehow detect and use the UNSAFE prefixed for newer versions of react)? It is a mono repo, but the main grouped tests don't seem to have been wired together for a while, and I've ported the tests into the package directly in this PR, so it's ready to be split out. |
Another forum post about using state within |
Hi @CaptainN and all, now that 1.8.2 is published we can start working on publish this new version. Do we have any pending issues here? Any reported issue in the forums/slack that should be included in this conversation? |
This is very helpful for all of us using React! Awesome :) Would it be worth it to briefly think of a path forward towards supporting Suspense and concurrent mode with this hook? At least make sure that the current API would not have to be reworked and that it could be a minor release in the future? |
@filipenevola There is nothing outstanding that should prevent a review. There are some additional features I might like to add (specifically an API to specify a "shouldUpdate" method), but nothing that would hold up a review of at least the general approach we've taken here. |
@Floriferous Great care was taken to make sure this hook will work with Suspense, concurrent mode and Error Bounds (time slicing based features) without leaking memory or resources. Supporting Suspense API directly is a bit more of an effort, and probably not suitable for this hook because of it's generic nature. That said, there's no reason someone couldn't build a solution which supports Suspense for |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work, README content is amazing 😉
Version 2.0.0 of react-meteor-data is published 🎉 |
@filipenevola It would be awesome to close the corresponding issues linked in the PR description. Thanks a lot for merging! 🎉 |
@lightningboss done. if some of them are still pending we can open again, no problem. |
Great stuff! We should also now cut a v1 branch and publish it as 1.0.0 too. |
Awesome to see this committed and released, thanks @filipenevola, and congrats @CaptainN ! Just : since this went through so many attempts, approaches and refactorings through 3 successive PRs and 150+ commits in total, it would be best to squash into one commit ? |
@dburles I just created the Are you going to use v1? I would like to find someone that is going to use v1 then this person can lead the PR that we are going to merge and publish as 1.0.0 |
@yched I personally like to see all the changes then we can understand how we ended up in this state but maybe just me hehe 😉 |
There was a lot of discussion in 3 PRs and a lot of commits that lead to the way the current code is. It's actually enough that maybe I should write a summary and store that somewhere. Most of the work for V1 will be in documentation. There is already aPR to rename the deprecated methods. |
Yes, I already sent a message there also #274 (comment) |
Hi there, do you have a readme files for this? regards |
This PR is a roundup of the discussion (and builds on the work) in #262 and #271, and supersedes: #242, #252, #256, #263, #266, #267, #268.
It does the following:
useTracker
to for use as an alternative to withTracker in hooks based projects.Rewrites
withTracker
on top ofuseTracker
(issues Unsafe lifecycle methods were found within a strict-mode tree #256, React 16.3 => migration from componentWillMount and componentWillUpdate #252, componentWillMount vs componentDidMount #242 / PR [WIP] Update lifecycle methods for newer React #261)withTracker
and inuseTracker
if no deps are specified, but also allows asynchronous reactivity afterfirstRun
if deps are supplied, and properly responds to deps changes. This implementation is compatible with Concurrent Mode, React Suspense and Error Boundaries.useRef
. There was some concern that results from that may be randomly tossed, but for now (react 16.8.6) they are stable. Even if they are tossed, the only effect this will have on our implementation is that it'll recreate the computation on the next render.useEffect
. The main function runs when a new computation is created (beforereactiveFn
) and then if it returns a function, that function is run right before the computation is destroyed. I don't know if this is really all that useful in real world use cases, but it is useful for testing some internal behaviors. I left it undocumented for now.reactiveFn
.Since this bumps the react version requirement to 16.8, there has been some discussion about how to properly release this with a major version bump. One suggestion was to bump the old version to 1.0.0 which can receive updates separately, then release this update as 2.0.0.
I believe this is ready for review. (Third time's a charm!)
CC @hwillson @menelike @yched