-
Notifications
You must be signed in to change notification settings - Fork 49.9k
fix[devtools/useMemoCache]: implement a working copy of useMemoCache #27659
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
|
|
||
| const memoCache = fiber.updateQueue?.memoCache; | ||
| if (memoCache == null) { | ||
| return []; |
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.
Wouldn't this case need to write the cache?
Where is this implementation coming from?
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.
Compared to
| function useMemoCache(size: number): Array<any> { |
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.
i think the main difference is that it's using syntax sugar which the real version has to avoid because we prefer to avoid the bloated expansion of optional chains and such. this looks right at least, though +1 to just reusing the same implementation
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.
It should not do the same thing as the original implementation. Other hook implementations in this file actually don't mutate anything in Fiber or Hook object.
This can't be applied for useMemoCache and the main reason is its implementation: although it is a hook, it is not implemented in the same way as others. It doesn't update memoizedState on the Fiber, so we could see it in the chain with other hooks.
When inspectHooksOfFiber is called, it gets a Fiber as an argument, which is already "rendered", so we could traverse through Fiber.memoizedState and return values from there. For some reason, this doesn't work with useMemoCache, I've tried returning just memoCache.data[memoCache.index], but this implementation produces errors in the render function of the inspected component. I am guessing that it is somewhat related to useMemoCache's implementation.
05e7994 to
fba271f
Compare
fba271f to
105169b
Compare
josephsavona
left a comment
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.
Makes sense, thanks for explaining why this can't reuse the original implementation (and for implementing this, of course!)
#### Upstream Changes - facebook/react#27692 - facebook/react#27712 - facebook/react#27659
…acebook#27659) In facebook#27472 I've removed broken `useMemoCache` implementation and replaced it with a stub. It actually produces errors when trying to inspect components, which are compiled with Forget. The main difference from the implementation in facebook#26696 is that we are using corresponding `Fiber` here, which has patched `updateQueue` with `memoCache`. Previously we would check it on a hook object, which doesn't have `updateQueue`. Tested on pages, which are using Forget and by inspecting elements, which are transpiled with Forget.
…27659) In #27472 I've removed broken `useMemoCache` implementation and replaced it with a stub. It actually produces errors when trying to inspect components, which are compiled with Forget. The main difference from the implementation in #26696 is that we are using corresponding `Fiber` here, which has patched `updateQueue` with `memoCache`. Previously we would check it on a hook object, which doesn't have `updateQueue`. Tested on pages, which are using Forget and by inspecting elements, which are transpiled with Forget. DiffTrain build for commit aec521a.
In #27472 I've removed broken
useMemoCacheimplementation and replaced it with a stub. It actually produces errors when trying to inspect components, which are compiled with Forget.The main difference from the implementation in #26696 is that we are using corresponding
Fiberhere, which has patchedupdateQueuewithmemoCache. Previously we would check it on a hook object, which doesn't haveupdateQueue.Tested on pages, which are using Forget and by inspecting elements, which are transpiled with Forget.