Unverified Commit 30c64ba0 authored by Wyatt Johnson's avatar Wyatt Johnson Committed by GitHub

Fix interception route rewrites for nested dynamic routes (#84413)

### What?

Fixes interception routes with dynamic parameters that were generating
rewrite rules in an incorrect format, preventing proper URL rewriting by
Vercel and Next.js.

### Why?

The failing test
`parallel-routes-and-interception-nested-dynamic-routes` revealed that
interception routes with dynamic segments weren't working correctly when
deployed. The root cause was that the previous implementation using
`safePathToRegexp` produced rewrite destinations that weren't in a
format compatible with direct parameter substitution during the rewrite
process.

When the router tried to rewrite URLs to their intercepted destinations,
the parameter format prevented Vercel/Next.js from properly substituting
the captured values, causing routes to fail.

### How?

Completely rewrote the `generate-interception-routes-rewrites` logic to
use `getNamedRouteRegex` instead of `safePathToRegexp`. This ensures:

1. **Correct rewrite format**: Rewrites are now generated in a format
that allows direct parameter substitution
2. **Parameter consistency**: Source regex is generated first, then its
parameter reference is passed to destination generation to ensure
parameter names match for substitution
3. **Clean URLs**: Added `stripNormalizedSeparators` to prevent
`_NEXTSEP_` internal separator from leaking into client-facing URLs
4. **Stricter matching**: Updated router reducers to pass `next-url`
header for the stricter Next-Url regex matching required by the new
rewrite mechanism

**Testing:**
- Added 23 comprehensive tests for rewrite generation covering all
interception marker types
- Added 18 tests for route matching utilities
- All existing tests pass including the previously failing
`parallel-routes-and-interception-nested-dynamic-routes`

Fixes the failing test:
`test/e2e/app-dir/parallel-routes-and-interception-nested-dynamic-routes/parallel-routes-and-interception-nested-dynamic-routes.test.ts`

NAR-432
parent ec560204
...@@ -865,5 +865,7 @@ ...@@ -865,5 +865,7 @@
"864": "Missing value for segment key: \"%s\" with dynamic param type: %s", "864": "Missing value for segment key: \"%s\" with dynamic param type: %s",
"865": "`experimental.rdcForNavigations` is enabled, but `experimental.cacheComponents` is not.", "865": "`experimental.rdcForNavigations` is enabled, but `experimental.cacheComponents` is not.",
"866": "Both \"%s\" and \"%s\" files are detected. Please use \"%s\" instead.", "866": "Both \"%s\" and \"%s\" files are detected. Please use \"%s\" instead.",
"867": "The %s \"%s\" must export a %s or a \\`default\\` function" "867": "The %s \"%s\" must export a %s or a \\`default\\` function",
"868": "No reference found for param: %s in reference: %s",
"869": "No reference found for segment: %s with reference: %s"
} }
...@@ -396,7 +396,7 @@ function Router({ ...@@ -396,7 +396,7 @@ function Router({
} }
}, []) }, [])
const { cache, tree, nextUrl, focusAndScrollRef } = state const { cache, tree, nextUrl, focusAndScrollRef, previousNextUrl } = state
const matchingHead = useMemo(() => { const matchingHead = useMemo(() => {
return findHeadInCache(cache, tree[1]) return findHeadInCache(cache, tree[1])
...@@ -423,8 +423,9 @@ function Router({ ...@@ -423,8 +423,9 @@ function Router({
tree, tree,
focusAndScrollRef, focusAndScrollRef,
nextUrl, nextUrl,
previousNextUrl,
} }
}, [tree, focusAndScrollRef, nextUrl]) }, [tree, focusAndScrollRef, nextUrl, previousNextUrl])
let head let head
if (matchingHead !== null) { if (matchingHead !== null) {
......
...@@ -389,7 +389,14 @@ function InnerLayoutRouter({ ...@@ -389,7 +389,14 @@ function InnerLayoutRouter({
new URL(url, location.origin), new URL(url, location.origin),
{ {
flightRouterState: refetchTree, flightRouterState: refetchTree,
nextUrl: includeNextUrl ? context.nextUrl : null, nextUrl: includeNextUrl
? // We always send the last next-url, not the current when
// performing a dynamic request. This is because we update
// the next-url after a navigation, but we want the same
// interception route to be matched that used the last
// next-url.
context.previousNextUrl || context.nextUrl
: null,
} }
).then((serverResponse) => { ).then((serverResponse) => {
startTransition(() => { startTransition(() => {
......
...@@ -138,6 +138,7 @@ describe('createInitialRouterState', () => { ...@@ -138,6 +138,7 @@ describe('createInitialRouterState', () => {
}, },
cache: expectedCache, cache: expectedCache,
nextUrl: '/linking', nextUrl: '/linking',
previousNextUrl: null,
} }
expect(state).toMatchObject(expected) expect(state).toMatchObject(expected)
......
...@@ -110,6 +110,7 @@ export function createInitialRouterState({ ...@@ -110,6 +110,7 @@ export function createInitialRouterState({
// the || operator is intentional, the pathname can be an empty string // the || operator is intentional, the pathname can be an empty string
(extractPathFromFlightRouterState(initialTree) || location?.pathname) ?? (extractPathFromFlightRouterState(initialTree) || location?.pathname) ??
null, null,
previousNextUrl: null,
} }
if (process.env.NODE_ENV !== 'development' && location) { if (process.env.NODE_ENV !== 'development' && location) {
......
...@@ -16,6 +16,7 @@ export function handleMutable( ...@@ -16,6 +16,7 @@ export function handleMutable(
// shouldScroll is true by default, can override to false. // shouldScroll is true by default, can override to false.
const shouldScroll = mutable.shouldScroll ?? true const shouldScroll = mutable.shouldScroll ?? true
let previousNextUrl = state.previousNextUrl
let nextUrl = state.nextUrl let nextUrl = state.nextUrl
if (isNotUndefined(mutable.patchedTree)) { if (isNotUndefined(mutable.patchedTree)) {
...@@ -23,6 +24,7 @@ export function handleMutable( ...@@ -23,6 +24,7 @@ export function handleMutable(
const changedPath = computeChangedPath(state.tree, mutable.patchedTree) const changedPath = computeChangedPath(state.tree, mutable.patchedTree)
if (changedPath) { if (changedPath) {
// If the tree changed, we need to update the nextUrl // If the tree changed, we need to update the nextUrl
previousNextUrl = nextUrl
nextUrl = changedPath nextUrl = changedPath
} else if (!nextUrl) { } else if (!nextUrl) {
// if the tree ends up being the same (ie, no changed path), and we don't have a nextUrl, then we should use the canonicalUrl // if the tree ends up being the same (ie, no changed path), and we don't have a nextUrl, then we should use the canonicalUrl
...@@ -84,5 +86,6 @@ export function handleMutable( ...@@ -84,5 +86,6 @@ export function handleMutable(
? mutable.patchedTree ? mutable.patchedTree
: state.tree, : state.tree,
nextUrl, nextUrl,
previousNextUrl: previousNextUrl,
} }
} }
...@@ -391,7 +391,12 @@ export function navigateReducer( ...@@ -391,7 +391,12 @@ export function navigateReducer(
new URL(updatedCanonicalUrl, url.origin), new URL(updatedCanonicalUrl, url.origin),
{ {
flightRouterState: dynamicRequestTree, flightRouterState: dynamicRequestTree,
nextUrl: state.nextUrl, // We always send the last next-url, not the current when
// performing a dynamic request. This is because we update
// the next-url after a navigation, but we want the same
// interception route to be matched that used the last
// next-url.
nextUrl: state.previousNextUrl || state.nextUrl,
} }
) )
......
...@@ -45,5 +45,6 @@ export function restoreReducer( ...@@ -45,5 +45,6 @@ export function restoreReducer(
// Restore provided tree // Restore provided tree
tree: treeToRestore, tree: treeToRestore,
nextUrl: extractPathFromFlightRouterState(treeToRestore) ?? url.pathname, nextUrl: extractPathFromFlightRouterState(treeToRestore) ?? url.pathname,
previousNextUrl: null,
} }
} }
...@@ -257,8 +257,14 @@ export function serverActionReducer( ...@@ -257,8 +257,14 @@ export function serverActionReducer(
// Otherwise the server action might be intercepted with the wrong action id // Otherwise the server action might be intercepted with the wrong action id
// (ie, one that corresponds with the intercepted route) // (ie, one that corresponds with the intercepted route)
const nextUrl = const nextUrl =
state.nextUrl && hasInterceptionRouteInCurrentTree(state.tree) // We always send the last next-url, not the current when
? state.nextUrl // performing a dynamic request. This is because we update
// the next-url after a navigation, but we want the same
// interception route to be matched that used the last
// next-url.
(state.previousNextUrl || state.nextUrl) &&
hasInterceptionRouteInCurrentTree(state.tree)
? state.previousNextUrl || state.nextUrl
: null : null
const navigatedAt = Date.now() const navigatedAt = Date.now()
......
...@@ -254,6 +254,11 @@ export type AppRouterState = { ...@@ -254,6 +254,11 @@ export type AppRouterState = {
* The underlying "url" representing the UI state, which is used for intercepting routes. * The underlying "url" representing the UI state, which is used for intercepting routes.
*/ */
nextUrl: string | null nextUrl: string | null
/**
* The previous next-url that was used previous to a dynamic navigation.
*/
previousNextUrl: string | null
} }
export type ReadonlyReducerState = Readonly<AppRouterState> export type ReadonlyReducerState = Readonly<AppRouterState>
......
...@@ -45,7 +45,19 @@ export function buildCustomRoute( ...@@ -45,7 +45,19 @@ export function buildCustomRoute(
) )
} }
const regex = normalizeRouteRegex(source) // If this is an internal rewrite and it already provides a regex, use it
// otherwise, normalize the source to a regex.
let regex: string
if (
!route.internal ||
type !== 'rewrite' ||
!('regex' in route) ||
typeof route.regex !== 'string'
) {
regex = normalizeRouteRegex(source)
} else {
regex = route.regex
}
if (type !== 'redirect') { if (type !== 'redirect') {
return { ...route, regex } return { ...route, regex }
......
...@@ -31,6 +31,11 @@ export type Rewrite = { ...@@ -31,6 +31,11 @@ export type Rewrite = {
* @internal - used internally for routing * @internal - used internally for routing
*/ */
internal?: boolean internal?: boolean
/**
* @internal - used internally for routing
*/
regex?: string
} }
export type Header = { export type Header = {
......
...@@ -4,7 +4,7 @@ import type { NextConfigComplete } from '../../config-shared' ...@@ -4,7 +4,7 @@ import type { NextConfigComplete } from '../../config-shared'
import type { RenderServer, initialize } from '../router-server' import type { RenderServer, initialize } from '../router-server'
import type { PatchMatcher } from '../../../shared/lib/router/utils/path-match' import type { PatchMatcher } from '../../../shared/lib/router/utils/path-match'
import type { Redirect } from '../../../types' import type { Redirect } from '../../../types'
import type { Header, Rewrite } from '../../../lib/load-custom-routes' import type { Header } from '../../../lib/load-custom-routes'
import type { UnwrapPromise } from '../../../lib/coalesced-function' import type { UnwrapPromise } from '../../../lib/coalesced-function'
import type { NextUrlWithParsedQuery } from '../../request-meta' import type { NextUrlWithParsedQuery } from '../../request-meta'
...@@ -42,12 +42,8 @@ import type { TLSSocket } from 'tls' ...@@ -42,12 +42,8 @@ import type { TLSSocket } from 'tls'
import { import {
NEXT_REWRITTEN_PATH_HEADER, NEXT_REWRITTEN_PATH_HEADER,
NEXT_REWRITTEN_QUERY_HEADER, NEXT_REWRITTEN_QUERY_HEADER,
NEXT_ROUTER_STATE_TREE_HEADER,
RSC_HEADER, RSC_HEADER,
} from '../../../client/components/app-router-headers' } from '../../../client/components/app-router-headers'
import { getSelectedParams } from '../../../client/components/router-reducer/compute-changed-path'
import { isInterceptionRouteRewrite } from '../../../lib/generate-interception-routes-rewrites'
import { parseAndValidateFlightRouterState } from '../../app-render/parse-and-validate-flight-router-state'
const debug = setupDebug('next:router-server:resolve-routes') const debug = setupDebug('next:router-server:resolve-routes')
...@@ -775,27 +771,6 @@ export function getResolveRoutes( ...@@ -775,27 +771,6 @@ export function getResolveRoutes(
if (route.destination) { if (route.destination) {
let rewriteParams = params let rewriteParams = params
try {
// An interception rewrite might reference a dynamic param for a route the user
// is currently on, which wouldn't be extractable from the matched route params.
// This attempts to extract the dynamic params from the provided router state.
if (isInterceptionRouteRewrite(route as Rewrite)) {
const stateHeader = req.headers[NEXT_ROUTER_STATE_TREE_HEADER]
if (stateHeader) {
rewriteParams = {
...getSelectedParams(
parseAndValidateFlightRouterState(stateHeader)
),
...params,
}
}
}
} catch (err) {
// this is a no-op -- we couldn't extract dynamic params from the provided router state,
// so we'll just use the params from the route matcher
}
const { parsedDestination } = prepareDestination({ const { parsedDestination } = prepareDestination({
appendParamsToQuery: true, appendParamsToQuery: true,
destination: route.destination, destination: route.destination,
......
...@@ -27,10 +27,6 @@ import { decodeQueryPathParameter } from './lib/decode-query-path-parameter' ...@@ -27,10 +27,6 @@ import { decodeQueryPathParameter } from './lib/decode-query-path-parameter'
import type { DeepReadonly } from '../shared/lib/deep-readonly' import type { DeepReadonly } from '../shared/lib/deep-readonly'
import { parseReqUrl } from '../lib/url' import { parseReqUrl } from '../lib/url'
import { formatUrl } from '../shared/lib/router/utils/format-url' import { formatUrl } from '../shared/lib/router/utils/format-url'
import { parseAndValidateFlightRouterState } from './app-render/parse-and-validate-flight-router-state'
import { isInterceptionRouteRewrite } from '../lib/generate-interception-routes-rewrites'
import { NEXT_ROUTER_STATE_TREE_HEADER } from '../client/components/app-router-headers'
import { getSelectedParams } from '../client/components/router-reducer/compute-changed-path'
function filterInternalQuery( function filterInternalQuery(
query: Record<string, undefined | string | string[]>, query: Record<string, undefined | string | string[]>,
...@@ -266,27 +262,6 @@ export function getServerUtils({ ...@@ -266,27 +262,6 @@ export function getServerUtils({
} }
if (params) { if (params) {
try {
// An interception rewrite might reference a dynamic param for a route the user
// is currently on, which wouldn't be extractable from the matched route params.
// This attempts to extract the dynamic params from the provided router state.
if (isInterceptionRouteRewrite(rewrite as Rewrite)) {
const stateHeader = req.headers[NEXT_ROUTER_STATE_TREE_HEADER]
if (stateHeader) {
params = {
...getSelectedParams(
parseAndValidateFlightRouterState(stateHeader)
),
...params,
}
}
}
} catch (err) {
// this is a no-op -- we couldn't extract dynamic params from the provided router state,
// so we'll just use the params from the route matcher
}
const { parsedDestination, destQuery } = prepareDestination({ const { parsedDestination, destQuery } = prepareDestination({
appendParamsToQuery: true, appendParamsToQuery: true,
destination: rewrite.destination, destination: rewrite.destination,
...@@ -303,20 +278,6 @@ export function getServerUtils({ ...@@ -303,20 +278,6 @@ export function getServerUtils({
Object.assign(rewrittenParsedUrl.query, parsedDestination.query) Object.assign(rewrittenParsedUrl.query, parsedDestination.query)
delete (parsedDestination as any).query delete (parsedDestination as any).query
// for each property in rewrittenParsedUrl.query, if the value is parametrized (eg :foo), look up the value
// in rewriteParams and replace the parametrized value with the actual value
// this is used when the rewrite destination does not contain the original source param
// and so the value is still parametrized and needs to be replaced with the actual rewrite param
Object.entries(rewrittenParsedUrl.query).forEach(([key, value]) => {
if (value && typeof value === 'string' && value.startsWith(':')) {
const paramName = value.slice(1)
const actualValue = rewriteParams[paramName]
if (actualValue) {
rewrittenParsedUrl.query[key] = actualValue
}
}
})
Object.assign(rewrittenParsedUrl, parsedDestination) Object.assign(rewrittenParsedUrl, parsedDestination)
fsPathname = rewrittenParsedUrl.pathname fsPathname = rewrittenParsedUrl.pathname
......
...@@ -68,6 +68,7 @@ export const GlobalLayoutRouterContext = React.createContext<{ ...@@ -68,6 +68,7 @@ export const GlobalLayoutRouterContext = React.createContext<{
tree: FlightRouterState tree: FlightRouterState
focusAndScrollRef: FocusAndScrollRef focusAndScrollRef: FocusAndScrollRef
nextUrl: string | null nextUrl: string | null
previousNextUrl: string | null
}>(null as any) }>(null as any)
export const TemplateContext = React.createContext<React.ReactNode>(null as any) export const TemplateContext = React.createContext<React.ReactNode>(null as any)
......
...@@ -43,3 +43,13 @@ export function getSegmentParam(segment: string): { ...@@ -43,3 +43,13 @@ export function getSegmentParam(segment: string): {
return null return null
} }
export function isCatchAll(
type: DynamicParamTypes
): type is 'catchall' | 'catchall-intercepted' | 'optional-catchall' {
return (
type === 'catchall' ||
type === 'catchall-intercepted' ||
type === 'optional-catchall'
)
}
...@@ -52,6 +52,13 @@ type GetNamedRouteRegexOptions = { ...@@ -52,6 +52,13 @@ type GetNamedRouteRegexOptions = {
* the routes-manifest during the build. * the routes-manifest during the build.
*/ */
backreferenceDuplicateKeys?: boolean backreferenceDuplicateKeys?: boolean
/**
* If provided, this will be used as the reference for the dynamic parameter
* keys instead of generating them in context. This is currently only used for
* interception routes.
*/
reference?: Record<string, string>
} }
type GetRouteRegexOptions = { type GetRouteRegexOptions = {
...@@ -242,9 +249,15 @@ function getSafeKeyFromSegment({ ...@@ -242,9 +249,15 @@ function getSafeKeyFromSegment({
pattern = `(?<${cleanedKey}>[^/]+?)` pattern = `(?<${cleanedKey}>[^/]+?)`
} }
return optional return {
key,
pattern: optional
? `(?:/${interceptionPrefix}${pattern})?` ? `(?:/${interceptionPrefix}${pattern})?`
: `/${interceptionPrefix}${pattern}` : `/${interceptionPrefix}${pattern}`,
cleanedKey: cleanedKey,
optional,
repeat,
}
} }
function getNamedParametrizedRoute( function getNamedParametrizedRoute(
...@@ -252,12 +265,18 @@ function getNamedParametrizedRoute( ...@@ -252,12 +265,18 @@ function getNamedParametrizedRoute(
prefixRouteKeys: boolean, prefixRouteKeys: boolean,
includeSuffix: boolean, includeSuffix: boolean,
includePrefix: boolean, includePrefix: boolean,
backreferenceDuplicateKeys: boolean backreferenceDuplicateKeys: boolean,
reference: Record<string, string> = {}
) { ) {
const getSafeRouteKey = buildGetSafeRouteKey() const getSafeRouteKey = buildGetSafeRouteKey()
const routeKeys: { [named: string]: string } = {} const routeKeys: { [named: string]: string } = {}
const segments: string[] = [] const segments: string[] = []
const inverseParts: string[] = []
// Ensure we don't mutate the original reference object.
reference = structuredClone(reference)
for (const segment of removeTrailingSlash(route).slice(1).split('/')) { for (const segment of removeTrailingSlash(route).slice(1).split('/')) {
const hasInterceptionMarker = INTERCEPTION_ROUTE_MARKERS.some((m) => const hasInterceptionMarker = INTERCEPTION_ROUTE_MARKERS.some((m) =>
segment.startsWith(m) segment.startsWith(m)
...@@ -267,7 +286,7 @@ function getNamedParametrizedRoute( ...@@ -267,7 +286,7 @@ function getNamedParametrizedRoute(
if (hasInterceptionMarker && paramMatches && paramMatches[2]) { if (hasInterceptionMarker && paramMatches && paramMatches[2]) {
// If there's an interception marker, add it to the segments. // If there's an interception marker, add it to the segments.
segments.push( const { key, pattern, cleanedKey, repeat, optional } =
getSafeKeyFromSegment({ getSafeKeyFromSegment({
getSafeRouteKey, getSafeRouteKey,
interceptionMarker: paramMatches[1], interceptionMarker: paramMatches[1],
...@@ -278,14 +297,21 @@ function getNamedParametrizedRoute( ...@@ -278,14 +297,21 @@ function getNamedParametrizedRoute(
: undefined, : undefined,
backreferenceDuplicateKeys, backreferenceDuplicateKeys,
}) })
segments.push(pattern)
inverseParts.push(
`/${paramMatches[1]}:${reference[key] ?? cleanedKey}${repeat ? (optional ? '*' : '+') : ''}`
) )
reference[key] ??= cleanedKey
} else if (paramMatches && paramMatches[2]) { } else if (paramMatches && paramMatches[2]) {
// If there's a prefix, add it to the segments if it's enabled. // If there's a prefix, add it to the segments if it's enabled.
if (includePrefix && paramMatches[1]) { if (includePrefix && paramMatches[1]) {
segments.push(`/${escapeStringRegexp(paramMatches[1])}`) segments.push(`/${escapeStringRegexp(paramMatches[1])}`)
inverseParts.push(`/${paramMatches[1]}`)
} }
let s = getSafeKeyFromSegment({ const { key, pattern, cleanedKey, repeat, optional } =
getSafeKeyFromSegment({
getSafeRouteKey, getSafeRouteKey,
segment: paramMatches[2], segment: paramMatches[2],
routeKeys, routeKeys,
...@@ -294,24 +320,33 @@ function getNamedParametrizedRoute( ...@@ -294,24 +320,33 @@ function getNamedParametrizedRoute(
}) })
// Remove the leading slash if includePrefix already added it. // Remove the leading slash if includePrefix already added it.
let s = pattern
if (includePrefix && paramMatches[1]) { if (includePrefix && paramMatches[1]) {
s = s.substring(1) s = s.substring(1)
} }
segments.push(s) segments.push(s)
inverseParts.push(
`/:${reference[key] ?? cleanedKey}${repeat ? (optional ? '*' : '+') : ''}`
)
reference[key] ??= cleanedKey
} else { } else {
segments.push(`/${escapeStringRegexp(segment)}`) segments.push(`/${escapeStringRegexp(segment)}`)
inverseParts.push(`/${segment}`)
} }
// If there's a suffix, add it to the segments if it's enabled. // If there's a suffix, add it to the segments if it's enabled.
if (includeSuffix && paramMatches && paramMatches[3]) { if (includeSuffix && paramMatches && paramMatches[3]) {
segments.push(escapeStringRegexp(paramMatches[3])) segments.push(escapeStringRegexp(paramMatches[3]))
inverseParts.push(paramMatches[3])
} }
} }
return { return {
namedParameterizedRoute: segments.join(''), namedParameterizedRoute: segments.join(''),
routeKeys, routeKeys,
pathToRegexpPattern: inverseParts.join(''),
reference,
} }
} }
...@@ -332,7 +367,8 @@ export function getNamedRouteRegex( ...@@ -332,7 +367,8 @@ export function getNamedRouteRegex(
options.prefixRouteKeys, options.prefixRouteKeys,
options.includeSuffix ?? false, options.includeSuffix ?? false,
options.includePrefix ?? false, options.includePrefix ?? false,
options.backreferenceDuplicateKeys ?? false options.backreferenceDuplicateKeys ?? false,
options.reference
) )
let namedRegex = result.namedParameterizedRoute let namedRegex = result.namedParameterizedRoute
...@@ -344,6 +380,8 @@ export function getNamedRouteRegex( ...@@ -344,6 +380,8 @@ export function getNamedRouteRegex(
...getRouteRegex(normalizedRoute, options), ...getRouteRegex(normalizedRoute, options),
namedRegex: `^${namedRegex}$`, namedRegex: `^${namedRegex}$`,
routeKeys: result.routeKeys, routeKeys: result.routeKeys,
pathToRegexpPattern: result.pathToRegexpPattern,
reference: result.reference,
} }
} }
...@@ -375,7 +413,8 @@ export function getNamedMiddlewareRegex( ...@@ -375,7 +413,8 @@ export function getNamedMiddlewareRegex(
false, false,
false, false,
false, false,
false false,
undefined
) )
let catchAllGroupedRegex = catchAll ? '(?:(/.*)?)' : '' let catchAllGroupedRegex = catchAll ? '(?:(/.*)?)' : ''
return { return {
......
...@@ -83,10 +83,7 @@ describe('parallel-route-navigations', () => { ...@@ -83,10 +83,7 @@ describe('parallel-route-navigations', () => {
// If it's PPR or Cache Components, we'll see an immediate transition for // If it's PPR or Cache Components, we'll see an immediate transition for
// the client component. // the client component.
if ( if (process.env.__NEXT_EXPERIMENTAL_CACHE_COMPONENTS === 'true') {
process.env.__NEXT_EXPERIMENTAL_PPR === 'true' ||
process.env.__NEXT_EXPERIMENTAL_CACHE_COMPONENTS === 'true'
) {
await browser.waitForElementByCss( await browser.waitForElementByCss(
'[data-file="/[teamID]/sub/other-folder/page.tsx"]' '[data-file="/[teamID]/sub/other-folder/page.tsx"]'
) )
...@@ -106,19 +103,9 @@ describe('parallel-route-navigations', () => { ...@@ -106,19 +103,9 @@ describe('parallel-route-navigations', () => {
// Wait for the dynamic RSC request to lock, then unlock that request. // Wait for the dynamic RSC request to lock, then unlock that request.
await stable(async () => { await stable(async () => {
if ( // As Client Segment Cache is the default, we should see one dynamic
process.env.__NEXT_EXPERIMENTAL_PPR === 'true' ||
process.env.__NEXT_EXPERIMENTAL_CACHE_COMPONENTS === 'true' ||
process.env.__NEXT_EXPERIMENTAL_CLIENT_SEGMENT_CACHE === 'true'
) {
// When we're in PPR or Cache Components, we'll see one dynamic
// request. // request.
expect(hadLocked).toBe(1) expect(hadLocked).toBe(1)
} else {
// When we're not in PPR or Cache Components, we'll see two dynamic
// requests. One made to refetch each of the slots.
expect(hadLocked).toBe(2)
}
}) })
unlock() unlock()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment