rsnext/packages
Josh Story 84aeded02f
Refactor unstable_cache implementation (#60403)
The original motivation of this PR is to get `unstable_cache` into a
state where I can more easily change the implementation of postpone to
be more akin to "dynamic rendering APIs". the existing approach made
typing the staticGenerationStore in a way I wanted to for the planned
changes would have been hard to implement with the current approach. At
the same time this was an opportunity to make the implementation more
efficient and easier to reason about.

reorganizes unstable_cache to improve performance and potentially fix
latent bugs related to nest cache calls

In the original implementation there are repeated defined checks for the
store and relatively complex logic around gathering the cache entry. In
my refactor I fork the implementation based on whether we have a store
or not. Loosely this translates to whether the cache call is for App
Router vs Pages Router however due to a quirk in how we scope inner
cache calls there is an existing and unchanged case where a Pages Router
cached callback runs with a "fake" store that is used to scope some
cache values to prevent inner caching when one cached function calls
another. It should be noted that this fake store technique means that
inner cache calls inside Pages Router will hit the App Router pathway in
unstable cache. This is not great but it is the current behavior and
while I have made some changes that might fix some bugs changing this
felt like a much bigger lift to do in a primarily refactor PR.

This "fake" store can be replaced by a different async store for Pages
Router which we can use to scope the inner environment to not be cached
eventually though it may make more sense to just generalize the
staticGenerationStore into a kind of RenderStore and have it run for
Pages Router too.

I moved as much computation that can be done in the closure around the
cached function out of the cached function and I narrowed the scope of
the run call to make it clear that we really only need to scope the
callback.

I removed function allocations per invocation

I probably fixed a bug in how the revalidate property was refined on the
static generation store. Previously it would be possible to go from
number to false and back again but this doesn't make sense as false is
more like INFINITY in terms of refining to shorter values. This PR
updates this logic to be apparently

Closes NEXT-2028
2024-01-09 08:56:27 -08:00
..
create-next-app v14.0.5-canary.45 2024-01-08 23:22:49 +00:00
eslint-config-next v14.0.5-canary.45 2024-01-08 23:22:49 +00:00
eslint-plugin-next v14.0.5-canary.45 2024-01-08 23:22:49 +00:00
font v14.0.5-canary.45 2024-01-08 23:22:49 +00:00
next Refactor unstable_cache implementation (#60403) 2024-01-09 08:56:27 -08:00
next-bundle-analyzer v14.0.5-canary.45 2024-01-08 23:22:49 +00:00
next-codemod v14.0.5-canary.45 2024-01-08 23:22:49 +00:00
next-env v14.0.5-canary.45 2024-01-08 23:22:49 +00:00
next-mdx v14.0.5-canary.45 2024-01-08 23:22:49 +00:00
next-plugin-storybook v14.0.5-canary.45 2024-01-08 23:22:49 +00:00
next-polyfill-module v14.0.5-canary.45 2024-01-08 23:22:49 +00:00
next-polyfill-nomodule v14.0.5-canary.45 2024-01-08 23:22:49 +00:00
next-swc v14.0.5-canary.45 2024-01-08 23:22:49 +00:00
react-dev-overlay v14.0.5-canary.45 2024-01-08 23:22:49 +00:00
react-refresh-utils v14.0.5-canary.45 2024-01-08 23:22:49 +00:00
third-parties v14.0.5-canary.45 2024-01-08 23:22:49 +00:00