Skip to content

Commit

Permalink
Merge branch 'canary' into eslint-plugin-next
Browse files Browse the repository at this point in the history
  • Loading branch information
kodiakhq[bot] committed Jul 7, 2023
2 parents 8e95cf7 + deb1d19 commit 56c4064
Show file tree
Hide file tree
Showing 11 changed files with 74 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ To access search params in [Pages](/docs/app/api-reference/file-conventions/page

Unlike Pages, [Layouts](/docs/app/api-reference/file-conventions/layout) (Server Components) **do not** receive the `searchParams` prop. This is because a shared layout is [not re-rendered during navigation](/docs/app/building-your-application/routing#partial-rendering) which could lead to stale `searchParams` between navigations. View [detailed explanation](/docs/app/api-reference/file-conventions/layout#layouts-do-not-receive-searchparams).

Instead, use the Page [`searchParams`](/docs/app/api-reference/file-conventions/page) prop or the [`useSearchParams`](/docs/app/api-reference/functions/use-params) hook in a Client Component, which is re-rendered on the client with the latest `searchParams`.
Instead, use the Page [`searchParams`](/docs/app/api-reference/file-conventions/page) prop or the [`useSearchParams`](/docs/app/api-reference/functions/use-search-params) hook in a Client Component, which is re-rendered on the client with the latest `searchParams`.

## Examples

Expand Down
12 changes: 9 additions & 3 deletions docs/02-app/02-api-reference/06-create-next-app.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,23 @@ description: Create Next.js apps in one command with create-next-app.

{/* The content of this doc is shared between the app and pages router. You can use the `<PagesOnly>Content</PagesOnly>` component to add content that is specific to the Pages Router. Any shared content should not be wrapped in a component. */}

The easiest way to get started with Next.js is by using `create-next-app`. This CLI tool enables you to quickly start building a new Next.js application, with everything set up for you. You can create a new app using the default Next.js template, or by using one of the [official Next.js examples](https://github.com/vercel/next.js/tree/canary/examples). To get started, use the following command:
The easiest way to get started with Next.js is by using `create-next-app`. This CLI tool enables you to quickly start building a new Next.js application, with everything set up for you.

You can create a new app using the default Next.js template, or by using one of the [official Next.js examples](https://github.com/vercel/next.js/tree/canary/examples).

### Interactive

You can create a new project interactively by running:

```bash filename="Terminal"
npx create-next-app@latest
```

```bash filename="Terminal"
yarn create next-app
```

```bash filename="Terminal"
pnpm create next-app
```

Expand Down Expand Up @@ -89,7 +95,7 @@ Options:
-e, --example [name]|[github-url]

An example to bootstrap the app with. You can use an example name
from the official Next.js repo or a GitHub URL. The URL can use
from the official Next.js repo or a public GitHub URL. The URL can use
any branch and/or subdirectory

--example-path <path-to-example>
Expand All @@ -113,5 +119,5 @@ Options:
- **Interactive Experience**: Running `npx create-next-app@latest` (with no arguments) launches an interactive experience that guides you through setting up a project.
- **Zero Dependencies**: Initializing a project is as quick as one second. Create Next App has zero dependencies.
- **Offline Support**: Create Next App will automatically detect if you're offline and bootstrap your project using your local package cache.
- **Support for Examples**: Create Next App can bootstrap your application using an example from the Next.js examples collection (e.g. `npx create-next-app --example api-routes`).
- **Support for Examples**: Create Next App can bootstrap your application using an example from the Next.js examples collection (e.g. `npx create-next-app --example api-routes`) or any public GitHub repository.
- **Tested**: The package is part of the Next.js monorepo and tested using the same integration test suite as Next.js itself, ensuring it works as expected with every release.
2 changes: 1 addition & 1 deletion packages/next/src/lib/metadata/resolvers/resolve-url.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export function getSocialImageFallbackMetadataBase(

if (isMetadataBaseMissing) {
Log.warnOnce(
`\nmetadata.metadataBase is not set for resolving social open graph or twitter images, fallbacks to "${fallbackMetadata.origin}". See https://nextjs.org/docs/app/api-reference/functions/generate-metadata#metadatabase`
`\nmetadata.metadataBase is not set for resolving social open graph or twitter images, using "${fallbackMetadata.origin}". See https://nextjs.org/docs/app/api-reference/functions/generate-metadata#metadatabase`
)
}

Expand Down
7 changes: 5 additions & 2 deletions packages/next/src/server/app-render/app-render.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,10 @@ import { interopDefault } from './interop-default'
import { preloadComponent } from './preload-component'
import { FlightRenderResult } from './flight-render-result'
import { createErrorHandler } from './create-error-handler'
import { getShortDynamicParamType } from './get-short-dynamic-param-type'
import {
getShortDynamicParamType,
dynamicParamTypes,
} from './get-short-dynamic-param-type'
import { getSegmentParam } from './get-segment-param'
import { getCssInlinedLinkTags } from './get-css-inlined-link-tags'
import { getPreloadableFonts } from './get-preloadable-fonts'
Expand Down Expand Up @@ -324,7 +327,7 @@ export async function renderToHTMLOrFlight(
if (!value) {
// Handle case where optional catchall does not have a value, e.g. `/dashboard/[...slug]` when requesting `/dashboard`
if (segmentParam.type === 'optional-catchall') {
const type = getShortDynamicParamType(segmentParam.type)
const type = dynamicParamTypes[segmentParam.type]
return {
param: key,
value: null,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
import { DynamicParamTypes, DynamicParamTypesShort } from './types'

export const dynamicParamTypes: Record<
DynamicParamTypes,
DynamicParamTypesShort
> = {
catchall: 'c',
'optional-catchall': 'oc',
dynamic: 'd',
}

/**
* Shorten the dynamic param in order to make it smaller when transmitted to the browser.
*/
export function getShortDynamicParamType(
type: DynamicParamTypes
): DynamicParamTypesShort {
switch (type) {
case 'catchall':
return 'c'
case 'optional-catchall':
return 'oc'
case 'dynamic':
return 'd'
default:
throw new Error('Unknown dynamic param type')
const short = dynamicParamTypes[type]
if (!short) {
throw new Error('Unknown dynamic param type')
}
return short
}
6 changes: 3 additions & 3 deletions packages/next/src/server/dev/on-demand-entry-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,9 @@ export function getEntryKey(
pageBundleType: 'app' | 'pages' | 'root',
page: string
) {
// TODO: handle the /@children slot better
// this is a quick hack to handle when children is provided as @children/page instead of /page
return `${compilerType}@${pageBundleType}@${page.replace(/\/@children/g, '')}`
// TODO: handle the /children slot better
// this is a quick hack to handle when children is provided as children/page instead of /page
return `${compilerType}@${pageBundleType}@${page.replace(/\/children/g, '')}`
}

function getPageBundleType(pageBundlePath: string) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ describe('app dir - metadata missing metadataBase', () => {
await next.start()
await fetchViaHTTP(next.url, '/')
expect(next.cliOutput).toInclude(
'metadata.metadataBase is not set for resolving social open graph or twitter images, fallbacks to'
'metadata.metadataBase is not set for resolving social open graph or twitter images, using'
)
expect(next.cliOutput).toInclude(`"http://localhost:${port}`)
expect(next.cliOutput).toInclude(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export default function ParallelPage() {
return (
<>
<p>Hello from nested parallel page!</p>
<div id="timestamp">{Date.now()}</div>
</>
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export default function Layout({ parallelB }: { parallelB: React.ReactNode }) {
return (
<main>
<h3>{`(parallelB)`}</h3>
<div>{parallelB}</div>
</main>
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export default function Parallel({ children }) {
return (
<div>
parallel/layout:
<div className="parallel" title="children">
{children}
</div>
</div>
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,21 @@ createNextDescribe(
return newTimestamp !== timestamp ? 'failure' : 'success'
}, 'success')
})

it('should support nested parallel routes', async () => {
const browser = await next.browser('parallel-nested/home/nested')
const timestamp = await browser.elementByCss('#timestamp').text()

await new Promise((resolve) => {
setTimeout(resolve, 3000)
})

await check(async () => {
// an invalid response triggers a fast refresh, so if the timestamp doesn't update, this behaved correctly
const newTimestamp = await browser.elementByCss('#timestamp').text()
return newTimestamp !== timestamp ? 'failure' : 'success'
}, 'success')
})
}
})

Expand Down

0 comments on commit 56c4064

Please sign in to comment.