Unverified Commit 554a1e3c authored by Sam Selikoff's avatar Sam Selikoff Committed by GitHub

Fix Navigation Inspector Continue Rendering with loading.tsx (#94355)

## Summary

- Add regression coverage for Navigation Inspector `Continue Rendering`
with a route-level `loading.tsx`
- Fix Instant Navigation lock timing by snapshotting the active lock
when a dynamic request starts
- Prevent inspector re-arm from trapping in-flight dynamic responses
behind the next capture lock

## Why

The Navigation Inspector recently changed `Continue Rendering` to re-arm
capture after releasing the current lock. That surfaced a race in the
lower-level Instant Navigation lock handling.

The flow was:

1. `Continue Rendering` deletes the `next-instant-navigation-testing`
cookie.
2. Deleting the cookie releases the current navigation lock and triggers
a soft refresh.
3. The inspector quickly writes a new pending cookie to re-arm capture.
4. A route-level `loading.tsx` navigation may still have dynamic data
applying from the unlock-triggered refresh.
5. Before this change, `fetchMissingDynamicData` waited on whichever
lock was active when the response was applied.

That meant the refresh response could accidentally see the newly
re-armed lock and suspend forever.

This surfaced with `loading.tsx` more reliably than inline Suspense
because the route-level loading boundary commits the segment loading
shell, then final content depends on the unlock refresh path. Inline
Suspense generally keeps the deferred dynamic work associated with the
original captured navigation, so it waits on the original lock and
resumes when that lock is released.

## Fix

Dynamic requests now capture the current navigation lock when the
request starts, then wait only on that specific lock when applying the
response.

This preserves the intended behavior:

- Requests started during a capture still wait for that capture to
release.
- Requests started after unlock are not blocked by a later re-arm.
- The inspector can continue re-arming capture without racing in-flight
refresh responses.

Conceptually, a dynamic request should wait on the lock that existed
when that request started, not whatever lock happens to exist later when
its response is applied.
parent 5b99d26d
...@@ -127,6 +127,8 @@ export type NavigationRequestAccumulation = { ...@@ -127,6 +127,8 @@ export type NavigationRequestAccumulation = {
scrollRef: ScrollRef | null scrollRef: ScrollRef | null
} }
export type NavigationLock = Promise<void> | null
const noop = () => {} const noop = () => {}
export function createInitialCacheNodeForHydration( export function createInitialCacheNodeForHydration(
...@@ -1383,7 +1385,8 @@ export function spawnDynamicRequests( ...@@ -1383,7 +1385,8 @@ export function spawnDynamicRequests(
// The original navigation's push/replace intent. Threaded through to the // The original navigation's push/replace intent. Threaded through to the
// server-patch retry logic so it can inherit the intent if the original // server-patch retry logic so it can inherit the intent if the original
// transition hasn't committed yet. // transition hasn't committed yet.
navigateType: 'push' | 'replace' navigateType: 'push' | 'replace',
navigationLock: NavigationLock
): void { ): void {
const dynamicRequestTree = task.dynamicRequestTree const dynamicRequestTree = task.dynamicRequestTree
if (dynamicRequestTree === null) { if (dynamicRequestTree === null) {
...@@ -1407,7 +1410,8 @@ export function spawnDynamicRequests( ...@@ -1407,7 +1410,8 @@ export function spawnDynamicRequests(
primaryUrl, primaryUrl,
nextUrl, nextUrl,
freshnessPolicy, freshnessPolicy,
routeCacheEntry routeCacheEntry,
navigationLock
) )
const separateRefreshUrls = accumulation.separateRefreshUrls const separateRefreshUrls = accumulation.separateRefreshUrls
...@@ -1459,7 +1463,8 @@ export function spawnDynamicRequests( ...@@ -1459,7 +1463,8 @@ export function spawnDynamicRequests(
// hard refresh. // hard refresh.
nextUrl, nextUrl,
freshnessPolicy, freshnessPolicy,
routeCacheEntry routeCacheEntry,
navigationLock
) )
) )
} }
...@@ -1697,7 +1702,8 @@ async function fetchMissingDynamicData( ...@@ -1697,7 +1702,8 @@ async function fetchMissingDynamicData(
url: URL, url: URL,
nextUrl: string | null, nextUrl: string | null,
freshnessPolicy: FreshnessPolicy, freshnessPolicy: FreshnessPolicy,
routeCacheEntry: FulfilledRouteCacheEntry | null routeCacheEntry: FulfilledRouteCacheEntry | null,
navigationLock: NavigationLock
): Promise<{ ): Promise<{
exitStatus: NavigationTaskExitStatus exitStatus: NavigationTaskExitStatus
url: URL url: URL
...@@ -1734,7 +1740,7 @@ async function fetchMissingDynamicData( ...@@ -1734,7 +1740,7 @@ async function fetchMissingDynamicData(
// writing the dynamic data. This allows tests to assert on the prefetched // writing the dynamic data. This allows tests to assert on the prefetched
// UI state. // UI state.
if (process.env.__NEXT_EXPOSE_TESTING_API) { if (process.env.__NEXT_EXPOSE_TESTING_API) {
await waitForNavigationLock() await waitForNavigationLock(navigationLock)
} }
// TODO: Implement Shell extraction as part of Cached Navigations. // TODO: Implement Shell extraction as part of Cached Navigations.
...@@ -2152,16 +2158,25 @@ function createDeferredRsc< ...@@ -2152,16 +2158,25 @@ function createDeferredRsc<
} }
/** /**
* Helper for the Instant Navigation Testing API. Waits for the navigation lock * Helper for the Instant Navigation Testing API. Snapshots the lock that is
* to be released before returning. The network request has already completed by * active when a navigation starts, so the navigation can wait for the same lock
* the time this is called, so this only delays writing the dynamic data. * even if another lock is acquired before its dynamic response is applied.
* *
* Not exposed in production builds by default. * Not exposed in production builds by default.
*/ */
async function waitForNavigationLock(): Promise<void> { export function getCurrentNavigationLock(): NavigationLock {
if (process.env.__NEXT_EXPOSE_TESTING_API) {
const { getCurrentNavigationLock: getCurrentLock } =
require('../segment-cache/navigation-testing-lock') as typeof import('../segment-cache/navigation-testing-lock')
return getCurrentLock()
}
return null
}
async function waitForNavigationLock(lock: NavigationLock): Promise<void> {
if (process.env.__NEXT_EXPOSE_TESTING_API) { if (process.env.__NEXT_EXPOSE_TESTING_API) {
const { waitForNavigationLockIfActive } = const { waitForNavigationLockIfActive } =
require('../segment-cache/navigation-testing-lock') as typeof import('../segment-cache/navigation-testing-lock') require('../segment-cache/navigation-testing-lock') as typeof import('../segment-cache/navigation-testing-lock')
await waitForNavigationLockIfActive() await waitForNavigationLockIfActive(lock)
} }
} }
...@@ -10,7 +10,7 @@ import { ...@@ -10,7 +10,7 @@ import {
} from '../../segment-cache/navigation' } from '../../segment-cache/navigation'
import { invalidateSegmentCacheEntries } from '../../segment-cache/cache' import { invalidateSegmentCacheEntries } from '../../segment-cache/cache'
import { hasInterceptionRouteInCurrentTree } from './has-interception-route-in-current-tree' import { hasInterceptionRouteInCurrentTree } from './has-interception-route-in-current-tree'
import { FreshnessPolicy } from '../ppr-navigations' import { FreshnessPolicy, getCurrentNavigationLock } from '../ppr-navigations'
import { import {
invalidateBfCache, invalidateBfCache,
UnknownDynamicStaleTime, UnknownDynamicStaleTime,
...@@ -61,6 +61,7 @@ export function refreshDynamicData( ...@@ -61,6 +61,7 @@ export function refreshDynamicData(
const currentRenderedSearch = state.renderedSearch const currentRenderedSearch = state.renderedSearch
const currentFlightRouterState = state.tree const currentFlightRouterState = state.tree
const scrollBehavior = ScrollBehavior.NoScroll const scrollBehavior = ScrollBehavior.NoScroll
const navigationLock = getCurrentNavigationLock()
// Create a NavigationSeed from the current FlightRouterState. // Create a NavigationSeed from the current FlightRouterState.
// TODO: Eventually we will store this type directly on the state object // TODO: Eventually we will store this type directly on the state object
...@@ -92,6 +93,7 @@ export function refreshDynamicData( ...@@ -92,6 +93,7 @@ export function refreshDynamicData(
nextUrlForRefresh, nextUrlForRefresh,
scrollBehavior, scrollBehavior,
navigateType, navigateType,
navigationLock,
null, null,
// Refresh navigations don't use route prediction, so there's no route // Refresh navigations don't use route prediction, so there's no route
// cache entry to mark as having a dynamic rewrite on mismatch. If a // cache entry to mark as having a dynamic rewrite on mismatch. If a
......
...@@ -6,6 +6,7 @@ import type { ...@@ -6,6 +6,7 @@ import type {
import { extractPathFromFlightRouterState } from '../compute-changed-path' import { extractPathFromFlightRouterState } from '../compute-changed-path'
import { import {
FreshnessPolicy, FreshnessPolicy,
getCurrentNavigationLock,
spawnDynamicRequests, spawnDynamicRequests,
startPPRNavigation, startPPRNavigation,
type NavigationRequestAccumulation, type NavigationRequestAccumulation,
...@@ -43,6 +44,7 @@ export function restoreReducer( ...@@ -43,6 +44,7 @@ export function restoreReducer(
const restoredUrl = action.url const restoredUrl = action.url
const restoredNextUrl = const restoredNextUrl =
extractPathFromFlightRouterState(treeToRestore) ?? restoredUrl.pathname extractPathFromFlightRouterState(treeToRestore) ?? restoredUrl.pathname
const navigationLock = getCurrentNavigationLock()
const now = Date.now() const now = Date.now()
// TODO: Store the dynamic stale time on the top-level state so it's known // TODO: Store the dynamic stale time on the top-level state so it's known
...@@ -89,7 +91,8 @@ export function restoreReducer( ...@@ -89,7 +91,8 @@ export function restoreReducer(
// to find and mark the entry. // to find and mark the entry.
null, null,
// History traversal always uses 'replace'. // History traversal always uses 'replace'.
'replace' 'replace',
navigationLock
) )
return completeTraverseNavigation( return completeTraverseNavigation(
state, state,
......
...@@ -67,7 +67,7 @@ import { ...@@ -67,7 +67,7 @@ import {
type ActionRevalidationKind, type ActionRevalidationKind,
} from '../../../../shared/lib/action-revalidation-kind' } from '../../../../shared/lib/action-revalidation-kind'
import { isExternalURL } from '../../app-router-utils' import { isExternalURL } from '../../app-router-utils'
import { FreshnessPolicy } from '../ppr-navigations' import { FreshnessPolicy, getCurrentNavigationLock } from '../ppr-navigations'
import { processFetch } from '../fetch-server-response' import { processFetch } from '../fetch-server-response'
import { import {
invalidateBfCache, invalidateBfCache,
...@@ -496,6 +496,7 @@ export function serverActionReducer( ...@@ -496,6 +496,7 @@ export function serverActionReducer(
false // hasDynamicRewrite false // hasDynamicRewrite
) )
} }
const navigationLock = getCurrentNavigationLock()
return navigateToKnownRoute( return navigateToKnownRoute(
now, now,
...@@ -511,6 +512,7 @@ export function serverActionReducer( ...@@ -511,6 +512,7 @@ export function serverActionReducer(
nextUrl, nextUrl,
scrollBehavior, scrollBehavior,
navigateType, navigateType,
navigationLock,
null, null,
// Server action redirects don't use route prediction - we already // Server action redirects don't use route prediction - we already
// have the route tree from the server response. If a mismatch occurs // have the route tree from the server response. If a mismatch occurs
......
...@@ -11,7 +11,7 @@ import { ...@@ -11,7 +11,7 @@ import {
navigateToKnownRoute, navigateToKnownRoute,
} from '../../segment-cache/navigation' } from '../../segment-cache/navigation'
import { refreshReducer } from './refresh-reducer' import { refreshReducer } from './refresh-reducer'
import { FreshnessPolicy } from '../ppr-navigations' import { FreshnessPolicy, getCurrentNavigationLock } from '../ppr-navigations'
export function serverPatchReducer( export function serverPatchReducer(
state: ReadonlyReducerState, state: ReadonlyReducerState,
...@@ -43,6 +43,7 @@ export function serverPatchReducer( ...@@ -43,6 +43,7 @@ export function serverPatchReducer(
const retryCanonicalUrl = createHrefFromUrl(retryUrl) const retryCanonicalUrl = createHrefFromUrl(retryUrl)
const retryNextUrl = action.nextUrl const retryNextUrl = action.nextUrl
const scrollBehavior = ScrollBehavior.Default const scrollBehavior = ScrollBehavior.Default
const navigationLock = getCurrentNavigationLock()
const now = Date.now() const now = Date.now()
return navigateToKnownRoute( return navigateToKnownRoute(
now, now,
...@@ -58,6 +59,7 @@ export function serverPatchReducer( ...@@ -58,6 +59,7 @@ export function serverPatchReducer(
retryNextUrl, retryNextUrl,
scrollBehavior, scrollBehavior,
navigateType, navigateType,
navigationLock,
null, null,
// Server patch (retry) navigations don't use route prediction. This is // Server patch (retry) navigations don't use route prediction. This is
// typically a retry after a previous mismatch, so the route was already // typically a retry after a previous mismatch, so the route was already
......
...@@ -26,9 +26,11 @@ function parseCookieValue(raw: string): InstantNavCookieState { ...@@ -26,9 +26,11 @@ function parseCookieValue(raw: string): InstantNavCookieState {
} }
try { try {
const parsed = JSON.parse(raw) const parsed = JSON.parse(raw)
if (Array.isArray(parsed) && parsed.length >= 3) { if (Array.isArray(parsed)) {
const rawState = parsed[2] if (parsed.length >= 3) {
return rawState === null ? 'mpa' : 'spa' const rawState = parsed[2]
return rawState === null ? 'mpa' : 'spa'
}
} }
} catch {} } catch {}
return 'pending' return 'pending'
...@@ -189,7 +191,11 @@ export function startListeningForInstantNavigationCookie(): void { ...@@ -189,7 +191,11 @@ export function startListeningForInstantNavigationCookie(): void {
if (state === 'pending') { if (state === 'pending') {
// External actor starting a new lock scope. // External actor starting a new lock scope.
if (lockState !== null) { if (lockState !== null) {
releaseLock() // This can be the delayed CookieStore event for the pending
// cookie that was already observed synchronously from
// document.cookie. Keep the existing lock identity so work that
// captured it keeps waiting on the same promise.
return
} }
acquireLock() acquireLock()
} }
...@@ -262,14 +268,23 @@ export function isNavigationLocked(): boolean { ...@@ -262,14 +268,23 @@ export function isNavigationLocked(): boolean {
return false return false
} }
export function getCurrentNavigationLock(): Promise<void> | null {
if (process.env.__NEXT_EXPOSE_TESTING_API) {
return lockState !== null ? lockState.promise : null
}
return null
}
/** /**
* Waits for the navigation lock to be released, if it's currently held. * Waits for the navigation lock to be released, if it's currently held.
* No-op if the lock is not acquired. * No-op if the lock is not acquired.
*/ */
export async function waitForNavigationLockIfActive(): Promise<void> { export async function waitForNavigationLockIfActive(
lock: Promise<void> | null = getCurrentNavigationLock()
): Promise<void> {
if (process.env.__NEXT_EXPOSE_TESTING_API) { if (process.env.__NEXT_EXPOSE_TESTING_API) {
if (lockState !== null) { if (lock !== null) {
await lockState.promise await lock
} }
} }
} }
...@@ -16,6 +16,8 @@ import { ...@@ -16,6 +16,8 @@ import {
startPPRNavigation, startPPRNavigation,
spawnDynamicRequests, spawnDynamicRequests,
FreshnessPolicy, FreshnessPolicy,
getCurrentNavigationLock,
type NavigationLock,
type NavigationRequestAccumulation, type NavigationRequestAccumulation,
} from '../router-reducer/ppr-navigations' } from '../router-reducer/ppr-navigations'
import { createHrefFromUrl } from '../router-reducer/create-href-from-url' import { createHrefFromUrl } from '../router-reducer/create-href-from-url'
...@@ -64,6 +66,8 @@ export function navigate( ...@@ -64,6 +66,8 @@ export function navigate(
scrollBehavior: ScrollBehavior, scrollBehavior: ScrollBehavior,
navigateType: 'push' | 'replace' navigateType: 'push' | 'replace'
): AppRouterState | Promise<AppRouterState> { ): AppRouterState | Promise<AppRouterState> {
let navigationLock: NavigationLock = null
// Instant Navigation Testing API: when the lock is active, ensure a // Instant Navigation Testing API: when the lock is active, ensure a
// prefetch task has been initiated before proceeding with the navigation. // prefetch task has been initiated before proceeding with the navigation.
// This guarantees that segment data requests are at least pending, even // This guarantees that segment data requests are at least pending, even
...@@ -74,6 +78,7 @@ export function navigate( ...@@ -74,6 +78,7 @@ export function navigate(
const { isNavigationLocked } = const { isNavigationLocked } =
require('./navigation-testing-lock') as typeof import('./navigation-testing-lock') require('./navigation-testing-lock') as typeof import('./navigation-testing-lock')
if (isNavigationLocked()) { if (isNavigationLocked()) {
navigationLock = getCurrentNavigationLock()
return ensurePrefetchThenNavigate( return ensurePrefetchThenNavigate(
state, state,
url, url,
...@@ -84,7 +89,8 @@ export function navigate( ...@@ -84,7 +89,8 @@ export function navigate(
nextUrl, nextUrl,
freshnessPolicy, freshnessPolicy,
scrollBehavior, scrollBehavior,
navigateType navigateType,
navigationLock
) )
} }
} }
...@@ -99,7 +105,8 @@ export function navigate( ...@@ -99,7 +105,8 @@ export function navigate(
nextUrl, nextUrl,
freshnessPolicy, freshnessPolicy,
scrollBehavior, scrollBehavior,
navigateType navigateType,
navigationLock
) )
} }
...@@ -113,7 +120,8 @@ function navigateImpl( ...@@ -113,7 +120,8 @@ function navigateImpl(
nextUrl: string | null, nextUrl: string | null,
freshnessPolicy: FreshnessPolicy, freshnessPolicy: FreshnessPolicy,
scrollBehavior: ScrollBehavior, scrollBehavior: ScrollBehavior,
navigateType: 'push' | 'replace' navigateType: 'push' | 'replace',
navigationLock: NavigationLock
): AppRouterState | Promise<AppRouterState> { ): AppRouterState | Promise<AppRouterState> {
const now = Date.now() const now = Date.now()
const href = url.href const href = url.href
...@@ -134,7 +142,8 @@ function navigateImpl( ...@@ -134,7 +142,8 @@ function navigateImpl(
freshnessPolicy, freshnessPolicy,
scrollBehavior, scrollBehavior,
navigateType, navigateType,
route route,
navigationLock
) )
} }
...@@ -170,7 +179,8 @@ function navigateImpl( ...@@ -170,7 +179,8 @@ function navigateImpl(
freshnessPolicy, freshnessPolicy,
scrollBehavior, scrollBehavior,
navigateType, navigateType,
optimisticRoute optimisticRoute,
navigationLock
) )
} }
} }
...@@ -192,7 +202,8 @@ function navigateImpl( ...@@ -192,7 +202,8 @@ function navigateImpl(
currentFlightRouterState, currentFlightRouterState,
freshnessPolicy, freshnessPolicy,
scrollBehavior, scrollBehavior,
navigateType navigateType,
navigationLock
).catch(() => { ).catch(() => {
// If the navigation fails, return the current state // If the navigation fails, return the current state
return state return state
...@@ -213,6 +224,7 @@ export function navigateToKnownRoute( ...@@ -213,6 +224,7 @@ export function navigateToKnownRoute(
nextUrl: string | null, nextUrl: string | null,
scrollBehavior: ScrollBehavior, scrollBehavior: ScrollBehavior,
navigateType: 'push' | 'replace', navigateType: 'push' | 'replace',
navigationLock: NavigationLock,
debugInfo: Array<unknown> | null, debugInfo: Array<unknown> | null,
// The route cache entry used for this navigation, if it came from route // The route cache entry used for this navigation, if it came from route
// prediction. Passed through so it can be marked as having a dynamic rewrite // prediction. Passed through so it can be marked as having a dynamic rewrite
...@@ -276,7 +288,8 @@ export function navigateToKnownRoute( ...@@ -276,7 +288,8 @@ export function navigateToKnownRoute(
freshnessPolicy, freshnessPolicy,
accumulation, accumulation,
routeCacheEntry, routeCacheEntry,
navigateType navigateType,
navigationLock
) )
} }
return completeSoftNavigation( return completeSoftNavigation(
...@@ -309,7 +322,8 @@ function navigateUsingPrefetchedRouteTree( ...@@ -309,7 +322,8 @@ function navigateUsingPrefetchedRouteTree(
freshnessPolicy: FreshnessPolicy, freshnessPolicy: FreshnessPolicy,
scrollBehavior: ScrollBehavior, scrollBehavior: ScrollBehavior,
navigateType: 'push' | 'replace', navigateType: 'push' | 'replace',
route: FulfilledRouteCacheEntry route: FulfilledRouteCacheEntry,
navigationLock: NavigationLock
): AppRouterState { ): AppRouterState {
const routeTree = route.tree const routeTree = route.tree
const canonicalUrl = route.canonicalUrl + url.hash const canonicalUrl = route.canonicalUrl + url.hash
...@@ -336,6 +350,7 @@ function navigateUsingPrefetchedRouteTree( ...@@ -336,6 +350,7 @@ function navigateUsingPrefetchedRouteTree(
nextUrl, nextUrl,
scrollBehavior, scrollBehavior,
navigateType, navigateType,
navigationLock,
null, null,
route route
) )
...@@ -364,7 +379,8 @@ async function navigateToUnknownRoute( ...@@ -364,7 +379,8 @@ async function navigateToUnknownRoute(
currentFlightRouterState: FlightRouterState, currentFlightRouterState: FlightRouterState,
freshnessPolicy: FreshnessPolicy, freshnessPolicy: FreshnessPolicy,
scrollBehavior: ScrollBehavior, scrollBehavior: ScrollBehavior,
navigateType: 'push' | 'replace' navigateType: 'push' | 'replace',
navigationLock: NavigationLock
): Promise<AppRouterState> { ): Promise<AppRouterState> {
// Runs when a navigation happens but there's no cached prefetch we can use. // Runs when a navigation happens but there's no cached prefetch we can use.
// Don't bother to wait for a prefetch response; go straight to a full // Don't bother to wait for a prefetch response; go straight to a full
...@@ -529,6 +545,7 @@ async function navigateToUnknownRoute( ...@@ -529,6 +545,7 @@ async function navigateToUnknownRoute(
nextUrl, nextUrl,
scrollBehavior, scrollBehavior,
navigateType, navigateType,
navigationLock,
debugInfo, debugInfo,
// Unknown route navigations don't use route prediction - the route tree // Unknown route navigations don't use route prediction - the route tree
// came directly from the server. If a mismatch occurs during dynamic data // came directly from the server. If a mismatch occurs during dynamic data
...@@ -966,7 +983,8 @@ async function ensurePrefetchThenNavigate( ...@@ -966,7 +983,8 @@ async function ensurePrefetchThenNavigate(
nextUrl: string | null, nextUrl: string | null,
freshnessPolicy: FreshnessPolicy, freshnessPolicy: FreshnessPolicy,
scrollBehavior: ScrollBehavior, scrollBehavior: ScrollBehavior,
navigateType: 'push' | 'replace' navigateType: 'push' | 'replace',
navigationLock: NavigationLock
): Promise<AppRouterState> { ): Promise<AppRouterState> {
const link = getLinkForCurrentNavigation() const link = getLinkForCurrentNavigation()
const fetchStrategy = link !== null ? link.fetchStrategy : FetchStrategy.PPR const fetchStrategy = link !== null ? link.fetchStrategy : FetchStrategy.PPR
...@@ -996,7 +1014,8 @@ async function ensurePrefetchThenNavigate( ...@@ -996,7 +1014,8 @@ async function ensurePrefetchThenNavigate(
nextUrl, nextUrl,
freshnessPolicy, freshnessPolicy,
scrollBehavior, scrollBehavior,
navigateType navigateType,
navigationLock
) )
// Only transition to captured-SPA once the navigation is known to be an SPA. // Only transition to captured-SPA once the navigation is known to be an SPA.
......
export default function Loading() {
return <div>Loading await connection page...</div>
}
import { connection } from 'next/server'
export default async function TargetPage() {
await connection()
return (
<div>
<h1>Target Page</h1>
<div data-testid="dynamic-content">Dynamic content loaded</div>
</div>
)
}
...@@ -33,49 +33,41 @@ export default function Page() { ...@@ -33,49 +33,41 @@ export default function Page() {
</li> </li>
</ol> </ol>
<nav style={{ marginTop: '1.5rem' }}> <nav style={{ marginTop: '1.5rem' }}>
<Link <div>
href="/target-page/my-post?search=foo" <Link
id="link-to-target" href="/target-page/my-post?search=foo"
style={{ id="link-to-target"
display: 'inline-block', style={{
padding: '0.5rem 1rem', display: 'inline-block',
background: '#0070f3', padding: '0.5rem 1rem',
color: '#fff', background: '#0070f3',
borderRadius: 6, color: '#fff',
textDecoration: 'none', borderRadius: 6,
}} textDecoration: 'none',
> }}
Go to target page &rarr; >
</Link> Go to target page &rarr;
<Link </Link>
href="/mpa-target" <Link
id="link-to-mpa-target" href="/mpa-target"
style={{ id="link-to-mpa-target"
display: 'inline-block', style={{
marginLeft: '0.75rem', display: 'inline-block',
padding: '0.5rem 1rem', marginLeft: '0.75rem',
background: '#111', padding: '0.5rem 1rem',
color: '#fff', background: '#111',
borderRadius: 6, color: '#fff',
textDecoration: 'none', borderRadius: 6,
}} textDecoration: 'none',
> }}
Go to MPA target &rarr; >
</Link> Go to MPA target &rarr;
{/* <Link </Link>
href="/blocking-page?foo=bar" </div>
id="link-to-target"
style={{ <div>
display: 'inline-block', <Link href="/await-connection">Page with await connection</Link>
padding: '0.5rem 1rem', </div>
background: '#0070f3',
color: '#fff',
borderRadius: 6,
textDecoration: 'none',
}}
>
Go to blocking page
</Link> */}
</nav> </nav>
</div> </div>
) )
......
...@@ -13,8 +13,6 @@ describe.skip('instant-nav-panel', () => { ...@@ -13,8 +13,6 @@ describe.skip('instant-nav-panel', () => {
files: __dirname, files: __dirname,
}) })
const targetPage = '/target-page/my-post?search=foo'
async function waitForPanelRouterTransition() { async function waitForPanelRouterTransition() {
// Run all the necessary CSS transitions // Run all the necessary CSS transitions
// and click-outside event handler adjustment due to cascading update. // and click-outside event handler adjustment due to cascading update.
...@@ -301,12 +299,26 @@ describe.skip('instant-nav-panel', () => { ...@@ -301,12 +299,26 @@ describe.skip('instant-nav-panel', () => {
.waitFor({ state: 'visible', timeout: 30000 }) .waitFor({ state: 'visible', timeout: 30000 })
} }
async function expectAwaitConnectionPageLoading(browser: Playwright) {
await retry(
async () => {
const text = await browser.elementByCss('body').text()
expect(text).toContain('Loading await connection page...')
},
30_000,
500
)
expect(
await browser.locator('[data-testid="dynamic-content"]').count()
).toBe(0)
}
async function openHomeWithTargetPageWarmup() { async function openHomeWithTargetPageWarmup() {
const [browser] = await Promise.all([ const [browser] = await Promise.all([
next.browser('/'), next.browser('/'),
isNextDev && !isTurbopack isNextDev && !isTurbopack
? // warmup target page compilation before clicking Start, to avoid extra flakiness. ? // warmup target page compilation before clicking Start, to avoid extra flakiness.
next.render(targetPage).catch(() => {}) next.render('/target-page/my-post?search=foo').catch(() => {})
: null, : null,
]) ])
await clearInstantModeCookie(browser) await clearInstantModeCookie(browser)
...@@ -384,7 +396,7 @@ describe.skip('instant-nav-panel', () => { ...@@ -384,7 +396,7 @@ describe.skip('instant-nav-panel', () => {
describe('MPA captures', () => { describe('MPA captures', () => {
it('should show page load state after clicking Start and refreshing', async () => { it('should show page load state after clicking Start and refreshing', async () => {
const browser = await next.browser(targetPage) const browser = await next.browser('/target-page/my-post?search=foo')
await clearInstantModeCookie(browser) await clearInstantModeCookie(browser)
await openInstantNavPanel(browser) await openInstantNavPanel(browser)
...@@ -421,7 +433,7 @@ describe.skip('instant-nav-panel', () => { ...@@ -421,7 +433,7 @@ describe.skip('instant-nav-panel', () => {
}) })
it('should reset the panel and app when pressing the close button from captured MPA state', async () => { it('should reset the panel and app when pressing the close button from captured MPA state', async () => {
const browser = await next.browser(targetPage) const browser = await next.browser('/target-page/my-post?search=foo')
await clearInstantModeCookie(browser) await clearInstantModeCookie(browser)
await openInstantNavPanel(browser) await openInstantNavPanel(browser)
...@@ -441,7 +453,7 @@ describe.skip('instant-nav-panel', () => { ...@@ -441,7 +453,7 @@ describe.skip('instant-nav-panel', () => {
}) })
it('should keep params and searchParams RSC content suspended for a captured MPA page load', async () => { it('should keep params and searchParams RSC content suspended for a captured MPA page load', async () => {
const browser = await next.browser(targetPage) const browser = await next.browser('/target-page/my-post?search=foo')
await clearInstantModeCookie(browser) await clearInstantModeCookie(browser)
await openInstantNavPanel(browser) await openInstantNavPanel(browser)
...@@ -480,7 +492,7 @@ describe.skip('instant-nav-panel', () => { ...@@ -480,7 +492,7 @@ describe.skip('instant-nav-panel', () => {
}) })
it('should re-arm capture and return to awaiting navigation after Continue Rendering from MPA state', async () => { it('should re-arm capture and return to awaiting navigation after Continue Rendering from MPA state', async () => {
const browser = await next.browser(targetPage) const browser = await next.browser('/target-page/my-post?search=foo')
await clearInstantModeCookie(browser) await clearInstantModeCookie(browser)
await openInstantNavPanel(browser) await openInstantNavPanel(browser)
...@@ -519,7 +531,7 @@ describe.skip('instant-nav-panel', () => { ...@@ -519,7 +531,7 @@ describe.skip('instant-nav-panel', () => {
}) })
// Navigate to target page via SPA (use eval to bypass overlay pointer interception) // Navigate to target page via SPA (use eval to bypass overlay pointer interception)
await clickLink(browser, targetPage) await clickLink(browser, '/target-page/my-post?search=foo')
// Panel should transition to client navigation capture state // Panel should transition to client navigation capture state
await expectSpaPanel(browser) await expectSpaPanel(browser)
...@@ -537,7 +549,7 @@ describe.skip('instant-nav-panel', () => { ...@@ -537,7 +549,7 @@ describe.skip('instant-nav-panel', () => {
await clickStartCapturing(browser) await clickStartCapturing(browser)
// Navigate to target page via SPA (use eval to bypass overlay pointer interception) // Navigate to target page via SPA (use eval to bypass overlay pointer interception)
await clickLink(browser, targetPage) await clickLink(browser, '/target-page/my-post?search=foo')
// Dynamic data should be suspended under the lock. // Dynamic data should be suspended under the lock.
// Use a longer timeout because dev mode needs to compile the target page. // Use a longer timeout because dev mode needs to compile the target page.
...@@ -557,7 +569,7 @@ describe.skip('instant-nav-panel', () => { ...@@ -557,7 +569,7 @@ describe.skip('instant-nav-panel', () => {
await openInstantNavPanel(browser) await openInstantNavPanel(browser)
await clickStartCapturing(browser) await clickStartCapturing(browser)
await clickLink(browser, targetPage) await clickLink(browser, '/target-page/my-post?search=foo')
await expectSpaPanel(browser) await expectSpaPanel(browser)
await expectTargetPageSpaShell(browser) await expectTargetPageSpaShell(browser)
...@@ -575,7 +587,7 @@ describe.skip('instant-nav-panel', () => { ...@@ -575,7 +587,7 @@ describe.skip('instant-nav-panel', () => {
await openInstantNavPanel(browser) await openInstantNavPanel(browser)
await clickStartCapturing(browser) await clickStartCapturing(browser)
await clickLink(browser, targetPage) await clickLink(browser, '/target-page/my-post?search=foo')
await expectSpaPanel(browser) await expectSpaPanel(browser)
await expectTargetPageSpaShell(browser) await expectTargetPageSpaShell(browser)
...@@ -586,8 +598,23 @@ describe.skip('instant-nav-panel', () => { ...@@ -586,8 +598,23 @@ describe.skip('instant-nav-panel', () => {
await openInstantNavPanel(browser) await openInstantNavPanel(browser)
await clickStartCapturing(browser) await clickStartCapturing(browser)
await clickLink(browser, targetPage) await clickLink(browser, '/target-page/my-post?search=foo')
await expectSpaPanel(browser)
await clickContinueRendering(browser)
await expectPendingPanel(browser)
await expectTargetPageRendered(browser)
await waitForInstantModeCookie(browser)
})
it('should continue rendering a captured await connection navigation with loading.tsx', async () => {
const browser = await openHomeWithTargetPageWarmup()
await openInstantNavPanel(browser)
await clickStartCapturing(browser)
await clickLink(browser, '/await-connection')
await expectSpaPanel(browser) await expectSpaPanel(browser)
await expectAwaitConnectionPageLoading(browser)
await clickContinueRendering(browser) await clickContinueRendering(browser)
await expectPendingPanel(browser) await expectPendingPanel(browser)
...@@ -608,7 +635,7 @@ describe.skip('instant-nav-panel', () => { ...@@ -608,7 +635,7 @@ describe.skip('instant-nav-panel', () => {
await waitForInstantNavPanelOpen(browser) await waitForInstantNavPanelOpen(browser)
await expectMpaPanel(browser) await expectMpaPanel(browser)
await clickLink(browser, targetPage) await clickLink(browser, '/target-page/my-post?search=foo')
await expectSpaPanel(browser) await expectSpaPanel(browser)
await expectTargetPageSpaShell(browser) await expectTargetPageSpaShell(browser)
}) })
...@@ -618,7 +645,7 @@ describe.skip('instant-nav-panel', () => { ...@@ -618,7 +645,7 @@ describe.skip('instant-nav-panel', () => {
await openInstantNavPanel(browser) await openInstantNavPanel(browser)
await clickStartCapturing(browser) await clickStartCapturing(browser)
await clickLink(browser, targetPage) await clickLink(browser, '/target-page/my-post?search=foo')
await expectSpaPanel(browser) await expectSpaPanel(browser)
await browser.refresh() await browser.refresh()
......
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