-
Notifications
You must be signed in to change notification settings - Fork 47.7k
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
[fresh] Reset useMemoCache in response to a FastRefresh run #30677
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
This PR introduces a new debug property on fibers to indicate that it is being rerendered as a result of a FastRefresh run. This allows React to clear the cache even where the size (incidentally) remains constant between renders: for example, if edited code _happens_ to keep the cache size the same but the code is meaningfully different such that it is no longer correct to reuse the cache. ghstack-source-id: 4984a3834adb18af06ffdbd5700406e1ba29a60d Pull Request resolved: #30677
Comparing: dd8e0ba...d2d5f30 Critical size changesIncludes critical production bundles, as well as any change greater than 2%:
Significant size changesIncludes any change greater than 0.2%: Expand to show
|
This PR introduces a new (dev only) debug property on fibers to indicate that it is being rerendered as a result of a FastRefresh run. This allows React to clear the cache even where the size (incidentally) remains constant between renders: for example, if edited code _happens_ to keep the cache size the same but the code is meaningfully different such that it is no longer correct to reuse the cache. ghstack-source-id: 4984a3834adb18af06ffdbd5700406e1ba29a60d Pull Request resolved: #30677
This PR introduces a new (dev only) debug property on fibers to indicate that it is being rerendered as a result of a FastRefresh run. This allows React to clear the cache even where the size (incidentally) remains constant between renders: for example, if edited code _happens_ to keep the cache size the same but the code is meaningfully different such that it is no longer correct to reuse the cache. ghstack-source-id: 4984a3834adb18af06ffdbd5700406e1ba29a60d Pull Request resolved: #30677
This PR introduces a new (dev only) debug property on fibers to indicate that it is being rerendered as a result of a FastRefresh run. This allows React to clear the cache even where the size (incidentally) remains constant between renders: for example, if edited code _happens_ to keep the cache size the same but the code is meaningfully different such that it is no longer correct to reuse the cache. ghstack-source-id: 9bf49f9ea20ca785c93d32c2f1f720d225d7d764 Pull Request resolved: #30677
Is it possible to use the module-level |
Also noticing the test passes even if I comment out |
This PR introduces a new (dev only) debug property on fibers to indicate that it is being rerendered as a result of a FastRefresh run. This allows React to clear the cache even where the size (incidentally) remains constant between renders: for example, if edited code _happens_ to keep the cache size the same but the code is meaningfully different such that it is no longer correct to reuse the cache. ghstack-source-id: d4b47584ad600e908ef51d271a96e89617bdb4e5 Pull Request resolved: #30677
This PR introduces a new (dev only) debug property on fibers to indicate that it is being rerendered as a result of a FastRefresh run. This allows React to clear the cache even where the size (incidentally) remains constant between renders: for example, if edited code _happens_ to keep the cache size the same but the code is meaningfully different such that it is no longer correct to reuse the cache. ghstack-source-id: 2e14ae4bf8aaf9070848138901585d47c2a98e21 Pull Request resolved: #30677
I think #30700 makes sense to me, any reason why we don't do that instead? |
Closing in favor of #30700 |
Stacked on #30662. Alternative to #30663 and #30677. During a Fast Refresh, we always want to evict the memo cache, same as we do with normal `useMemo`. The mechanism used by `useMemo` and other Hooks is this module-level variable: https://github.com/facebook/react/blob/fca5d655d78917400a2722287351c20938166669/packages/react-reconciler/src/ReactFiberHooks.js#L304-L307 which has DEV-only behavior as if the dependencies are always different: https://github.com/facebook/react/blob/fca5d655d78917400a2722287351c20938166669/packages/react-reconciler/src/ReactFiberHooks.js#L451-L460 The `useMemoCache` Hook doesn't use a dependency array but conceptually I think we want the same behavior. ## Test Plan The test passes. --------- Co-authored-by: Lauren Tan <[email protected]>
Stacked on #30662. Alternative to #30663 and #30677. During a Fast Refresh, we always want to evict the memo cache, same as we do with normal `useMemo`. The mechanism used by `useMemo` and other Hooks is this module-level variable: https://github.com/facebook/react/blob/fca5d655d78917400a2722287351c20938166669/packages/react-reconciler/src/ReactFiberHooks.js#L304-L307 which has DEV-only behavior as if the dependencies are always different: https://github.com/facebook/react/blob/fca5d655d78917400a2722287351c20938166669/packages/react-reconciler/src/ReactFiberHooks.js#L451-L460 The `useMemoCache` Hook doesn't use a dependency array but conceptually I think we want the same behavior. ## Test Plan The test passes. --------- Co-authored-by: Lauren Tan <[email protected]> DiffTrain build for [7e8a06c](7e8a06c)
Stacked on #30662. Alternative to #30663 and #30677. During a Fast Refresh, we always want to evict the memo cache, same as we do with normal `useMemo`. The mechanism used by `useMemo` and other Hooks is this module-level variable: https://github.com/facebook/react/blob/fca5d655d78917400a2722287351c20938166669/packages/react-reconciler/src/ReactFiberHooks.js#L304-L307 which has DEV-only behavior as if the dependencies are always different: https://github.com/facebook/react/blob/fca5d655d78917400a2722287351c20938166669/packages/react-reconciler/src/ReactFiberHooks.js#L451-L460 The `useMemoCache` Hook doesn't use a dependency array but conceptually I think we want the same behavior. ## Test Plan The test passes. --------- Co-authored-by: Lauren Tan <[email protected]> DiffTrain build for commit 7e8a06c.
Stack from ghstack (oldest at bottom):
This PR introduces a new (dev only) debug property on fibers to indicate
that it is being rerendered as a result of a FastRefresh run. This
allows React to clear the cache even where the size (incidentally)
remains constant between renders: for example, if edited code happens
to keep the cache size the same but the code is meaningfully different
such that it is no longer correct to reuse the cache.