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[devtools/useMemoCache]: add stub for useMemoCache in ReactDebugHook #27472

Merged

Conversation

hoxyq
Copy link
Contributor

@hoxyq hoxyq commented Oct 6, 2023

Currently, we have this error in our logs of the internal version of React DevTools:

TypeError: Cannot read properties of undefined (reading 'memoCache')
    at Proxy.useMemoCache (chrome-extension://dnjnjgbfilfphmojnmhliehogmojhclc/build/react_devtools_backend_compact.js:151:71)

Looking at the build files of the extension, it fails here:

if (
hook !== null &&
hook.updateQueue !== null &&
hook.updateQueue.memoCache != null
) {

Looks like updateQueue can be undefined, as it is not defined in hook object here:

export type Hook = {
memoizedState: any,
baseState: any,
baseQueue: Update<any, any> | null,
queue: any,
next: Hook | null,
};

Also, it looks like useMemoCache implementation doesn't expect this, so it should also result into TypeError here, line 1114:

function useMemoCache(size: number): Array<any> {
let memoCache = null;
// Fast-path, load memo cache from wip fiber if already prepared
let updateQueue: FunctionComponentUpdateQueue | null =
(currentlyRenderingFiber.updateQueue: any);
if (updateQueue !== null) {
memoCache = updateQueue.memoCache;
}

Should this also be updated?

@hoxyq hoxyq requested review from poteto and josephsavona October 6, 2023 14:18
@facebook-github-bot facebook-github-bot added CLA Signed React Core Team Opened by a member of the React Core Team labels Oct 6, 2023
@react-sizebot
Copy link

react-sizebot commented Oct 6, 2023

Comparing: 16619f1...1217280

Critical size changes

Includes critical production bundles, as well as any change greater than 2%:

Name +/- Base Current +/- gzip Base gzip Current gzip
oss-stable/react-dom/cjs/react-dom.production.min.js = 174.46 kB 174.46 kB = 54.27 kB 54.27 kB
oss-experimental/react-dom/cjs/react-dom.production.min.js = 176.31 kB 176.31 kB = 54.88 kB 54.88 kB
facebook-www/ReactDOM-prod.classic.js = 564.48 kB 564.48 kB = 99.37 kB 99.37 kB
facebook-www/ReactDOM-prod.modern.js = 548.21 kB 548.21 kB = 96.44 kB 96.44 kB
oss-experimental/react-debug-tools/cjs/react-debug-tools.production.min.js = 7.13 kB 6.83 kB = 2.66 kB 2.54 kB
oss-stable-semver/react-debug-tools/cjs/react-debug-tools.production.min.js = 7.13 kB 6.83 kB = 2.66 kB 2.54 kB
oss-stable/react-debug-tools/cjs/react-debug-tools.production.min.js = 7.13 kB 6.83 kB = 2.66 kB 2.54 kB

Significant size changes

Includes any change greater than 0.2%:

Expand to show
Name +/- Base Current +/- gzip Base gzip Current gzip
oss-experimental/react-debug-tools/cjs/react-debug-tools.development.js = 23.11 kB 22.67 kB = 6.27 kB 6.18 kB
oss-stable-semver/react-debug-tools/cjs/react-debug-tools.development.js = 23.11 kB 22.67 kB = 6.27 kB 6.18 kB
oss-stable/react-debug-tools/cjs/react-debug-tools.development.js = 23.11 kB 22.67 kB = 6.27 kB 6.18 kB
oss-experimental/react-debug-tools/cjs/react-debug-tools.production.min.js = 7.13 kB 6.83 kB = 2.66 kB 2.54 kB
oss-stable-semver/react-debug-tools/cjs/react-debug-tools.production.min.js = 7.13 kB 6.83 kB = 2.66 kB 2.54 kB
oss-stable/react-debug-tools/cjs/react-debug-tools.production.min.js = 7.13 kB 6.83 kB = 2.66 kB 2.54 kB

Generated by 🚫 dangerJS against 1217280

@sophiebits
Copy link
Collaborator

I think you are mixing up fiber.updateQueue and hook.updateQueue?

@hoxyq
Copy link
Contributor Author

hoxyq commented Oct 6, 2023

I think you are mixing up fiber.updateQueue and hook.updateQueue?

Oh, probably, but its only for the last point that I've mentioned about useMemoCache implementation, right?

@sophiebits
Copy link
Collaborator

I don't think the hook object ever has .updateQueue?

@hoxyq
Copy link
Contributor Author

hoxyq commented Oct 6, 2023

I don't think the hook object ever has .updateQueue?

Looks like it. For context, this field was added in #26696.

@josephsavona why aren't we using hook.memoizedState in useMemoCache implementation? Is it the only way to share value between hook's implementation and its shim in ReactDebugHooks?

@josephsavona
Copy link
Contributor

Discussed in our sync and the conclusion was that we don't think useMemoCache should be exposed in devtools. It's an implementation detail of Forget's memoization and not a hook that users should ever be calling directly. The fact that it's a hook is also an implementation detail.

So for now we'll remove from devtools and then we'll revisit whether we should show higher-level information from Forget in devtools. For example we could in theory show information about which sets of values Forget is memoizing, and what the inputs/ouputs of each of those units are.

@hoxyq hoxyq force-pushed the devtools/fix-use-memo-cache-undefined-type-error branch from 85429c7 to 7dadf27 Compare October 10, 2023 16:59
@hoxyq hoxyq changed the title fix[devtools/useMemoCache]: updateQueue can be undefined fix[devtools/useMemoCache]: add stub for useMemoCache in ReactDebugHook Oct 10, 2023
@hoxyq hoxyq force-pushed the devtools/fix-use-memo-cache-undefined-type-error branch from 7dadf27 to a5c6ea1 Compare October 10, 2023 17:06
@hoxyq
Copy link
Contributor Author

hoxyq commented Oct 10, 2023

Discussed in our sync and the conclusion was that we don't think useMemoCache should be exposed in devtools. It's an implementation detail of Forget's memoization and not a hook that users should ever be calling directly. The fact that it's a hook is also an implementation detail.

So for now we'll remove from devtools and then we'll revisit whether we should show higher-level information from Forget in devtools. For example we could in theory show information about which sets of values Forget is memoizing, and what the inputs/ouputs of each of those units are.

I've updated this PR accordingly.

Now, when user inspects component, which uses useMemoCache, it won't be listed under hooks section:
Screenshot 2023-10-10 at 18 00 31

Previously, we would list this hook here, because of updating hookLog object once this hook is called by dispatcher. With these changes it is just a stub now for ReactDebugHooks.

Copy link
Contributor

@josephsavona josephsavona left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice, thanks for flagging this and for updating!

@hoxyq hoxyq force-pushed the devtools/fix-use-memo-cache-undefined-type-error branch from a5c6ea1 to 1217280 Compare October 17, 2023 17:31
@hoxyq hoxyq merged commit a419575 into facebook:main Oct 17, 2023
2 checks passed
@hoxyq hoxyq deleted the devtools/fix-use-memo-cache-undefined-type-error branch October 17, 2023 17:39
kodiakhq bot pushed a commit to vercel/next.js that referenced this pull request Oct 18, 2023
hoxyq added a commit that referenced this pull request Oct 18, 2023
Changes:
* fix[devtools/useMemoCache]: add stub for useMemoCache in
ReactDebugHook ([hoxyq](https://github.com/hoxyq) in
[#27472](#27472))
* useDeferredValue should skip initialValue if it suspends
([acdlite](https://github.com/acdlite) in
[#27509](#27509))
* feat[react-devtools-extensions/logging]: initialize session id on the
client for logging ([hoxyq](https://github.com/hoxyq) in
[#27517](#27517))
* refactor[react-devtools-extensions]: use globals to eliminate dead
code ([hoxyq](https://github.com/hoxyq) in
[#27516](#27516))
* fix[devtools/inspectElement]: dont pause initial inspectElement call
when user switches tabs ([hoxyq](https://github.com/hoxyq) in
[#27488](#27488))
hoxyq added a commit that referenced this pull request Nov 14, 2023
…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.
EdisonVan pushed a commit to EdisonVan/react that referenced this pull request Apr 15, 2024
…ok (facebook#27472)

Currently, we have this error in our logs of the internal version of
React DevTools:
```
TypeError: Cannot read properties of undefined (reading 'memoCache')
    at Proxy.useMemoCache (chrome-extension://dnjnjgbfilfphmojnmhliehogmojhclc/build/react_devtools_backend_compact.js:151:71)
```

Looking at the build files of the extension, it fails here:
https://github.com/facebook/react/blob/dddfe688206dafa5646550d351eb9a8e9c53654a/packages/react-debug-tools/src/ReactDebugHooks.js#L333-L337

Looks like `updateQueue` can be `undefined`, as it is not defined in
hook object here:
https://github.com/facebook/react/blob/dddfe688206dafa5646550d351eb9a8e9c53654a/packages/react-reconciler/src/ReactFiberHooks.js#L180-L186

~~Also, it looks like `useMemoCache` implementation doesn't expect this,
so it should also result into TypeError here, line 1114:~~

https://github.com/facebook/react/blob/dddfe688206dafa5646550d351eb9a8e9c53654a/packages/react-reconciler/src/ReactFiberHooks.js#L1108-L1115

~~Should this also be updated?~~
EdisonVan pushed a commit to EdisonVan/react that referenced this pull request Apr 15, 2024
Changes:
* fix[devtools/useMemoCache]: add stub for useMemoCache in
ReactDebugHook ([hoxyq](https://github.com/hoxyq) in
[facebook#27472](facebook#27472))
* useDeferredValue should skip initialValue if it suspends
([acdlite](https://github.com/acdlite) in
[facebook#27509](facebook#27509))
* feat[react-devtools-extensions/logging]: initialize session id on the
client for logging ([hoxyq](https://github.com/hoxyq) in
[facebook#27517](facebook#27517))
* refactor[react-devtools-extensions]: use globals to eliminate dead
code ([hoxyq](https://github.com/hoxyq) in
[facebook#27516](facebook#27516))
* fix[devtools/inspectElement]: dont pause initial inspectElement call
when user switches tabs ([hoxyq](https://github.com/hoxyq) in
[facebook#27488](facebook#27488))
EdisonVan pushed a commit to EdisonVan/react that referenced this pull request Apr 15, 2024
…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.
bigfootjon pushed a commit that referenced this pull request Apr 18, 2024
…ok (#27472)

Currently, we have this error in our logs of the internal version of
React DevTools:
```
TypeError: Cannot read properties of undefined (reading 'memoCache')
    at Proxy.useMemoCache (chrome-extension://dnjnjgbfilfphmojnmhliehogmojhclc/build/react_devtools_backend_compact.js:151:71)
```

Looking at the build files of the extension, it fails here:
https://github.com/facebook/react/blob/dddfe688206dafa5646550d351eb9a8e9c53654a/packages/react-debug-tools/src/ReactDebugHooks.js#L333-L337

Looks like `updateQueue` can be `undefined`, as it is not defined in
hook object here:
https://github.com/facebook/react/blob/dddfe688206dafa5646550d351eb9a8e9c53654a/packages/react-reconciler/src/ReactFiberHooks.js#L180-L186

~~Also, it looks like `useMemoCache` implementation doesn't expect this,
so it should also result into TypeError here, line 1114:~~

https://github.com/facebook/react/blob/dddfe688206dafa5646550d351eb9a8e9c53654a/packages/react-reconciler/src/ReactFiberHooks.js#L1108-L1115

~~Should this also be updated?~~

DiffTrain build for commit a419575.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed React Core Team Opened by a member of the React Core Team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants