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

[DevTools] Make sure named hooks Suspense cache is persisting between elements #21822

Closed
bvaughn opened this issue Jul 7, 2021 · 2 comments · Fixed by #21831
Closed

[DevTools] Make sure named hooks Suspense cache is persisting between elements #21822

bvaughn opened this issue Jul 7, 2021 · 2 comments · Fixed by #21831

Comments

@bvaughn
Copy link
Contributor

bvaughn commented Jul 7, 2021

It currently looks like the map.get(element) returns undefined even for previously-loaded elements. Are we evicting from the cache prematurely? Why?

Our second level caching (inside of parseHookNames) is working but this is still resulting in a lot of unnecessary work.

@bvaughn
Copy link
Contributor Author

bvaughn commented Jul 8, 2021

Update: I am seeing what looks items getting evicted from the Suspense cache unexpectedly.

I added logging and verified that the elements are referentially equal between selections, but the cache is returning undefined – (the WeakMap has fewer items in it than it should). I changed from a WeakMap to a Map (even though the objects aren't being released so I wouldn't expect a difference) and the behavior is unchanged. I also added another WeakMap (not connected to the Suspense cache, just one managed by my module) and it retains the elements between selections, so it seems like the Suspense cache map is specifically doing something unexpected here.

@bvaughn
Copy link
Contributor Author

bvaughn commented Jul 8, 2021

This is caused by useCacheRefresh blowing away all caches, not just the one being reset. I have a repro here: https://codesandbox.io/s/fragrant-wood-n7vx4?file=/src/caches.js

Apparently it is a known limitation of the current API. I've posted about it on the WG thread: reactwg/react-18#25 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant