Commit graph

1612 commits

Author SHA1 Message Date
SubsequentlySneeds
c3f4e5d866
Minor grammar fix in "src Directory" page (#53481)
This change removes the sentence fragment starting with "Which" and merges it into the previous sentence.
2023-08-02 16:33:31 +00:00
Delba de Oliveira
eecd8dc146
Docs: update caching docs (#53478)
This PR:
- Makes minor content and formatting improvements
- Updates caching diagrams:
  - Adds missing static/dynamic diagram (fixes #53460) 
  - Tweaks designs to explain things better
  - Increases font sizes

Relies on: https://github.com/vercel/front/pull/24321
2023-08-02 12:11:22 +00:00
Steven
1b2e361e0d
chore(docs): add section about responsive images (#53463)
We got some feedback from that there is missing information when working with responsive images.

This PR adds a new section for Responsive Images along with some recipes how to achieve that.
2023-08-02 09:29:08 +00:00
leotrt
f51978beae
fix(doc): Broken link formatting in draft-mode doc (app router) (#53446)
### What?
Link to dynamic rendering is not appearing as such in the App router's draft-mode docs.

### Why?
The formatting is wrong, it misses a parenthesis

### How?
Added the missing parenthesis
2023-08-01 15:22:49 +00:00
Delba de Oliveira
dc3936b11a
Docs: Review Getting Started Section (#53377)
I've started reviewing the docs to identify areas we need to cover / improve. This PR contains minor improvements for the **getting started**, **installation**, and **project structure** pages.


New tasks added to linear: 
- Create [middleware.ts](https://linear.app/vercel/issue/DX-1834/create-middlewarets-api-reference-in-file-conventions) page
- Create [instrumentation.ts](https://linear.app/vercel/issue/DX-1833/create-instrumentationts-api-reference-in-file-conventions) page
2023-08-01 15:12:18 +00:00
Delba de Oliveira
b4d40f454e
Docs: Fix formatting issues in the caching docs (#53436) 2023-08-01 13:34:25 +00:00
Lee Robinson
19c4eec064
docs: fix broken diagram in caching docs (#53414)
Follow up from https://github.com/vercel/next.js/pull/52514.

We're still missing the static and dynamic diagram, it was missed in the PR to `front` to add the original diagrams. We'll need to get that in as well, could be here, or in a follow up.
2023-08-01 03:21:00 +00:00
Delba de Oliveira
98c3076eb4
Docs: Document caching mechanisms (#52514)
This PR document the caching semantics in Next.js, how they interact, and what APIs affect them. We're also taking the opportunity to consolidate terminology, remove duplicate content, and update sections of the docs that relate to caching. 

### Documentation

- [x] Create a new section for caching
- [x] Explain how the different caching mechanisms work
   - [x] Request Memoization (React Cache)
   - [x] Persistent Data Cache 
   - [x] Persistent Full Route Cache 
   - [x] In-memory, client-side Router Cache 
- [x] Document how different APIs affect caching
- [x] Document cache interactions 
- [x] Clean up stale information in the other docs sections
   - [x] Routing Section
      - [x] Move advanced navigation topics from fundamentals to **How Navigation Works** section
      - [x] Rewrite the **How Navigation Works** section
   - [x] Rendering Section
      - [x] Simplify fundamentals page
      - [x] Rewrite the **Static and Dynamic Rendering** pages
      - [ ] ~Create a page to explain how **Client and Server Components** are rendered~. Moved to this PR: https://github.com/vercel/next.js/pull/51579
   - [x] Data fetching section 
      - [x] Consolidate data fetching story for fetching, caching, and revalidating
      - [x] Clarify data fetching story with 3rd party libraries and React `cache`
      - [x] Create **Data Fetching Patterns** page
- [x] Document other related behaviors: 
   - [x] Update information on scroll position for back/forward navigation 
   - [x] Remove the concepts of **soft and hard navigation**
   - [x] Remove the concepts of **static and dynamic data fetching**
   - [x] Use consistent terminology **runtime** 👉🏼  **request time**. Runtime for Edge and Node.js, request time to describe when dynamic stuff happens
   - [x] `generateStaticParams` being able to seed the Full Route Cache
- [x] Polish 💅🏼 

---
### Related PRs:

- Diagrams: https://github.com/vercel/front/pull/24142
- Redirects: https://github.com/vercel/front/pull/24179
2023-07-31 17:03:26 +00:00
Ozan Sevkin
97a0a3373f
docs: update active link code snippet for better equality check (#53327)
Update pathname and href matching check from startsWith() method to strict equality. startsWith() method causes all paths to match with root link "/"
2023-07-30 23:21:59 +00:00
JJ
d3b0c7bb42
[Docs] remove x-xss-protection-header (#53362)
The x-xss-protection header is a non-standardized http header with low browser-capability.
If it is likely to be supported in the future, it can be treated as experimental, but since it is not, it is preferable to remove it.

https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-XSS-Protection
https://caniuse.com/mdn-http_headers_x-xss-protection
2023-07-30 20:12:41 +00:00
Steven Tey
ed35e2a6ea
Added docs on async not-found.js server components (#51999)
While `not-found.js` components do not accept any props, you can still turn the `not-found.js` component into an async server component to fetch dynamic data:


```tsx filename="app/blog/not-found.tsx" switcher
import Link from 'next/link'
import { headers } from "next/headers";

export default async function NotFound() {
  const headersList = headers();
  const domain = headersList.get("host")
  const data = await getSiteData(domain)
  return (
    <div>
      <h2>Not Found: {data.name}</h2>
      <p>Could not find requested resource</p>
      <p>
        View <Link href="/blog">all posts</Link>
      </p>
    </div>
  )
}
```

Co-authored-by: Lee Robinson <9113740+leerob@users.noreply.github.com>
Co-authored-by: JJ Kasper <22380829+ijjk@users.noreply.github.com>
2023-07-29 07:33:28 +00:00
Dom Sip
b149fb7009
docs: Update Route Handlers AI example code snippet (#52127)
changing AI example model from `text-davinci-003` to `gpt-3.5-turbo`
which is in a `chat/route.ts` format.

The alternative but with "completition" style would be a bit longer code
like:

```
// app/api/completion/route.ts

import { Configuration, OpenAIApi } from 'openai-edge'
import { OpenAIStream, StreamingTextResponse } from 'ai'

export const runtime = 'edge'

const apiConfig = new Configuration({
  apiKey: process.env.OPENAI_API_KEY!,
})

const openai = new OpenAIApi(apiConfig)

function buildPrompt(prompt: string) {
  return prompt.split('\n').map((message) => ({
    role: 'user',
    content: message,
  }));
}

export async function POST(req: Request) {
  
  // Extract the `prompt` from the body of the request
  const { prompt } = await req.json();

  // Request the OpenAI API for the response based on the prompt
  const response = await openai.createChatCompletion({
    model: 'gpt-3.5-turbo',
    stream: true,
    messages: buildPrompt(prompt),
    max_tokens: 500,
    temperature: 0.7,
    top_p: 1,
    frequency_penalty: 1,
    presence_penalty: 1,
  })

  // Convert the response into a friendly text-stream
  const stream = OpenAIStream(response)

  // Respond with the stream
  return new StreamingTextResponse(stream)
}

```

<!-- Thanks for opening a PR! Your contribution is much appreciated.
To make sure your PR is handled as smoothly as possible we request that
you follow the checklist sections below.
Choose the right checklist for the change(s) that you're making:

## For Contributors

### Improving Documentation

- Run `pnpm prettier-fix` to fix formatting issues before opening the
PR.
- Read the Docs Contribution Guide to ensure your contribution follows
the docs guidelines:
https://nextjs.org/docs/community/contribution-guide

### Adding or Updating Examples

- The "examples guidelines" are followed from our contributing doc
https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md
- Make sure the linting passes by running `pnpm build && pnpm lint`. See
https://github.com/vercel/next.js/blob/canary/contributing/repository/linting.md

### Fixing a bug

- Related issues linked using `fixes #number`
- Tests added. See:
https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs
- Errors have a helpful link attached, see
https://github.com/vercel/next.js/blob/canary/contributing.md

### Adding a feature

- Implements an existing feature request or RFC. Make sure the feature
request has been accepted for implementation before opening a PR. (A
discussion must be opened, see
https://github.com/vercel/next.js/discussions/new?category=ideas)
- Related issues/discussions are linked using `fixes #number`
- e2e tests added
(https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs
- Documentation added
- Telemetry added. In case of a feature if it's used or not.
- Errors have a helpful link attached, see
https://github.com/vercel/next.js/blob/canary/contributing.md


## For Maintainers

- Minimal description (aim for explaining to someone not on the team to
understand the PR)
- When linking to a Slack thread, you might want to share details of the
conclusion
- Link both the Linear (Fixes NEXT-xxx) and the GitHub issues
- Add review comments if necessary to explain to the reviewer the logic
behind a change

### What?

### Why?

### How?

Closes NEXT-
Fixes #

-->

---------

Co-authored-by: Lee Robinson <me@leerob.io>
Co-authored-by: Tim Neutkens <tim@timneutkens.nl>
Co-authored-by: JJ Kasper <jj@jjsweb.site>
2023-07-29 00:25:48 -07:00
Julien Bouquillon
71f08ef873
docs: fix typo (#53100)
just a typo in next/jest docs
2023-07-29 07:12:33 +00:00
Shunya Hayashi
dffafdecd3
Update nginx.conf example in documentation for improved flexibility and clarity (#53135)
## Description

This PR updates the provided example of nginx.conf in the documentation. The changes introduce more flexibility and clarity, making the example easier to understand and more suited for general use.

## What?

Changes include ↓

- Modifying the root directory to `/var/www/out`. This aligns more closely with typical server configurations and separates the public web content from other parts of the server.

- Updating the try_files directive for the `/` location block. The directive now attempts to serve `$uri`, `$uri.html`, and `$uri/` in that order. This setup caters to the common pattern in static websites of serving files derived directly from the URL and correctly handles URLs that omit the .html extension.

- The `/blog/` location block is retained as is, with the rewrite directive still relevant and not requiring changes.

## Why?

These modifications aim to improve the applicability of the example to a wider range of use cases and make it more comprehensible for new users.

## How?

The changes were made directly to the `nginx.conf` example provided in the docs, following the standard syntax and conventions of Nginx configuration files.


Please let me know if there are any questions, or if further modifications are needed !!

Co-authored-by: JJ Kasper <22380829+ijjk@users.noreply.github.com>
2023-07-29 07:03:14 +00:00
Andrew Garvin
ce29de25e4
Fixed simple typo in documentation (#53317)
I think this is a typo, at the very least I found the sentence a little clunky.
2023-07-28 21:22:37 +00:00
Steven Tey
7f77f427d2
docs: Add next-international to examples list (#53303) 2023-07-28 21:04:22 +00:00
Zack Tanner
604681912b
ensure colocated unit tests run in CI & fix various failing tests (#53270)
Colocated unit tests (such as ones in `packages/next` and `packages/font`) weren't running in CI since `run-tests` marks the glob cwd as `<root>/tests`. This modifies the working directory to be the root so the new expanded test pattern will pick up files outside of `test/`.

Several of these tests were failing so there are updates in here to fix them. Specifically:

- Source Sans Pro font was renamed to Source Sans 3
- `fillCacheWithDataProperty` test was hitting the `bailOptimistic` code path
- `resolve-metadata` had an invalid assertion (`rel: icon` gets added as part of `IconsMetadata`)
- `resolve-opengraph` wasn't handling undefined images
- `server-patch-reducer` now use inline snapshots as one was failing since it now has a prefetchCache
2023-07-28 13:54:15 +00:00
Oyebadejo Michael
37bb09d36a
chore(docs): remove repeated closing bracket (#53268)
### Adding or Updating Examples

- The repeated closing bracket that comes just after "Server Actions" has been removed

### Fixing a bug

- fixes #53267
2023-07-27 19:35:34 +00:00
Balázs Orbán
7721b9ba64
docs: match image example with code (#53254)
Closes NEXT-1761
Fixes #52037
2023-07-27 12:27:50 +00:00
Florentin / 珞辰
f1bd1eda8e
[docs] add documentation for maxDuration segment option (#52326)
This PR documents the new `maxDuration` segment options that allows to opt into higher Vercel function timeouts.
2023-07-26 16:35:28 +00:00
Aryan Malik
ccc269a5ae
Update 01-installation.mdx (#53192)
Added switcher on `page/_document.tsx` example just for a consistency
2023-07-26 15:34:27 +00:00
Aryan Malik
4cb14b5110
Fix grammatical error in docs (#53197)
Changed 'created' to 'create' for improved grammar and clarity in the documentation.

Find it under `Custom App`
[https://nextjs.org/docs/pages/building-your-application/routing/custom-app](url)
2023-07-26 13:25:25 +00:00
Daniel
84197ece65
chore(docs): client-side data fetching loading state (#53164)
setLoading must be "true" at first and then set to "false". The documentation, as is, always has the value of setLoading set to "false".

The purpose of this code is to show "...loading" on the screen while the data is being fetched. In order for this to happen, setLoading must be initially set to "true" and then (after the data is successfully loaded) set to "false", since the line `if (isLoading) return <p>Loading...</p>` is asking if the content is still loading, and if it is, it'll return a message indicating it.

Because of this

### What?
setLoading should be set to "true" at first.

### Why?
Because the code then asks if the content is being loaded. The code (as is) always has setLoading set as "false" and it doesn't show the loading message when it's supposed to.

### How?
I changed the line to `const [isLoading, setLoading] = useState(true)`.




Co-authored-by: Steven <229881+styfle@users.noreply.github.com>
2023-07-25 16:49:40 +00:00
Steven
a0856eb596
chore: update warning message from yarn add sharp to npm i sharp (#53130)
Previously, this warning message assumed the user knew what `yarn` was and had it installed.

This PR changes the warning message to assume the user knows what `npm` is and has it installed, since `npm` ships with the official `node` installation.
2023-07-24 22:33:12 +00:00
Lee Robinson
436408272e
docs: fix codeblock for redirect (#53120)
Just needs a language 👍
2023-07-24 16:48:15 +00:00
vinay
c355fb1a38
(Docs) Remove FormData type on formData defined in .js file (#53014) 2023-07-24 15:47:35 +00:00
vinay
a18e2ec94b
(Docs) Add missing import for useRef() (#53015) 2023-07-23 21:41:10 +00:00
Paul Barry
85676da42c
chore(docs): Extend the options for custom server init (#52851)
## For Contributors

### Improving Documentation

While working with a custom server, I noticed that [the list of available options within the codebase](https://github.com/vercel/next.js/blob/canary/packages/next/src/server/base-server.ts#L138-L180) was much larger than [the options listed within the docs](https://nextjs.org/docs/pages/building-your-application/configuring/custom-server). This PR extends the `next` import function options to include all of ~the allowed~ documented options from the codebase. 

- [x] Run `pnpm prettier-fix` to fix formatting issues before opening the PR.
- [x] Read the Docs Contribution Guide to ensure your contribution follows the docs guidelines: https://nextjs.org/docs/community/contribution-guide




Co-authored-by: Lee Robinson <9113740+leerob@users.noreply.github.com>
2023-07-23 17:25:07 +00:00
Sungyun Hur
caeaa74dda
docs: fix typo in 08-parallel-routes.mdx (#53069)
### What?

Fix a typo in `08-parallel-routes.mdx` by adding a whitespace.

### Why?

<img width="783" alt="스크린샷 2023-07-23 오후 4 11 22" src="https://github.com/vercel/next.js/assets/8033896/0bb92fc5-5a6f-4461-895a-a956abf52a9d">


### How?
2023-07-23 17:01:38 +00:00
trigaten
e4871f6927
docs: remove unneeded good to know section during installation (#53078)
Co-authored-by: Lee Robinson <me@leerob.io>
2023-07-23 09:49:51 -07:00
Vu Van Dung
a0ea5f2d79
Fix formData code snippet in route handler docs (#52532)
### Why?

The code snippet in the Route handler `formData` documentation

```ts
import { NextResponse } from 'next/server'
 
export async function POST(request: Request) {
  const formData = await request.formData()
  return NextResponse.json({ formData })
}
```

is slightly wrong, because `formData` is not a plain object and hence `return NextResponse.json({ formData })` doesn't actually work.

Since we are already in the topic of parsing `formData`, I also added a mention on `zod-form-data` which can be used to validate the form and parse it to non-string formats such as `number`.
2023-07-22 21:15:12 +00:00
vinay
94878fe719
(Docs) add missing import. (#52992)
`import { cookies } from 'next/headers'`
2023-07-22 05:05:38 +00:00
Steven
26a57af389
chore(docs): fix broken link (#53021)
This link is failing CI as seen here:

https://github.com/vercel/next.js/actions/runs/5623454975/job/15238167610


```
Error: The action could not create a Github comment because it is initiated from a forked repo. View the action logs for a list of broken links.
This PR introduces broken links to the docs:
┌─────────┬───────────────────────────────────────────────────────────────────────────────┬──────┬─────────────────────────────────────────────────────────────────────────────────────┐
│ (index) │                                     link                                      │ type │                                       docPath                                       │
├─────────┼───────────────────────────────────────────────────────────────────────────────┼──────┼─────────────────────────────────────────────────────────────────────────────────────┤
│    0    │ 'app/building-your-application/configuring/typescript#statically-typed-links' │      │ 'docs/02-app/01-building-your-application/01-routing/03-linking-and-navigating.mdx' │
└─────────┴───────────────────────────────────────────────────────────────────────────────┴──────┴─────────────────────────────────────────────────────────────────────────────────────┘
Error: This PR introduces broken links to the docs. The action could not create a Github check because it is initiated from a forked repo.
Error: Process completed with exit code 1.
```
2023-07-21 18:28:24 +00:00
Heidar-An
732219e9df
Update 02-dynamic-routes.mdx (#52975)
grammatical mistake

### What?
Small grammatical mistake on https://nextjs.org/docs/pages/building-your-application/routing/dynamic-routes
2023-07-21 17:08:52 +00:00
Shaun Ferris
3e34b9f2d2
"Clarify the 'Existing Projects' section of the TypeScript docs: (#52944)
> Add a sentence to the instructions for using typescript in an existing project instructing the user to copy the `paths` compiler option from the existing jsconfig file to the new tsconfig file.
> Not doing so causes absolute imports from project directories to break, and gives "Module Not Found" messages that the docs do not have a case for solving"
2023-07-21 15:09:28 +00:00
Cassidy Williams
7a0297c2d4
Change "publically" to "publicly" in the routing docs (#52966)
### What and why?

The word "publicly" should be spelled consistently across the documentation. It is spelled currently as "publically" in a few places.

### How?

Fixed the spelling!
2023-07-20 20:47:42 +00:00
Daryll J. Reillo
66f0983cb8
Update 06-lazy-loading.mdx: Incorrect filename in Example on "Importing Named Imports" (#52932)
The correct filename is seen on PagesOnly. But on AppOnly, the filename is not correct. It should be "hello" instead of "ClientComponent".

line to change:
from:
import('../components/ClientComponent').then((mod) => mod.Hello)

to:
import('../components/hello').then((mod) => mod.Hello)


line to change:
from:
import('../components/ClientComponent').then((mod) => mod.Hello)

to:
import('../components/hello').then((mod) => mod.Hello)
2023-07-20 12:57:18 +00:00
Soheil Nazari
20b115e827
wrong content for next.config.mjs for MDX Plugins (#52738) 2023-07-19 21:55:40 +00:00
Adam Hunter
2c1c8fa089
docs: fix example component in MDX documentation (#52753) 2023-07-19 14:25:31 -07:00
Steven
b12e6fef0c
chore(docs): fix typo in generate metadata docs (#52904)
- See current bug:
https://nextjs.org/docs/app/api-reference/functions/generate-metadata#generatemetadata-function
- Closes #52903
2023-07-19 14:21:18 -07:00
Antoine Bourin
08e87fb405
docs: add Typescript statically typed links mention in link doc (#52847) 2023-07-19 14:15:04 -07:00
Steven Tey
55fdfe4280
Update 02-edge-and-nodejs-runtimes.mdx (#52888)
Added clarification that runtime edge can be defined on Layout level too.

Co-authored-by: Steven <229881+styfle@users.noreply.github.com>
Co-authored-by: Balázs Orbán <18369201+balazsorban44@users.noreply.github.com>
2023-07-19 14:41:01 +00:00
Joseph Garrone
f5272acbe5
docs: Add tss-react for CSS-in-JS docs (#52764) 2023-07-18 19:48:01 -07:00
Rinald
d18334ae92
docs: Improve OpenTelemetry manual config (#52784) 2023-07-18 19:46:30 -07:00
hiro
daac0484fa
Fix typo in docs (#52815)
The following files have been modified.

- `docs/02-app/01-building-your-application/05-optimizing/04-metadata.mdx`
  programatically -> programmatically
- `docs/02-app/02-api-reference/04-functions/image-response.mdx`
   ImageReponse -> ImageResponse




Co-authored-by: JJ Kasper <22380829+ijjk@users.noreply.github.com>
2023-07-18 04:36:31 +00:00
Eldar Amantay
0084166caa
chore(docs): Add mentioning of HOSTNAME env variable for standalone output (#52804)
### What?

Update documentation to mention a `HOSTNAME` env variable for `standalone` output

Related to Feature: https://github.com/vercel/next.js/pull/44627 

### Why?

Current documentation mentions only `PORT` env, but does not mention `HOSTNAME` added in January

Affected documentation pages:

- https://nextjs.org/docs/app/api-reference/next-config-js/output

Affected examples:

- https://github.com/vercel/next.js/tree/canary/examples/with-docker
- https://github.com/vercel/next.js/tree/canary/examples/with-docker-multi-env

### How?

- Run examples
- Check documentation
2023-07-17 19:59:53 +00:00
Cheol-Won
82efdfe877
docs : fix typo in React cache example (#52787)
### Description
This PR fix typo in the description of Caching Data

### Changes
- Added types to React `cache()` exercise

File: `docs/02-app/01-building-your-application/03-data-fetching/02-caching.mdx`
2023-07-17 15:46:30 +00:00
vinay
503677c099
(Docs) add missing js version for generateMetadata. (#52763)
There was no JS version for `generateMetadata` function.

fixes #52759 

Co-authored-by: Steven <229881+styfle@users.noreply.github.com>
2023-07-17 15:23:54 +00:00
Tim Neutkens
f5f79e7a8c
Update mention of route handlers for forms (#52781)
Route handlers are not specifically different from API Routes in terms of forms or other usage, the only difference is how you write them (Request) => Response. Initially this mention was supposed to be removed when server actions are marked stable, but it's leading to some confusion so I've updated the mention to clarify that there will be a more integrated solution for React.
2023-07-17 14:11:42 +00:00
Balázs Orbán
82cf9a670e
docs: move MUI to supported list (#52584)
fixes #52575

---------

Co-authored-by: Lee Robinson <me@leerob.io>
Co-authored-by: Alexandre Fauquette <45398769+alexfauquette@users.noreply.github.com>
Co-authored-by: Steven <steven@ceriously.com>
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
2023-07-12 12:50:20 -07:00