Commit 06f01e59 authored by JJ Kasper's avatar JJ Kasper

Merge branch 'next-14-1' of github.com:vercel/next.js into next-14-1

parents c1edac79 6aee03de
......@@ -153,6 +153,7 @@ export function createEmptyCacheNode(): CacheNode {
rsc: null,
prefetchRsc: null,
parallelRoutes: new Map(),
lazyDataResolved: false,
}
}
......@@ -541,7 +542,6 @@ function Router({
return
}
// @ts-ignore useTransition exists
// TODO-APP: Ideally the back button should not use startTransition as it should apply the updates synchronously
// Without startTransition works if the cache is there for this path
startTransition(() => {
......
......@@ -355,6 +355,7 @@ function InnerLayoutRouter({
prefetchRsc: null,
head: null,
parallelRoutes: new Map(),
lazyDataResolved: false,
}
/**
......@@ -411,6 +412,7 @@ function InnerLayoutRouter({
context.nextUrl,
buildId
)
childNode.lazyDataResolved = false
}
/**
......@@ -419,15 +421,19 @@ function InnerLayoutRouter({
// When the data has not resolved yet `use` will suspend here.
const [flightData, overrideCanonicalUrl] = use(lazyData)
// segmentPath from the server does not match the layout's segmentPath
childNode.lazyData = null
// setTimeout is used to start a new transition during render, this is an intentional hack around React.
setTimeout(() => {
startTransition(() => {
changeByServerResponse(fullTree, flightData, overrideCanonicalUrl)
if (!childNode.lazyDataResolved) {
// setTimeout is used to start a new transition during render, this is an intentional hack around React.
setTimeout(() => {
startTransition(() => {
changeByServerResponse(fullTree, flightData, overrideCanonicalUrl)
})
})
})
// It's important that we mark this as resolved, in case this branch is replayed, we don't want to continously re-apply
// the patch to the tree.
childNode.lazyDataResolved = true
}
// Suspend infinitely as `changeByServerResponse` will cause a different part of the tree to be rendered.
use(createInfinitePromise()) as never
}
......
......@@ -183,6 +183,7 @@ describe('navigateReducer', () => {
"buildId": "development",
"cache": {
"lazyData": null,
"lazyDataResolved": false,
"parallelRoutes": Map {
"children" => Map {
"linking" => {
......@@ -377,6 +378,7 @@ describe('navigateReducer', () => {
"buildId": "development",
"cache": {
"lazyData": null,
"lazyDataResolved": false,
"parallelRoutes": Map {
"children" => Map {
"linking" => {
......@@ -1040,6 +1042,7 @@ describe('navigateReducer', () => {
"buildId": "development",
"cache": {
"lazyData": null,
"lazyDataResolved": false,
"parallelRoutes": Map {
"children" => Map {
"linking" => {
......@@ -1278,6 +1281,7 @@ describe('navigateReducer', () => {
"buildId": "development",
"cache": {
"lazyData": null,
"lazyDataResolved": false,
"parallelRoutes": Map {
"children" => Map {
"parallel-tab-bar" => {
......@@ -1637,6 +1641,7 @@ describe('navigateReducer', () => {
"buildId": "development",
"cache": {
"lazyData": null,
"lazyDataResolved": false,
"parallelRoutes": Map {
"children" => Map {
"linking" => {
......
......@@ -166,6 +166,7 @@ describe('serverPatchReducer', () => {
"buildId": "development",
"cache": {
"lazyData": null,
"lazyDataResolved": false,
"parallelRoutes": Map {
"children" => Map {
"linking" => {
......@@ -349,6 +350,7 @@ describe('serverPatchReducer', () => {
"buildId": "development",
"cache": {
"lazyData": null,
"lazyDataResolved": false,
"parallelRoutes": Map {
"children" => Map {
"linking" => {
......
......@@ -19,6 +19,11 @@ export type ChildSegmentMap = Map<string, CacheNode>
export type CacheNode = ReadyCacheNode | LazyCacheNode
export type LazyCacheNode = {
/**
* Whether the lazy cache node data promise has been resolved.
* This value is only true after we've called `use` on the promise (and applied the data to the tree).
*/
lazyDataResolved?: boolean
/**
* When rsc is null, this is a lazily-initialized cache node.
*
......@@ -61,6 +66,11 @@ export type LazyCacheNode = {
}
export type ReadyCacheNode = {
/**
* Whether the lazy cache node data promise has been resolved.
* This value is only true after we've called `use` on the promise (and applied the data to the tree).
*/
lazyDataResolved?: boolean
/**
* When rsc is not null, it represents the RSC data for the
* corresponding segment.
......
......@@ -140,8 +140,8 @@ function dispatchAction(
const newAction: ActionQueueNode = {
payload,
next: null,
resolve: resolvers!.resolve,
reject: resolvers!.reject,
resolve: resolvers.resolve,
reject: resolvers.reject,
}
// Check if the queue is empty
......
......@@ -12,7 +12,7 @@ function SubmitButton() {
)
}
export default async function Page() {
export default function Page() {
return (
<>
<h1>Add to cart</h1>
......
export default function Loading() {
return <div id="loading">Loading</div>
}
import React from 'react'
// ensure this page is dynamically rendered so we always trigger a loading state
export const dynamic = 'force-dynamic'
export default function page() {
return <div id="page-content">Content</div>
}
async function getTitle() {
return await new Promise((resolve) =>
setTimeout(() => resolve('Async Title'), 1000)
)
}
export async function generateMetadata() {
return { title: await getTitle() }
}
import Link from 'next/link'
export default function page() {
return (
<div>
<Link href="/metadata-await-promise/nested">Link to nested</Link>
</div>
)
}
'use server'
import { revalidatePath } from 'next/cache'
export async function action() {
revalidatePath('/', 'layout')
return true
}
'use client'
import { useFormState } from 'react-dom'
import { action } from './action'
export default function Page() {
const [submitted, formAction] = useFormState(action, false)
if (submitted) {
return <div>Form Submitted.</div>
}
return (
<div>
<h1>Form</h1>
<form action={formAction}>
<button id="submit-button">Push this button to submit the form</button>
</form>
</div>
)
}
import Link from 'next/link'
export default async function Home() {
await new Promise((resolve) => setTimeout(resolve, 1500))
return (
<div>
<h1>Home</h1>
<Link href="/popstate-revalidate/foo">To /foo</Link>
</div>
)
}
......@@ -7,7 +7,7 @@ createNextDescribe(
{
files: __dirname,
},
({ next, isNextDev, isNextDeploy }) => {
({ next, isNextDev, isNextDeploy, isNextStart }) => {
describe('query string', () => {
it('should set query correctly', async () => {
const browser = await next.browser('/')
......@@ -788,5 +788,57 @@ createNextDescribe(
expect(newScrollPosition).toEqual(scrollPosition)
})
})
describe('navigating to a page with async metadata', () => {
it('should render the final state of the page with correct metadata', async () => {
const browser = await next.browser('/metadata-await-promise')
// dev + PPR doesn't trigger the loading boundary as it's not prefetched
if (isNextDev && process.env.__NEXT_EXPERIMENTAL_PPR) {
await browser
.elementByCss("[href='/metadata-await-promise/nested']")
.click()
} else {
const loadingText = await browser
.elementByCss("[href='/metadata-await-promise/nested']")
.click()
.waitForElementByCss('#loading')
.text()
expect(loadingText).toBe('Loading')
}
await retry(async () => {
expect(await browser.elementById('page-content').text()).toBe(
'Content'
)
expect(await browser.elementByCss('title').text()).toBe('Async Title')
})
})
})
describe('browser back to a revalidated page', () => {
it('should load the page', async () => {
const browser = await next.browser('/popstate-revalidate')
expect(await browser.elementByCss('h1').text()).toBe('Home')
await browser.elementByCss("[href='/popstate-revalidate/foo']").click()
await browser.waitForElementByCss('#submit-button')
expect(await browser.elementByCss('h1').text()).toBe('Form')
await browser.elementById('submit-button').click()
await retry(async () => {
expect(await browser.elementByCss('body').text()).toContain(
'Form Submitted.'
)
})
await browser.back()
await retry(async () => {
expect(await browser.elementByCss('h1').text()).toBe('Home')
})
})
})
}
)
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