react icon indicating copy to clipboard operation
react copied to clipboard

Export unstable_useMemoCache in experimental server runtime

Open gsathya opened this issue 1 year ago • 5 comments

Flight already has an implementation of useMemoCache: https://github.com/facebook/react/blob/main/packages/react-server/src/ReactFlightHooks.js#L73-L79

This PR exports the existing hook.

gsathya avatar Mar 11 '24 17:03 gsathya

Comparing: dfaed5582550f11b27aae967a8e7084202dd2d90...9493aa7df0b276c1fee9aecd7d977d1fe5e5cdb8

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 = 177.10 kB 177.10 kB = 55.20 kB 55.20 kB
oss-experimental/react-dom/cjs/react-dom.production.min.js = 177.64 kB 177.64 kB = 55.53 kB 55.53 kB
facebook-www/ReactDOM-prod.classic.js = 594.34 kB 594.34 kB = 104.96 kB 104.96 kB
facebook-www/ReactDOM-prod.modern.js = 577.60 kB 577.60 kB = 102.02 kB 102.02 kB
test_utils/ReactAllWarnings.js Deleted 66.60 kB 0.00 kB Deleted 16.28 kB 0.00 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/cjs/react.react-server.production.min.js +0.79% 9.62 kB 9.70 kB +0.21% 3.84 kB 3.85 kB
oss-experimental/react/cjs/react.react-server.production.js +0.56% 39.92 kB 40.14 kB +0.39% 11.80 kB 11.84 kB
oss-experimental/react/cjs/react.react-server.development.js +0.27% 82.27 kB 82.49 kB +0.20% 23.13 kB 23.17 kB
test_utils/ReactAllWarnings.js Deleted 66.60 kB 0.00 kB Deleted 16.28 kB 0.00 kB

Generated by :no_entry_sign: dangerJS against 9493aa7df0b276c1fee9aecd7d977d1fe5e5cdb8

react-sizebot avatar Mar 11 '24 17:03 react-sizebot

It doesn't actually do anything so compiling a server layer with Forget would actually be a regression and arguably a bug. It should ideally error early if you do that.

sebmarkbage avatar Mar 12 '24 17:03 sebmarkbage

The same thing applies to Fizz in a way too btw since we're trying to replace the multi-pass renders there.

sebmarkbage avatar Mar 12 '24 17:03 sebmarkbage

Previous discussion in https://github.com/facebook/react/pull/27829

sebmarkbage avatar Mar 12 '24 17:03 sebmarkbage

It doesn't actually do anything so compiling a server layer with Forget would actually be a regression and arguably a bug. It should ideally error early if you do that.

@sebmarkbage is there a reliable way to know if the compiler is trying to compile a server component (and therefore bail out of it?)

poteto avatar Mar 12 '24 19:03 poteto

It varies by environment but since Server Components needs to compile in a separate layer of the bundler with a different set of compilers/plugins, you would typically simply exclude Forget from the compilation there.

sebmarkbage avatar Mar 13 '24 04:03 sebmarkbage

It doesn't actually do anything so compiling a server layer with Forget would actually be a regression and arguably a bug. It should ideally error early if you do that.

That makes sense but we've got potential optimisations planned that could help server components. I guess we could turn it on then, but maybe the safe default now is to run the compiler always but not do any memoization for server components?

gsathya avatar Mar 13 '24 15:03 gsathya