Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions crates/next-core/src/next_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -856,8 +856,6 @@ pub struct ExperimentalConfig {
/// directory.
ppr: Option<ExperimentalPartialPrerendering>,
taint: Option<bool>,
#[serde(rename = "routerBFCache")]
router_bfcache: Option<bool>,
proxy_timeout: Option<f64>,
/// enables the minification of server code.
server_minification: Option<bool>,
Expand Down
3 changes: 0 additions & 3 deletions packages/next/src/build/define-env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,9 +205,6 @@ export function getDefineEnv({
'process.env.__NEXT_DYNAMIC_ON_HOVER': Boolean(
config.experimental.dynamicOnHover
),
'process.env.__NEXT_ROUTER_BF_CACHE': Boolean(
config.experimental.routerBFCache
),
'process.env.__NEXT_OPTIMISTIC_CLIENT_CACHE':
config.experimental.optimisticClientCache ?? true,
'process.env.__NEXT_MIDDLEWARE_PREFETCH':
Expand Down
2 changes: 1 addition & 1 deletion packages/next/src/client/components/bfcache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { FlightRouterState } from '../../shared/lib/app-router-types'
import { useState } from 'react'

// When the flag is disabled, only track the currently active tree
const MAX_BF_CACHE_ENTRIES = process.env.__NEXT_ROUTER_BF_CACHE ? 3 : 1
const MAX_BF_CACHE_ENTRIES = process.env.__NEXT_CACHE_COMPONENTS ? 3 : 1

export type RouterBFCacheEntry = {
tree: FlightRouterState
Expand Down
2 changes: 1 addition & 1 deletion packages/next/src/client/components/layout-router.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -728,7 +728,7 @@ export default function OuterLayoutRouter({
)
}

if (process.env.__NEXT_ROUTER_BF_CACHE) {
if (process.env.__NEXT_CACHE_COMPONENTS) {
const boundaryName = getBoundaryNameForSuspenseDevTools(tree)
child = (
<Activity
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,11 @@ export function serverActionReducer(
redirectType || RedirectType.push
)
)

// TODO: Investigate why this is needed with Activity.
if (process.env.__NEXT_CACHE_COMPONENTS) {
return state
}
} else {
resolve(actionResult)
}
Expand Down
1 change: 0 additions & 1 deletion packages/next/src/server/config-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,6 @@ export const experimentalSchema = {
rootParams: z.boolean().optional(),
isolatedDevBuild: z.boolean().optional(),
mcpServer: z.boolean().optional(),
routerBFCache: z.boolean().optional(),
removeUncaughtErrorAndRejectionListeners: z.boolean().optional(),
validateRSCRequestHeaders: z.boolean().optional(),
scrollRestoration: z.boolean().optional(),
Expand Down
6 changes: 0 additions & 6 deletions packages/next/src/server/config-shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -591,11 +591,6 @@ export interface ExperimentalConfig {
*/
taint?: boolean

/**
* Enables the Back/Forward Cache for the router.
*/
routerBFCache?: boolean

/**
* Uninstalls all "unhandledRejection" and "uncaughtException" listeners from
* the global process so that we can override the behavior, which in some
Expand Down Expand Up @@ -1517,7 +1512,6 @@ export const defaultConfig = Object.freeze({
webpackMemoryOptimizations: false,
optimizeServerReact: true,
viewTransition: false,
routerBFCache: false,
removeUncaughtErrorAndRejectionListeners: false,
validateRSCRequestHeaders: !!(
process.env.__NEXT_TEST_MODE || !isStableBuild()
Expand Down
3 changes: 2 additions & 1 deletion test/e2e/app-dir/app-basepath/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,8 @@ describe('app dir - basepath', () => {
// This verifies the redirect & server response happens in a single roundtrip,
// if the redirect resource was static. In development, these responses are always
// dynamically generated, so we only expect a single request for build/deploy.
if (!isNextDev) {
// TODO(client-segment-cache): re-enable when this optimization is added back
if (!isNextDev && !process.env.__NEXT_CACHE_COMPONENTS) {
expect(requests).toHaveLength(1)
expect(responses).toHaveLength(1)
}
Expand Down
4 changes: 4 additions & 0 deletions test/e2e/app-dir/back-forward-cache/app/page/[n]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,7 @@ export default async function Page({
</>
)
}

export function generateStaticParams() {
return [{ n: '1' }, { n: '2' }]
}
4 changes: 1 addition & 3 deletions test/e2e/app-dir/back-forward-cache/next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@
* @type {import('next').NextConfig}
*/
const nextConfig = {
experimental: {
routerBFCache: true,
},
cacheComponents: true,
}

module.exports = nextConfig
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,11 @@ describe('parallel-routes-catchall-css', () => {
// the slot's background color should be red
expect(await getSlotBackgroundColor(browser)).toBe('rgb(255, 0, 0)')

// there should no longer be a main element
expect(await browser.hasElementByCssSelector('#main')).toBeFalsy()
// the main element should either not exist or not be visible
const mainDisplay = await browser.eval(
`document.querySelector('#main') ? window.getComputedStyle(document.querySelector('#main')).display : null`
)
expect(mainDisplay === null || mainDisplay === 'none').toBe(true)

// the slot background should still be red on a fresh load
await browser.refresh()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ export default function RootLayout({
}) {
return (
<html lang="en">
<body>{children}</body>
<body>
<div>{children}</div>
</body>
</html>
)
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { nextTestSetup } from 'e2e-utils'
import { waitFor } from 'next-test-utils'
import type * as Playwright from 'playwright'
import { createRouterAct } from 'router-act'

Expand Down Expand Up @@ -116,14 +117,6 @@ describe('runtime prefetching', () => {

await browser.back()

// Reveal the link to the second page again. It should not be prefetched again
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 reveals aren't necessary anymore, since state is restored, they were already revealed.

await act(async () => {
const linkToggle = await browser.elementByCss(
`input[data-link-accordion="/${prefix}/dynamic-params/456"]`
)
await linkToggle.click()
}, 'no-requests')

// Navigate to the other page
await act(async () => {
await act(
Expand Down Expand Up @@ -233,14 +226,6 @@ describe('runtime prefetching', () => {
if (!isNextDeploy) {
await browser.back()

// Reveal the link to the second page again. It should not be prefetched again
await act(async () => {
const linkToggle = await browser.elementByCss(
`input[data-link-accordion="/with-root-param/de/${prefix}/root-params"]`
)
await linkToggle.click()
}, 'no-requests')

// Navigate to the other page
await act(async () => {
await act(
Expand Down Expand Up @@ -348,14 +333,6 @@ describe('runtime prefetching', () => {

await browser.back()

// Reveal the link to the second page again. It should not be prefetched again
await act(async () => {
const linkToggle = await browser.elementByCss(
`input[data-link-accordion="/${prefix}/search-params?searchParam=456"]`
)
await linkToggle.click()
}, 'no-requests')

// Navigate to the other page
await act(
async () => {
Expand Down Expand Up @@ -495,23 +472,8 @@ describe('runtime prefetching', () => {
// Go back to the previous page
await browser.back()

// Reveal the link again to trigger a runtime prefetch for the new value of the cookie
await act(async () => {
const linkToggle = await browser.elementByCss(
`input[data-link-accordion="/${prefix}/cookies"]`
)
await linkToggle.click()
}, [
// Should allow reading dynamic params
{
includes: 'Cookie: updatedValue',
},
// Should not prefetch the dynamic content
{
includes: 'Dynamic content',
block: 'reject',
},
])
// wait a tick before navigating
await waitFor(500)

// Navigate to the page
await act(async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,10 +187,6 @@ describe('segment cache (staleness)', () => {
await page.clock.setFixedTime(startDate + 29 * 1000)

await act(async () => {
const toggle = await browser.elementByCss(
'input[data-link-accordion="/dynamic"]'
)
await toggle.click()
const link = await browser.elementByCss('a[href="/dynamic"]')
await link.click()
// The next page is immediately rendered
Expand All @@ -207,10 +203,6 @@ describe('segment cache (staleness)', () => {

await act(
async () => {
const toggle = await browser.elementByCss(
'input[data-link-accordion="/dynamic"]'
)
await toggle.click()
const link = await browser.elementByCss('a[href="/dynamic"]')
await link.click()
},
Expand Down
Loading