Commit graph

5 commits

Author SHA1 Message Date
Jiachi Liu
7de1a4070d
Reland "app-router: new client-side cache semantics" (#48695)
Reverts vercel/next.js#48688
fix NEXT-1011
2023-04-22 10:41:08 +00:00
Jiachi Liu
8089d0a3bb
Revert "Reland app-router: new client-side cache semantics" (#48688)
Reverts vercel/next.js#48685

Temporary Revert again to investigate the hang job
fix NEXT-1011
2023-04-21 22:36:28 +02:00
Jiachi Liu
b61305afcc
Reland app-router: new client-side cache semantics (#48685)
Reland vercel/next.js#48383
fix NEXT-1011
2023-04-21 19:39:06 +00:00
Jiachi Liu
52fcc59717
Revert "app-router: new client-side cache semantics" (#48678)
Reverts vercel/next.js#48383
fix NEXT-1011

revert and re-land later
2023-04-21 17:21:58 +00:00
Jimmy Lai
658c600534
app-router: new client-side cache semantics (#48383)
This PR implements new cache semantics for the app router on the client.

## Context

Currently, on the App Router, every Link navigation is prefetched and
kept forever in the cache. This means that once you visit it, you will
always see the same version of the page for the duration of your
navigation.

## This PR

This PR introduces new semantics for how the App Router will cache
during navigations. Here's a TL;DR of the changes:
- all navigations (prefetched/unprefetched) are cached for a maximum of
30s from the time it was last accessed or created (in this order).
- in addition to this, the App Router will cache differently depending
on the `prefetch` prop passed to a `<Link>` component:
  - `prefetch={undefined}`/default behaviour:
- the router will prefetch the full page for static pages/partially for
dynamic pages
    - if accessed within 30s, it will use the cache
- after that, if accessed within 5 mins, it will re-fetch and suspend
below the nearest loading.js
- after those 5 mins, it will re-fetch the full content (with a new
loading.js boundary)
  - `prefetch={false}`:
    - the router will not prefetch anything
    - if accessed within 30s again, it will re-use the page
    - after that, it will re-fetch fully
  - `prefetch={true}`
- this will prefetch the full content of your page, dynamic or static
    - if accessed within 5 mins, it will re-use the page

## Follow ups

- we may add another API to control the cache TTL at the page level
- a way to opt-in for prefetch on hover even with prefetch={false}


<!-- Thanks for opening a PR! Your contribution is much appreciated.
To make sure your PR is handled as smoothly as possible we request that
you follow the checklist sections below.
Choose the right checklist for the change(s) that you're making:

## For Contributors

### Improving Documentation or adding/fixing Examples

- The "examples guidelines" are followed from our contributing doc
https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md
- Make sure the linting passes by running `pnpm build && pnpm lint`. See
https://github.com/vercel/next.js/blob/canary/contributing/repository/linting.md

### Fixing a bug

- Related issues linked using `fixes #number`
- Tests added. See:
https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs
- Errors have a helpful link attached, see
https://github.com/vercel/next.js/blob/canary/contributing.md

### Adding a feature

- Implements an existing feature request or RFC. Make sure the feature
request has been accepted for implementation before opening a PR. (A
discussion must be opened, see
https://github.com/vercel/next.js/discussions/new?category=ideas)
- Related issues/discussions are linked using `fixes #number`
- e2e tests added
(https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs
- Documentation added
- Telemetry added. In case of a feature if it's used or not.
- Errors have a helpful link attached, see
https://github.com/vercel/next.js/blob/canary/contributing.md



## For Maintainers

- Minimal description (aim for explaining to someone not on the team to
understand the PR)
- When linking to a Slack thread, you might want to share details of the
conclusion
- Link both the Linear (Fixes NEXT-xxx) and the GitHub issues
- Add review comments if necessary to explain to the reviewer the logic
behind a change

### What?

### Why?

### How?

Closes NEXT-
Fixes #

-->

link NEXT-1011
2023-04-21 14:29:39 +02:00