- 25 Sep, 2024 27 commits
-
-
vercel-release-bot authored
-
Josh Story authored
Next.js has a number of dynamic APIs that aren't available during prerendering. What happens when you access these APIs might differ depending on the mode you are using, for instance if you have PPR turned on or the newly introduced `dynamicIO` experimental mode. But regardless of the mode the underlying API represents accessing something that might only be available at render time (dynamic rendering) rather than prerender time (build and revalidate rendering) Unfortunately our current dynamic APIs make certain kinds of modeling tricky because they are all synchronous. For instance if we wanted to add a feature to Next.js where we started a dynamic render before a Request even hits the server it would be interesting to be able to start working on everything that does not rely on any dynamic data and then once a real Request arrives we can continue the render and provide the associated Request context through our dynamic APIs. If our dynamic APIs were all async we could build something like this because they represnt a value that will eventually resolve to some Request value. This PR updates most existing dynamic APIs to be async rather than sync. This is a breaking change and will need to be paired with codemods to realistically adopt. Additionally since this change is so invasive I have implemented it in a way to maximize backward compatibility by still allowing most synchronous access. The combination of codemods, typescript updates, and backward compat functionality should make it possible for projects to upgrade to the latest version with minimal effort and then follow up with a complete conversion over time. #### `cookies()` `cookies()` now returns `Promise<ReadonlyRequestCookies>`. Synchronous access to the underlying RequestCookies object is still supported to facilitate migration. ```tsx // ------------ preferred usage // async Server Component const token = (await cookies()).get('token') // sync Server Component import { use } from 'react' //... const token = use(cookies()).get('token') // ------------ temporarily allowed usage // javascript, dev warning at runtime const token = cookies().get('token') // typescript, dev warning at runtime import { type UnsafeUnwrappedCookies } from 'next/headers' // ... const token = (cookies() as unknown as UnsafeUnwrappedCookies).get('token') ``` #### `headers()` `headers()` now returns `Promise<ReadonlyHeaders>`. Synchronous access to the underlying Headers object is still supported to facilitate migration. ```tsx // ------------ preferred usage // async Server Component const header = (await headers()).get('x-foo') // sync Server Component import { use } from 'react' //... const header = use(headers()).get('x-foo') // ------------ temporarily allowed usage // javascript, dev warning at runtime const header = headers().get('x-foo') // typescript, dev warning at runtime import { type UnsafeUnwrappedHeaders } from 'next/headers' // ... const header = (headers() as unknown as UnsafeUnwrappedHeaders).get('x-foo') ``` #### `draftMode()` `draftMode()` now returns `Promise<DraftMode>`. Synchronous access to the underlying DraftMode object is still supported to facilitate migration. ```tsx // ------------ preferred usage // async Server Component if ((await draftMode()).isEnabled) { ... } // sync Server Component import { use } from 'react' //... if (use(draftMode()).isEnabled) { ... } // ------------ temporarily allowed usage // javascript, dev warning at runtime if (draftMode().isEnabled) { ... } // typescript, dev warning at runtime import { type UnsafeUnwrappedDraftMode} from 'next/headers' // ... if ((draftMode() as unknown as UnsafeUnwrappedDraftMode).isEnabled) { ... } ``` #### `searchParams` `searchParams` is now a `Promise<{...}>`. Synchronous access to the underlying search params is still supported to facilitate migration. ```tsx // ------------ preferred usage // async Page Component export default async function Page({ searchParams }: { searchParams: Promise<{ foo: string }> }) { const fooSearchParam = (await searchParams).foo } // sync Page Component import { use } from 'react' export default function Page({ searchParams }: { searchParams: Promise<{ foo: string }> }) { const fooSearchParam = use(searchParams).foo } // ------------ temporarily allowed usage // javascript, dev warning at runtime export default async function Page({ searchParams}) { const fooSearchParam = searchParams.foo } // typescript, dev warning at runtime import { type UnsafeUnwrappedSearchParams } from 'next/server' export default async function Page({ searchParams }: { searchParams: Promise<{ foo: string }> }) { const syncSearchParams = (searchParams as unknown as UnsafeUnwrappedSearchParams<typeof searchParams>) const fooSearchParam = syncSearchParams.foo } ``` #### `params` `params` is now a `Promise<{...}>`. Synchronous access to the underlying params is still supported to facilitate migration. It should be noted that while params are not usually dynamic there are certain modes where they can be such as fallback prerenders for PPR. ```tsx // ------------ preferred usage // async Segment Component export default async function Layout({ params }: { params: Promise<{ foo: string }> }) { const fooParam = (await params).foo } // sync Segment Component import { use } from 'react' export default function Layout({ params }: { params: Promise<{ foo: string }> }) { const fooParam = use(params).foo } // ------------ temporarily allowed usage // javascript, dev warning at runtime export default async function Layout({ params}) { const fooParam = params.foo } // typescript, dev warning at runtime import { type UnsafeUnwrappedParams } from 'next/headers' export default async function Layout({ params }: { params: Promise<{ foo: string }> }) { const syncParams = (params as unknown as UnsafeUnwrappedParams<typeof params>) const fooSearchParam = syncParams.foo } ``` ### Typescript Changes When using typescript with Next.js currently it is up to you to author types for Pages, Layouts and other Segment components that recieve props like `params` and `searchParams`. Next comes with some build-time type checking to ensure you have not improperly typed various top level module exports however the current type assertions for `params` and `searchParams` is `any`. This isn't very helpful because it allows you to erroneously type these props. `searchParams` is tricky because while the default type is a dictionary object parsed using node.js url parsing it is possible to customize when running a custom Next.js server. However we can ensure that you correctly type the prop as a Promise so with this change the validated type for `searchParams` will be `Promise<any>`. In the long run we will look at updating the `searchParams` underlying type to be URLSearchParams so we can move away from supporting customized parsing during rendering and we can get even more explicit about valid types. `params` is more straight forward because the framework controls the actual `params` prop implementation and no customization is possible. In the long run we want to enforce you are only typing params that are valid for the Layout level your file is located in but for now we are updating the allowed type to be `Promise<{[key: string]: string | string[] | undefined }>`. These new type restrictions may also require fixes before being able to successfully build a project that updates to include these breaking changes. These changes will also not always be codemodable because it is valid to type the entire component using an opaque type like `Props` which our codemods may not have an ability to introspect or modify. -
vercel-release-bot authored
-
PapatMayuri authored
This PR updates the with-draft-js example for using the App Router. Here are the changes that have been made: - Renamed the "pages" folder to the "app" folder. - Added the layout.tsx file as part of the App Router. - Updated the package.json file. CC: @samcx --------- Co-authored-by:Sam Ko <sam@vercel.com>
-
vercel-release-bot authored
-
JJ Kasper authored
This aims to provide more stability so we aren't hitting the network to grab the validator more than we need to and instead leverage the one from build instead which should also reduce some test flakiness we've been seeing.
-
JJ Kasper authored
x-ref: https://github.com/vercel/next.js/pull/70410 x-ref: https://github.com/vercel/next.js/pull/70435
-
Wyatt Johnson authored
<!-- 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 # --> This adds and updates some Typescript types for the React libraries used by Next.js. As a result some of the code was modified to match.
-
tranvanhieu01012002 authored
<!-- 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? Update the docker with multiple env examples by the correct hostname. ### Why? I am verry happy when I see this example, I need to deploy a project with multiple environments, I tested current example for my machine, but it started but it didn't connect to app. I really try this example https://github.com/vercel/next.js/tree/canary/examples/with-docker-multi-env. but it doesn't connect to nextjs container because the hostname configuation is incorrect. ### How? I created this PR to change hostname from host ```localhost``` to ```0.0.0.0``` in docker with multiple environments Closes NEXT- No fixing any issues Co-authored-by:
JJ Kasper <jj@jjsweb.site>
-
Sebastian Markbåge authored
Co-authored-by:JJ Kasper <jj@jjsweb.site>
-
Tobias Koppers authored
### What? * switch remove vs change order * take_collectibles does not need to return an Option * avoid double Option * fix edges set bugs * remove collectibles from outdated collectibles * remove unneccessary remove
-
Donny/강동윤 authored
Co-authored-by:Jiachi Liu <inbox@huozhi.im>
-
Jordy Fontoura authored
### What? This PR fixes a numbering issue in the example code of the documentation. The comments in the code jumped from step 3 to step 5, so I renumbered them to maintain the correct sequence. ### Why? Correcting the comment numbering improves the clarity and readability of the code, ensuring that readers can follow the steps in the right order. ### How? I changed step 5 to step 4 and step 6 to step 5, adjusting the comment sequence without altering the logic or functionality of the code. ### Evidence  Co-authored-by:
JJ Kasper <jj@jjsweb.site>
-
Benjamin Woodruff authored
A follow-up to the #70431 codemod diff, which leave behind a lot of trivial `let this = self;` statements. Using the following ast-grep rule config: ```yaml language: rust id: inline_trivial_this utils: block-with-this: all: - pattern: $BLOCK - kind: block - has: all: - pattern: let this = $SELF; - any: - pattern: let this = self; - pattern: let this = &self.0; rule: matches: block-with-this rewriters: - id: remove-let-this rule: pattern: let this = $SELF; fix: "" - id: inline-this-auto-deref rule: pattern: this inside: kind: field_expression transform: SELF_AUTO_DEREF: replace: source: $SELF replace: "&?(?<INNER>.*)" by: "$INNER" fix: $SELF_AUTO_DEREF - id: inline-this rule: pattern: this fix: $SELF transform: NEW_BLOCK: rewrite: source: $BLOCK rewriters: - remove-let-this - inline-this-auto-deref - inline-this fix: $NEW_BLOCK ``` Applied with ``` sg scan -U -r ../codemod_inline_trivial_this.yml . ``` -
Sebastian "Sebbie" Silbermann authored
-
vercel-release-bot authored
-
Niklas Mischkulnig authored
Closes PACK-3276
-
Alexander Lyon authored
### What? Add `@taskr/esnext` to the root package.json to get around hoisting rules breaking `taskr`'s automatic discovery (and fix builds on some platforms where it is broken). ### Why? Some types of 'magically' imported packages (such as taskr automatically supporting es6 by just adding a package, or drizzle automatically finding a database driver) aren't hoisted on some platforms in the way the tool expects, breaking it. The symptom of this is taskr throwing a syntax error on some platforms, because we use ES6 syntax and it can't find the package it needs to support it. ### How? By adding it to the root package.json we ensure it is always hoisted in the way taskr expects.
-
Jam Balaya authored
-
Jiachi Liu authored
-
Niklas Mischkulnig authored
Occurs for example in ``` Failed to load chunk server/chunks/08b5e__pnpm_560cbe._.js .... Caused by SyntaxError: Identifier 'require' has already been declared .... ```
-
Niklas Mischkulnig authored
Closes PACK-3275 Among other things, a regression from https://github.com/vercel/next.js/pull/70255, but it could also happen with `__dirname`. To prevent `SyntaxError: Identifier 'require' has already been declared`
-
Tobias Koppers authored
### What? * While looking for server component entries and client components, look for server utils too * Create a separate chunk group for server utils * Mark all user imports in the rsc entrypoint has server component entries * Fix order of imports to allow proper caching --------- Co-authored-by:Niklas Mischkulnig <4586894+mischnic@users.noreply.github.com>
-
vercel-release-bot authored
-
Benjamin Woodruff authored
Noticed this pattern while touching `turbo-tasks-fs`. Functions that take `self: Vc<Self>` and immediately await it without ever using the `Vc` version of the argument should just take `&self` as an argument. There are some remaining cleanup opportunities here, which I have some still-WIP codemods for: - [x] If we have a trivial `let this = self` or `let this = &self.0`, we should rewrite references to `this` to use `self`. *Done in #70431* - [ ] If we can be sure that a function never returns anything other than `Ok(...)`, we should remove `Result` from the return type. Those changes need to be performed as a separate codemod pass due to limitations with `ast-grep`. ## How? ast-grep: https://ast-grep.github.io/ Using the ast-grep config: https://gist.github.com/bgw/b7bc0a921cf3e3447acaf8feda60b518 Ran it with: ``` sg scan -U -r ../codemod_rewrite_vc_self.yml . ``` ## Should this be a lint? **Maybe.** I've managed to get the false-positive rate down to zero on our existing codebase (at the cost of missing some opportunities for cleanup). ast-grep supports running as a lint rule, and this can be autofixed. However, if we fix the `let this = ...` and `Result<...>` cases as well with additional lint rules, **this might be a bit annoying as it'll trigger cascading lint rules**. You *might* need to run the linter multiple times for it to eventually settle. It does not appear to be possible to do all these changes in a single lint rule, as we require modifying overlapping ranges of code (which ast-grep sadly doesn't seem to support with the `rewriters` rules). We should also consider `dynlint` before heavily investing into `ast-grep` as a linter: https://github.com/trailofbits/dylint
-
Donny/강동윤 authored
### What? Minor refactorings extracted from other PRs. ### Why? To make WIP small
-
JJ Kasper authored
Closes: https://github.com/vercel/next.js/pull/59342
-
- 24 Sep, 2024 13 commits
-
-
JJ Kasper authored
Closes: https://github.com/vercel/next.js/pull/58589/files
-
Benjamin Woodruff authored
Noticed these files while reviewing https://github.com/vercel/next.js/pull/70242 Mark them as generated so that github & graphite collapse them when reviewing code. ``` $ git ls-files | git check-attr -a --stdin | grep __snapshots__ ``` ``` .config/ast-grep/rule-tests/__snapshots__/no-context-snapshot.yml: linguist-generated: true examples/with-jest-babel/__tests__/__snapshots__/snapshot.tsx.snap: linguist-generated: true examples/with-jest/__tests__/__snapshots__/snapshot.tsx.snap: linguist-generated: true examples/with-typescript-graphql/test/__snapshots__/index.test.tsx.snap: linguist-generated: true test/development/acceptance-app/__snapshots__/ReactRefreshLogBox.test.ts.snap: linguist-generated: true test/development/acceptance/__snapshots__/ReactRefreshLogBox.test.ts.snap: linguist-generated: true test/development/acceptance/__snapshots__/ReactRefreshLogBoxMisc.test.ts.snap: linguist-generated: true test/development/acceptance/__snapshots__/error-recovery.test.ts.snap: linguist-generated: true test/development/basic/__snapshots__/next-rs-api.test.ts.snap: linguist-generated: true test/production/eslint/test/__snapshots__/next-build-and-lint.test.ts.snap: linguist-generated: true ```
-
Jiwon Choi authored
### Why? Prerequisite of `@next/codemod upgrade`. Current status of next-codemod is difficult to extend another commands as it relies on [meow](https://www.npmjs.com/package/meow) which requires to handle args and flags manually. For consistency with `next` and `create-next-app`, migrated to `commander` and `prompts`. https://github.com/user-attachments/assets/8d2e53be-4b7d-4755-9a3f-c73df1f9ef7e No behavioral changes **except the help message**.
-
Kutsan Kaplan authored
<!-- 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 # --> A new gtmScriptUrl option has been added to the third-parties GTM package. This allows you to replace the default https://www.googletagmanager.com/gtm.js URL with a custom gtm.js URL, such as "https://gtm.example.com/gtm.js". Closes: https://github.com/vercel/next.js/pull/63767 Closes: https://github.com/vercel/next.js/pull/68531 Closes: https://github.com/vercel/next.js/pull/67161 Closes: https://github.com/vercel/next.js/pull/61145 Closes: https://github.com/vercel/next.js/pull/58262 --------- Co-authored-by:
JJ Kasper <jj@jjsweb.site>
-
JJ Kasper authored
Lands https://github.com/vercel/next.js/pull/54317 as we can't update the history cleanly on that PR anymore Closes: https://github.com/vercel/next.js/pull/54317Co-authored-by:
Andrés Martínez <78830288+andresmarpz@users.noreply.github.com>
-
Alessio Maffeis authored
Minor tweak to the wording of this section to better convey the behavior of `scroll: false`. "Restoration" can be interpreted as reinstating a previously saved scroll position for that route (as it happens when using `router.back()`), while what it actually does is preserving the current scroll position when navigating to a new route, by means of disabling the default "scroll to top" behavior. Related to: https://github.com/vercel/next.js/issues/57258, and https://github.com/vercel/next.js/discussions/47781#discussioncomment-7338499Co-authored-by:
JJ Kasper <jj@jjsweb.site>
-
hrmny authored
### What? Added a step in both `build-native.cjs` and `build-wasm.cjs` scripts to run Prettier on the generated types file after writing it. Should have been added with #69680, but I didn't think about it. Currently, every time you built the native module you have changes in the git repo (which would be fixed on commit, but graphite might not be happy with uncommitted changes).
-
JJ Kasper authored
Original PR is too out of sync so this lands separate. Closes: https://github.com/vercel/next.js/pull/66780
-
Sam Ko authored
## Why? - Refactor popular-prs workflow to `.ts` - Bump packages
-
Wyatt Johnson authored
Updates the configuration to specify a boolean argument rather than string literals.
-
Victor Berchet authored
- Fix `id` to be a string - Use `const` instead of `let` as common ESLint rules would complain otherwise - Add types to tsx files and remove some from jsx Co-authored-by:JJ Kasper <jj@jjsweb.site>
-
PapatMayuri authored
This PR updates the ssr-caching example for using the App Router. Here are the changes that have been made: - Renamed the "pages" folder to the "app" folder. - Added the layout.tsx file as part of the App Router. - Updated the package.json file. CC: @samcx --------- Co-authored-by:samcx <sam@vercel.com>
-