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

[Breaking] disable client router cache for page segments #66039

Merged
merged 2 commits into from
May 21, 2024

Conversation

ztanner
Copy link
Member

@ztanner ztanner commented May 21, 2024

This configures the default client router cache staleTime.dynamic value to be 0.

This means that:

  • Navigating between pages will always fire off a network request to get RSC data for the page segment, rather than restoring from router cache
  • Loading states will remain cached for 5 minutes (or whatever config.experimental.staleTimes.static is set to)
  • Shared layout data will continue to remain cached due to partial rendering
  • Back/forward behavior will still restore from cache to ensure the browser can restore scroll position.

It's possible to opt-out of this, and into the previous behavior, by setting the staleTimes config in next.config.js:

/** @type {import('next').NextConfig} */
const nextConfig = {
  experimental: {
    staleTimes: {
      dynamic: 30
    },
  },
}

module.exports = nextConfig

@ijjk ijjk added created-by: Next.js team PRs by the Next.js team. Documentation Related to Next.js' official documentation. tests type: next labels May 21, 2024
Copy link
Member Author

ztanner commented May 21, 2024

This stack of pull requests is managed by Graphite. Learn more about stacking.

Join @ztanner and the rest of your teammates on Graphite Graphite

@ztanner ztanner force-pushed the 05-21-disable_client_router_cache_for_page_segments branch from f165319 to 225c419 Compare May 21, 2024 15:58
@ztanner ztanner changed the title disable client router cache for page segments [Breaking] disable client router cache for page segments May 21, 2024
@ijjk
Copy link
Member

ijjk commented May 21, 2024

Tests Passed

@ijjk
Copy link
Member

ijjk commented May 21, 2024

Stats from current PR

Default Build (Increase detected ⚠️)
General
vercel/next.js canary vercel/next.js 05-21-disable_client_router_cache_for_page_segments Change
buildDuration 18.6s 16s N/A
buildDurationCached 10.2s 8.4s N/A
nodeModulesSize 347 MB 347 MB N/A
nextStartRea..uration (ms) 429ms 411ms N/A
Client Bundles (main, webpack)
vercel/next.js canary vercel/next.js 05-21-disable_client_router_cache_for_page_segments Change
2141-HASH.js gzip 33.5 kB 33.5 kB N/A
2592-HASH.js gzip 5.06 kB 5.06 kB N/A
48cf7de5-HASH.js gzip 51 kB 51 kB N/A
6539.HASH.js gzip 169 B 169 B
framework-HASH.js gzip 56 kB 56 kB N/A
main-app-HASH.js gzip 221 B 221 B
main-HASH.js gzip 32.3 kB 32.3 kB N/A
webpack-HASH.js gzip 1.7 kB 1.7 kB N/A
Overall change 390 B 390 B
Legacy Client Bundles (polyfills)
vercel/next.js canary vercel/next.js 05-21-disable_client_router_cache_for_page_segments Change
polyfills-HASH.js gzip 31 kB 31 kB
Overall change 31 kB 31 kB
Client Pages
vercel/next.js canary vercel/next.js 05-21-disable_client_router_cache_for_page_segments Change
_app-HASH.js gzip 193 B 193 B
_error-HASH.js gzip 191 B 192 B N/A
amp-HASH.js gzip 511 B 510 B N/A
css-HASH.js gzip 341 B 341 B
dynamic-HASH.js gzip 2.52 kB 2.53 kB N/A
edge-ssr-HASH.js gzip 265 B 266 B N/A
head-HASH.js gzip 363 B 365 B N/A
hooks-HASH.js gzip 392 B 392 B
image-HASH.js gzip 4.27 kB 4.27 kB N/A
index-HASH.js gzip 268 B 266 B N/A
link-HASH.js gzip 2.69 kB 2.69 kB N/A
routerDirect..HASH.js gzip 328 B 326 B N/A
script-HASH.js gzip 396 B 395 B N/A
withRouter-HASH.js gzip 325 B 321 B N/A
1afbb74e6ecf..834.css gzip 106 B 106 B
Overall change 1.03 kB 1.03 kB
Client Build Manifests
vercel/next.js canary vercel/next.js 05-21-disable_client_router_cache_for_page_segments Change
_buildManifest.js gzip 481 B 483 B N/A
Overall change 0 B 0 B
Rendered Page Sizes
vercel/next.js canary vercel/next.js 05-21-disable_client_router_cache_for_page_segments Change
index.html gzip 522 B 521 B N/A
link.html gzip 536 B 533 B N/A
withRouter.html gzip 518 B 517 B N/A
Overall change 0 B 0 B
Edge SSR bundle Size
vercel/next.js canary vercel/next.js 05-21-disable_client_router_cache_for_page_segments Change
edge-ssr.js gzip 124 kB 124 kB N/A
page.js gzip 184 kB 184 kB N/A
Overall change 0 B 0 B
Middleware size
vercel/next.js canary vercel/next.js 05-21-disable_client_router_cache_for_page_segments Change
middleware-b..fest.js gzip 657 B 656 B N/A
middleware-r..fest.js gzip 156 B 155 B N/A
middleware.js gzip 29.6 kB 29.6 kB N/A
edge-runtime..pack.js gzip 1.02 kB 1.02 kB
Overall change 1.02 kB 1.02 kB
Next Runtimes
vercel/next.js canary vercel/next.js 05-21-disable_client_router_cache_for_page_segments Change
app-page-exp...dev.js gzip 180 kB 180 kB
app-page-exp..prod.js gzip 111 kB 111 kB
app-page-tur..prod.js gzip 120 kB 120 kB
app-page-tur..prod.js gzip 97.7 kB 97.7 kB
app-page.run...dev.js gzip 163 kB 163 kB
app-page.run..prod.js gzip 96.3 kB 96.3 kB
app-route-ex...dev.js gzip 24.4 kB 24.4 kB
app-route-ex..prod.js gzip 18.3 kB 18.3 kB
app-route-tu..prod.js gzip 18.3 kB 18.3 kB
app-route-tu..prod.js gzip 18.1 kB 18.1 kB
app-route.ru...dev.js gzip 24.2 kB 24.2 kB
app-route.ru..prod.js gzip 18.1 kB 18.1 kB
pages-api-tu..prod.js gzip 9.53 kB 9.53 kB
pages-api.ru...dev.js gzip 9.8 kB 9.8 kB
pages-api.ru..prod.js gzip 9.53 kB 9.53 kB
pages-turbo...prod.js gzip 21.4 kB 21.4 kB
pages.runtim...dev.js gzip 22 kB 22 kB
pages.runtim..prod.js gzip 21.4 kB 21.4 kB
server.runti..prod.js gzip 52 kB 52 kB
Overall change 1.03 MB 1.03 MB
build cache Overall increase ⚠️
vercel/next.js canary vercel/next.js 05-21-disable_client_router_cache_for_page_segments Change
0.pack gzip 1.66 MB 1.66 MB ⚠️ +1.52 kB
index.pack gzip 128 kB 128 kB N/A
Overall change 1.66 MB 1.66 MB ⚠️ +1.52 kB
Diff details
Diff for page.js

Diff too large to display

Diff for middleware.js

Diff too large to display

Diff for edge-ssr.js

Diff too large to display

Diff for image-HASH.js
@@ -1,7 +1,7 @@
 (self["webpackChunk_N_E"] = self["webpackChunk_N_E"] || []).push([
   [8358],
   {
-    /***/ 5498: /***/ (
+    /***/ 8536: /***/ (
       __unused_webpack_module,
       __unused_webpack_exports,
       __webpack_require__
@@ -9,7 +9,7 @@
       (window.__NEXT_P = window.__NEXT_P || []).push([
         "/image",
         function () {
-          return __webpack_require__(8082);
+          return __webpack_require__(3672);
         },
       ]);
       if (false) {
@@ -18,7 +18,7 @@
       /***/
     },
 
-    /***/ 771: /***/ (module, exports, __webpack_require__) => {
+    /***/ 400: /***/ (module, exports, __webpack_require__) => {
       "use strict";
       /* __next_internal_client_entry_do_not_use__  cjs */
       Object.defineProperty(exports, "__esModule", {
@@ -40,15 +40,15 @@
         __webpack_require__(5614)
       );
       const _head = /*#__PURE__*/ _interop_require_default._(
-        __webpack_require__(1549)
+        __webpack_require__(2537)
       );
-      const _getimgprops = __webpack_require__(6472);
-      const _imageconfig = __webpack_require__(6915);
-      const _imageconfigcontextsharedruntime = __webpack_require__(3993);
-      const _warnonce = __webpack_require__(3260);
-      const _routercontextsharedruntime = __webpack_require__(4781);
+      const _getimgprops = __webpack_require__(4031);
+      const _imageconfig = __webpack_require__(8267);
+      const _imageconfigcontextsharedruntime = __webpack_require__(6469);
+      const _warnonce = __webpack_require__(5240);
+      const _routercontextsharedruntime = __webpack_require__(5635);
       const _imageloader = /*#__PURE__*/ _interop_require_default._(
-        __webpack_require__(933)
+        __webpack_require__(271)
       );
       // This is replaced by webpack define plugin
       const configEnv = {
@@ -376,7 +376,7 @@
       /***/
     },
 
-    /***/ 6472: /***/ (
+    /***/ 4031: /***/ (
       __unused_webpack_module,
       exports,
       __webpack_require__
@@ -392,9 +392,9 @@
           return getImgProps;
         },
       });
-      const _warnonce = __webpack_require__(3260);
-      const _imageblursvg = __webpack_require__(7851);
-      const _imageconfig = __webpack_require__(6915);
+      const _warnonce = __webpack_require__(5240);
+      const _imageblursvg = __webpack_require__(2682);
+      const _imageconfig = __webpack_require__(8267);
       const VALID_LOADING_VALUES =
         /* unused pure expression or super */ null && [
           "lazy",
@@ -769,7 +769,7 @@
       /***/
     },
 
-    /***/ 7851: /***/ (__unused_webpack_module, exports) => {
+    /***/ 2682: /***/ (__unused_webpack_module, exports) => {
       "use strict";
       /**
        * A shared function, used on both client and server, to generate a SVG blur placeholder.
@@ -824,7 +824,7 @@
       /***/
     },
 
-    /***/ 4770: /***/ (
+    /***/ 3669: /***/ (
       __unused_webpack_module,
       exports,
       __webpack_require__
@@ -851,10 +851,10 @@
         },
       });
       const _interop_require_default = __webpack_require__(1478);
-      const _getimgprops = __webpack_require__(6472);
-      const _imagecomponent = __webpack_require__(771);
+      const _getimgprops = __webpack_require__(4031);
+      const _imagecomponent = __webpack_require__(400);
       const _imageloader = /*#__PURE__*/ _interop_require_default._(
-        __webpack_require__(933)
+        __webpack_require__(271)
       );
       function getImageProps(imgProps) {
         const { props } = (0, _getimgprops.getImgProps)(imgProps, {
@@ -886,7 +886,7 @@
       /***/
     },
 
-    /***/ 933: /***/ (__unused_webpack_module, exports) => {
+    /***/ 271: /***/ (__unused_webpack_module, exports) => {
       "use strict";
 
       Object.defineProperty(exports, "__esModule", {
@@ -921,7 +921,7 @@
       /***/
     },
 
-    /***/ 8082: /***/ (
+    /***/ 3672: /***/ (
       __unused_webpack_module,
       __webpack_exports__,
       __webpack_require__
@@ -938,8 +938,8 @@
 
       // EXTERNAL MODULE: ./node_modules/.pnpm/[email protected]/node_modules/react/jsx-runtime.js
       var jsx_runtime = __webpack_require__(1847);
-      // EXTERNAL MODULE: ./node_modules/.pnpm/file+..+main-repo+packages+next+next-packed.tgz_react-dom@19.0.0-beta-04b058868c-20240508_rea_x6nrtfoohwvncerarvzrfulp2u/node_modules/next/image.js
-      var next_image = __webpack_require__(5945);
+      // EXTERNAL MODULE: ./node_modules/.pnpm/file+..+diff-repo+packages+next+next-packed.tgz_react-dom@19.0.0-beta-04b058868c-20240508_rea_dbavudu66yewnjanau4b4qzpou/node_modules/next/image.js
+      var next_image = __webpack_require__(7037);
       var image_default = /*#__PURE__*/ __webpack_require__.n(next_image); // CONCATENATED MODULE: ./pages/nextjs.png
       /* harmony default export */ const nextjs = {
         src: "/_next/static/media/nextjs.cae0b805.png",
@@ -969,12 +969,12 @@
       /***/
     },
 
-    /***/ 5945: /***/ (
+    /***/ 7037: /***/ (
       module,
       __unused_webpack_exports,
       __webpack_require__
     ) => {
-      module.exports = __webpack_require__(4770);
+      module.exports = __webpack_require__(3669);
 
       /***/
     },
@@ -984,7 +984,7 @@
     /******/ var __webpack_exec__ = (moduleId) =>
       __webpack_require__((__webpack_require__.s = moduleId));
     /******/ __webpack_require__.O(0, [2888, 9774, 179], () =>
-      __webpack_exec__(5498)
+      __webpack_exec__(8536)
     );
     /******/ var __webpack_exports__ = __webpack_require__.O();
     /******/ _N_E = __webpack_exports__;
Diff for main-HASH.js

Diff too large to display

Commit: d2ef105

@ztanner ztanner force-pushed the 05-21-disable_client_router_cache_for_page_segments branch from 0ae5999 to e180e42 Compare May 21, 2024 18:43
@@ -114,51 +114,6 @@ describe('app dir - prefetching', () => {
).toBe(1)
})

it('should not fetch again when a static page was prefetched when navigating to it twice', async () => {
Copy link
Member Author

Choose a reason for hiding this comment

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

these tests were moved into prefetching.staletimes.test.ts since they're no longer valid when the staletime values are left unconfigured.

@ztanner ztanner force-pushed the 05-21-disable_client_router_cache_for_page_segments branch from e180e42 to d2ef105 Compare May 21, 2024 19:21
@ztanner ztanner marked this pull request as ready for review May 21, 2024 20:38
@ztanner ztanner requested review from molebox and StephDietz and removed request for a team May 21, 2024 20:38
@ztanner ztanner merged commit 1f545af into canary May 21, 2024
82 checks passed
@ztanner ztanner deleted the 05-21-disable_client_router_cache_for_page_segments branch May 21, 2024 20:54
@github-actions github-actions bot added the locked label Jun 5, 2024
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 5, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
created-by: Next.js team PRs by the Next.js team. Documentation Related to Next.js' official documentation. locked tests type: next
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants